summaryrefslogtreecommitdiff
path: root/deps/icu-small/source/i18n/casetrn.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/casetrn.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/casetrn.cpp')
-rw-r--r--deps/icu-small/source/i18n/casetrn.cpp193
1 files changed, 193 insertions, 0 deletions
diff --git a/deps/icu-small/source/i18n/casetrn.cpp b/deps/icu-small/source/i18n/casetrn.cpp
new file mode 100644
index 0000000000..602c22914f
--- /dev/null
+++ b/deps/icu-small/source/i18n/casetrn.cpp
@@ -0,0 +1,193 @@
+/*
+*******************************************************************************
+*
+* Copyright (C) 2001-2011, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+* file name: casetrn.cpp
+* encoding: US-ASCII
+* 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),
+ fCsp(ucase_getSingleton()),
+ 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),
+ fCsp(o.fCsp), fMap(o.fMap)
+{
+}
+
+/**
+ * Assignment operator.
+ */
+/*CaseMapTransliterator& CaseMapTransliterator::operator=(const CaseMapTransliterator& o) {
+ Transliterator::operator=(o);
+ fCsp = o.fCsp;
+ 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, locCache=0;
+
+ for(textPos=offsets.start; textPos<offsets.limit;) {
+ csc.cpStart=textPos;
+ c=text.char32At(textPos);
+ csc.cpLimit=textPos+=U16_LENGTH(c);
+
+ result=fMap(fCsp, c, utrans_rep_caseContextIterator, &csc, &s, "", &locCache);
+
+ 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 */