diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /intl/icu/source/i18n/regeximp.cpp | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'intl/icu/source/i18n/regeximp.cpp')
-rw-r--r-- | intl/icu/source/i18n/regeximp.cpp | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/intl/icu/source/i18n/regeximp.cpp b/intl/icu/source/i18n/regeximp.cpp new file mode 100644 index 0000000000..86e238c0f7 --- /dev/null +++ b/intl/icu/source/i18n/regeximp.cpp @@ -0,0 +1,120 @@ +// © 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(nullptr), fFoldLength(0) { +} + +CaseFoldingUTextIterator::~CaseFoldingUTextIterator() {} + +UChar32 CaseFoldingUTextIterator::next() { + UChar32 foldedC; + UChar32 originalC; + if (fFoldChars == nullptr) { + // 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 = nullptr; + return foldedC; + } + // String foldings fall through here. + fFoldIndex = 0; + } + + U16_NEXT(fFoldChars, fFoldIndex, fFoldLength, foldedC); + if (fFoldIndex >= fFoldLength) { + fFoldChars = nullptr; + } + return foldedC; +} + + +UBool CaseFoldingUTextIterator::inExpansion() { + return fFoldChars != nullptr; +} + + + +CaseFoldingUCharIterator::CaseFoldingUCharIterator(const char16_t *chars, int64_t start, int64_t limit) : + fChars(chars), fIndex(start), fLimit(limit), fFoldChars(nullptr), fFoldLength(0) { +} + + +CaseFoldingUCharIterator::~CaseFoldingUCharIterator() {} + + +UChar32 CaseFoldingUCharIterator::next() { + UChar32 foldedC; + UChar32 originalC; + if (fFoldChars == nullptr) { + // 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 = nullptr; + return foldedC; + } + // String foldings fall through here. + fFoldIndex = 0; + } + + U16_NEXT(fFoldChars, fFoldIndex, fFoldLength, foldedC); + if (fFoldIndex >= fFoldLength) { + fFoldChars = nullptr; + } + return foldedC; +} + + +UBool CaseFoldingUCharIterator::inExpansion() { + return fFoldChars != nullptr; +} + +int64_t CaseFoldingUCharIterator::getIndex() { + return fIndex; +} + + +U_NAMESPACE_END + +#endif + |