summaryrefslogtreecommitdiff
path: root/deps/icu-small/source/common/ubrk.cpp
diff options
context:
space:
mode:
authorSteven R. Loomis <srloomis@us.ibm.com>2017-04-13 16:25:08 -0700
committerSteven R. Loomis <srloomis@us.ibm.com>2017-05-09 15:20:02 -0700
commit5d0a770c129c00e3942263b429f8efa4c42efba9 (patch)
tree0766989dae39097084b6c5c8e2f75bf92812c713 /deps/icu-small/source/common/ubrk.cpp
parent147048a0d3e255d2a0604f3ab7c8f62252cb8252 (diff)
downloadnode-new-5d0a770c129c00e3942263b429f8efa4c42efba9.tar.gz
deps: ICU 59.1 bump
* No feature changes. * Bug fixes. * Details: http://site.icu-project.org/download/59 Fixes: https://github.com/nodejs/node/issues/12077 PR-URL: https://github.com/nodejs/node/pull/12486 Refs: https://github.com/nodejs/node/issues/7844 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
Diffstat (limited to 'deps/icu-small/source/common/ubrk.cpp')
-rw-r--r--deps/icu-small/source/common/ubrk.cpp62
1 files changed, 59 insertions, 3 deletions
diff --git a/deps/icu-small/source/common/ubrk.cpp b/deps/icu-small/source/common/ubrk.cpp
index b02c966b10..f8bdf5a6b6 100644
--- a/deps/icu-small/source/common/ubrk.cpp
+++ b/deps/icu-small/source/common/ubrk.cpp
@@ -1,4 +1,4 @@
-// Copyright (C) 2016 and later: Unicode, Inc. and others.
+// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
********************************************************************************
@@ -20,6 +20,7 @@
#include "unicode/rbbi.h"
#include "rbbirb.h"
#include "uassert.h"
+#include "cmemory.h"
U_NAMESPACE_USE
@@ -119,7 +120,28 @@ ubrk_openRules( const UChar *rules,
}
-
+U_CAPI UBreakIterator* U_EXPORT2
+ubrk_openBinaryRules(const uint8_t *binaryRules, int32_t rulesLength,
+ const UChar * text, int32_t textLength,
+ UErrorCode * status)
+{
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ if (rulesLength < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return NULL;
+ }
+ LocalPointer<RuleBasedBreakIterator> lpRBBI(new RuleBasedBreakIterator(binaryRules, rulesLength, *status), *status);
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ UBreakIterator *uBI = reinterpret_cast<UBreakIterator *>(lpRBBI.orphan());
+ if (text != NULL) {
+ ubrk_setText(uBI, text, textLength, status);
+ }
+ return uBI;
+}
U_CAPI UBreakIterator * U_EXPORT2
@@ -288,7 +310,8 @@ ubrk_getLocaleByType(const UBreakIterator *bi,
}
-void ubrk_refreshUText(UBreakIterator *bi,
+U_CAPI void U_EXPORT2
+ubrk_refreshUText(UBreakIterator *bi,
UText *text,
UErrorCode *status)
{
@@ -296,6 +319,39 @@ void ubrk_refreshUText(UBreakIterator *bi,
bii->refreshInputText(text, *status);
}
+U_CAPI int32_t U_EXPORT2
+ubrk_getBinaryRules(UBreakIterator *bi,
+ uint8_t * binaryRules, int32_t rulesCapacity,
+ UErrorCode * status)
+{
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ if ((binaryRules == NULL && rulesCapacity > 0) || rulesCapacity < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ RuleBasedBreakIterator* rbbi;
+ if ((rbbi = dynamic_cast<RuleBasedBreakIterator*>(reinterpret_cast<BreakIterator*>(bi))) == NULL) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ uint32_t rulesLength;
+ const uint8_t * returnedRules = rbbi->getBinaryRules(rulesLength);
+ if (rulesLength > INT32_MAX) {
+ *status = U_INDEX_OUTOFBOUNDS_ERROR;
+ return 0;
+ }
+ if (binaryRules != NULL) { // if not preflighting
+ // Here we know rulesLength <= INT32_MAX and rulesCapacity >= 0, can cast safely
+ if ((int32_t)rulesLength > rulesCapacity) {
+ *status = U_BUFFER_OVERFLOW_ERROR;
+ } else {
+ uprv_memcpy(binaryRules, returnedRules, rulesLength);
+ }
+ }
+ return (int32_t)rulesLength;
+}
#endif /* #if !UCONFIG_NO_BREAK_ITERATION */