summaryrefslogtreecommitdiff
path: root/deps/icu-small/source/i18n/smpdtfst.cpp
diff options
context:
space:
mode:
authorSteven R. Loomis <srloomis@us.ibm.com>2016-04-08 19:03:16 -0700
committerSteven R. Loomis <srloomis@us.ibm.com>2016-05-04 16:02:45 -0700
commit2bbd1cd6004b3e1467e30d860385a85dad01fe24 (patch)
treeb812046e89e46e0de09bc858e0b128787cbc0632 /deps/icu-small/source/i18n/smpdtfst.cpp
parentcd752e8463fad7c4805951d9ba47cd2f39691f2d (diff)
downloadandroid-node-v8-2bbd1cd6004b3e1467e30d860385a85dad01fe24.tar.gz
android-node-v8-2bbd1cd6004b3e1467e30d860385a85dad01fe24.tar.bz2
android-node-v8-2bbd1cd6004b3e1467e30d860385a85dad01fe24.zip
deps: Intl: Check in "small-icu" 57.1
* this commit has "small" ICU 57.1. See other related commit for tools to generate this commit. Fixes: https://github.com/nodejs/node/issues/3476 PR-URL: https://github.com/nodejs/node/pull/6088 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'deps/icu-small/source/i18n/smpdtfst.cpp')
-rw-r--r--deps/icu-small/source/i18n/smpdtfst.cpp135
1 files changed, 135 insertions, 0 deletions
diff --git a/deps/icu-small/source/i18n/smpdtfst.cpp b/deps/icu-small/source/i18n/smpdtfst.cpp
new file mode 100644
index 0000000000..f9e94b82c6
--- /dev/null
+++ b/deps/icu-small/source/i18n/smpdtfst.cpp
@@ -0,0 +1,135 @@
+/*
+*******************************************************************************
+* 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