/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// if some spaces are skipped, and the script type is Asian with no CJK rLocale, we have to return // (nStartPos, -1) for caller to send correct rLocale for loading correct dictionary.
result.startPos = nPos; if (nPos != nStartPos && nPos > 0 && !isCJK(rLocale) && getScriptClass(Text.iterateCodePoints(&nPos, -1)) == ScriptType::ASIAN) {
result.endPos = -1; return result;
}
/** Increments/decrements position first, then obtains character. @return current position, may be -1 or text length if string was consumed.
*/ static sal_Int32 iterateCodePoints(const OUString& Text, sal_Int32 &nStartPos, sal_Int32 inc, sal_uInt32& ch) {
sal_Int32 nLen = Text.getLength(); if (nStartPos + inc < 0 || nStartPos + inc >= nLen) {
ch = 0;
nStartPos = nStartPos + inc < 0 ? -1 : nLen;
} else {
ch = Text.iterateCodePoints(&nStartPos, inc); // Fix for #i80436#. // erAck: 2009-06-30T21:52+0200 This logic looks somewhat // suspicious as if it cures a symptom... anyway, had to add // nStartPos < Text.getLength() to silence the (correct) assertion // in rtl_uString_iterateCodePoints() if Text was one character // (codepoint) only, made up of a surrogate pair. //if (inc > 0 && nStartPos < Text.getLength()) // ch = Text.iterateCodePoints(&nStartPos, 0); // With surrogates, nStartPos may actually point behind string // now, even if inc is only +1 if (inc > 0)
ch = (nStartPos < nLen ? Text.iterateCodePoints(&nStartPos, 0) : 0);
} return nStartPos;
}
if (CharType == CharType::ANY_CHAR) return strLen; // end of char block is exclusive if (nStartPos < 0 || nStartPos >= strLen) return -1; if (CharType != static_cast<sal_Int16>(u_charType(Text.iterateCodePoints(&nStartPos, 0)))) return -1;
sal_uInt32 ch=0; while(iterateCodePoints(Text, nStartPos, 1, ch) < strLen && CharType == static_cast<sal_Int16>(u_charType(ch))) {} return nStartPos; // end of char block is exclusive
}
bool BreakIteratorImpl::createLocaleSpecificBreakIterator(const OUString& aLocaleName)
{ // to share service between same Language but different Country code, like zh_CN and zh_TW for (const lookupTableItem& listItem : lookupTable) { if (aLocaleName == listItem.aLocale.Language) {
xBI = listItem.xBI; returntrue;
}
}
for (const lookupTableItem& listItem : lookupTable) { if (rLocale == listItem.aLocale)
{
xBI = listItem.xBI; return xBI;
}
}
static constexpr OUString under(u"_"_ustr);
sal_Int32 l = rLocale.Language.getLength();
sal_Int32 c = rLocale.Country.getLength();
sal_Int32 v = rLocale.Variant.getLength();
if ((l > 0 && c > 0 && v > 0 && // load service with name <base>_<lang>_<country>_<variant>
createLocaleSpecificBreakIterator(rLocale.Language + under +
rLocale.Country + under + rLocale.Variant)) ||
(l > 0 && c > 0 && // load service with name <base>_<lang>_<country>
createLocaleSpecificBreakIterator(rLocale.Language + under +
rLocale.Country)) ||
(l > 0 && c > 0 && rLocale.Language == "zh" &&
(rLocale.Country == "HK" ||
rLocale.Country == "MO" ) && // if the country code is HK or MO, one more step to try TW.
createLocaleSpecificBreakIterator(rLocale.Language + under + "TW")) ||
(l > 0 && // load service with name <base>_<lang>
createLocaleSpecificBreakIterator(rLocale.Language)) || // load default service with name <base>_Unicode
createLocaleSpecificBreakIterator(u"Unicode"_ustr)) {
lookupTable.emplace_back( aLocale, xBI ); return xBI;
}
} throw RuntimeException(u"getLocaleSpecificBreakIterator: iterator not found"_ustr);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.