summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-09-27 09:11:35 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-09-27 11:02:56 +0200
commitcc1ed7fbce20f90650f96acc2846b6f232c8ab0f (patch)
treefcd441cdf9568861363894f63107967adf571f81 /i18npool
parentb50f595b34585f2927adfd44b4eaaafb8f600972 (diff)
loplugin:flatten in various
Change-Id: I42dca691ffadbddad38a7e8f978b1da9d5d9a7b0 Reviewed-on: https://gerrit.libreoffice.org/42842 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/source/indexentry/indexentrysupplier_default.cxx21
-rw-r--r--i18npool/source/textconversion/textconversion_ko.cxx142
-rw-r--r--i18npool/source/textconversion/textconversion_zh.cxx56
3 files changed, 109 insertions, 110 deletions
diff --git a/i18npool/source/indexentry/indexentrysupplier_default.cxx b/i18npool/source/indexentry/indexentrysupplier_default.cxx
index 419d84c80c5e..d0673a9d50ed 100644
--- a/i18npool/source/indexentry/indexentrysupplier_default.cxx
+++ b/i18npool/source/indexentry/indexentrysupplier_default.cxx
@@ -187,15 +187,15 @@ void Index::makeIndexKeys(const lang::Locale &rLocale, const OUString &algorithm
continue;
switch(curr) {
- case u'-':
- if (key_count > 0 && i + 1 < len ) {
+ case u'-': {
+ if (key_count <= 0 || i + 1 >= len)
+ throw RuntimeException();
for (curr = keyStr[++i]; key_count < MAX_KEYS && keys[key_count-1].key < curr; key_count++) {
keys[key_count].key = keys[key_count-1].key+1;
keys[key_count].desc.clear();
}
- } else
- throw RuntimeException();
- break;
+ break;
+ }
case u'[':
for (i++; i < len && keyStr[i] != ']'; i++) {
if (unicode::isWhiteSpace(keyStr[i])) {
@@ -212,8 +212,10 @@ void Index::makeIndexKeys(const lang::Locale &rLocale, const OUString &algorithm
case u'{':
close = '}';
SAL_FALLTHROUGH;
- case u'(':
- if (key_count > 0) {
+ case u'(': {
+ if (key_count <= 0)
+ throw RuntimeException();
+
sal_Int16 end = i+1;
for (; end < len && keyStr[end] != close; end++) ;
@@ -228,9 +230,8 @@ void Index::makeIndexKeys(const lang::Locale &rLocale, const OUString &algorithm
keys[key_count++].desc.clear();
}
i=end+1;
- } else
- throw RuntimeException();
- break;
+ break;
+ }
default:
keys[key_count].key = curr;
keys[key_count++].desc.clear();
diff --git a/i18npool/source/textconversion/textconversion_ko.cxx b/i18npool/source/textconversion/textconversion_ko.cxx
index e9a788f5a461..645acc93144c 100644
--- a/i18npool/source/textconversion/textconversion_ko.cxx
+++ b/i18npool/source/textconversion/textconversion_ko.cxx
@@ -221,83 +221,83 @@ TextConversion_ko::getConversions( const OUString& aText, sal_Int32 nStartPos, s
result.Boundary.startPos = result.Boundary.endPos = 0;
// do conversion only when there are right conversion type and dictionary services.
- if (nConversionType == TextConversionType::TO_HANGUL ||
- nConversionType == TextConversionType::TO_HANJA) {
- sal_Int32 start, end, length = aText.getLength() - nStartPos;
-
- if (length < 0 || nStartPos < 0)
- length = 0;
- else if (length > nLength)
- length = nLength;
-
- sal_Int16 scriptType = SCRIPT_OTHERS;
- sal_Int32 len = 1;
- bool toHanja = (nConversionType == TextConversionType::TO_HANJA);
- // FROM_LEFT: Hangul -> Hanja
- // FROM_RIGHT: Hanja -> Hangul
- ConversionDirection eDirection = toHanja ? ConversionDirection_FROM_LEFT : ConversionDirection_FROM_RIGHT;
- sal_Int32 maxLength = toHanja ? maxLeftLength : maxRightLength;
- if (maxLength == 0) maxLength = 1;
-
- // search for a max length of convertible text
- for (start = 0, end = 0; start < length; start++) {
- if (end <= start) {
- scriptType = checkScriptType(aText[nStartPos + start]);
- if (nConversionType == TextConversionType::TO_HANJA) {
- if (scriptType != SCRIPT_HANGUL) // skip non-Hangul characters
- continue;
- } else {
- if (scriptType != SCRIPT_HANJA) // skip non-Hanja characters
- continue;
- }
- end = start + 1;
- }
- if (nConversionOptions & TextConversionOption::CHARACTER_BY_CHARACTER) {
- result.Candidates = getCharConversions(aText, nStartPos + start, len, toHanja); // char2char conversion
+ if (nConversionType != TextConversionType::TO_HANGUL &&
+ nConversionType != TextConversionType::TO_HANJA)
+ throw NoSupportException(); // Conversion type is not supported in this service.
+ sal_Int32 start, end, length = aText.getLength() - nStartPos;
+
+ if (length < 0 || nStartPos < 0)
+ length = 0;
+ else if (length > nLength)
+ length = nLength;
+
+ sal_Int16 scriptType = SCRIPT_OTHERS;
+ sal_Int32 len = 1;
+ bool toHanja = (nConversionType == TextConversionType::TO_HANJA);
+ // FROM_LEFT: Hangul -> Hanja
+ // FROM_RIGHT: Hanja -> Hangul
+ ConversionDirection eDirection = toHanja ? ConversionDirection_FROM_LEFT : ConversionDirection_FROM_RIGHT;
+ sal_Int32 maxLength = toHanja ? maxLeftLength : maxRightLength;
+ if (maxLength == 0) maxLength = 1;
+
+ // search for a max length of convertible text
+ for (start = 0, end = 0; start < length; start++) {
+ if (end <= start) {
+ scriptType = checkScriptType(aText[nStartPos + start]);
+ if (nConversionType == TextConversionType::TO_HANJA) {
+ if (scriptType != SCRIPT_HANGUL) // skip non-Hangul characters
+ continue;
} else {
- for (; end < length && end - start < maxLength; end++)
- if (checkScriptType(aText[nStartPos + end]) != scriptType)
- break;
-
- for (len = end - start; len > 0; len--) {
- if (len > 1) {
- try {
- if (xCDL.is())
- result.Candidates = xCDL->queryConversions(aText, start + nStartPos, len,
- aLocale, ConversionDictionaryType::HANGUL_HANJA, eDirection, nConversionOptions); // user dictionary
- }
- catch ( NoSupportException & ) {
- // clear reference (when there is no user dictionary) in order
- // to not always have to catch this exception again
- // in further calls. (save time)
- xCDL = nullptr;
- }
- catch (...) {
- // catch all other exceptions to allow
- // querying the system dictionary in the next line
- }
- if (xCD.is() && toHanja) { // System dictionary would not do Hanja_to_Hangul conversion.
- candidates = xCD->getConversions(aText, start + nStartPos, len, eDirection, nConversionOptions);
- result.Candidates += candidates;
- }
- } else if (! toHanja) { // do whole word character 2 character conversion for Hanja to Hangul conversion
- result.Candidates = getCharConversions(aText, nStartPos + start, length - start, toHanja);
- if (result.Candidates.hasElements())
- len = result.Candidates[0].getLength();
+ if (scriptType != SCRIPT_HANJA) // skip non-Hanja characters
+ continue;
+ }
+ end = start + 1;
+ }
+ if (nConversionOptions & TextConversionOption::CHARACTER_BY_CHARACTER) {
+ result.Candidates = getCharConversions(aText, nStartPos + start, len, toHanja); // char2char conversion
+ } else {
+ for (; end < length && end - start < maxLength; end++)
+ if (checkScriptType(aText[nStartPos + end]) != scriptType)
+ break;
+
+ for (len = end - start; len > 0; len--) {
+ if (len > 1) {
+ try {
+ if (xCDL.is())
+ result.Candidates = xCDL->queryConversions(aText, start + nStartPos, len,
+ aLocale, ConversionDictionaryType::HANGUL_HANJA, eDirection, nConversionOptions); // user dictionary
+ }
+ catch ( NoSupportException & ) {
+ // clear reference (when there is no user dictionary) in order
+ // to not always have to catch this exception again
+ // in further calls. (save time)
+ xCDL = nullptr;
+ }
+ catch (...) {
+ // catch all other exceptions to allow
+ // querying the system dictionary in the next line
}
+ if (xCD.is() && toHanja) { // System dictionary would not do Hanja_to_Hangul conversion.
+ candidates = xCD->getConversions(aText, start + nStartPos, len, eDirection, nConversionOptions);
+ result.Candidates += candidates;
+ }
+ } else if (! toHanja) { // do whole word character 2 character conversion for Hanja to Hangul conversion
+ result.Candidates = getCharConversions(aText, nStartPos + start, length - start, toHanja);
if (result.Candidates.hasElements())
- break;
+ len = result.Candidates[0].getLength();
}
- }
- // found match
- if (result.Candidates.hasElements()) {
- result.Boundary.startPos = start + nStartPos;
- result.Boundary.endPos = start + len + nStartPos;
- return result;
+ if (result.Candidates.hasElements())
+ break;
}
}
- } else
- throw NoSupportException(); // Conversion type is not supported in this service.
+ // found match
+ if (result.Candidates.hasElements()) {
+ result.Boundary.startPos = start + nStartPos;
+ result.Boundary.endPos = start + len + nStartPos;
+ return result;
+ }
+ }
+
return result;
}
diff --git a/i18npool/source/textconversion/textconversion_zh.cxx b/i18npool/source/textconversion/textconversion_zh.cxx
index 224c7dea8d74..ae08f5221e3d 100644
--- a/i18npool/source/textconversion/textconversion_zh.cxx
+++ b/i18npool/source/textconversion/textconversion_zh.cxx
@@ -283,44 +283,42 @@ OUString SAL_CALL
TextConversion_zh::getConversion( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
{
- if (rLocale.Language == "zh" && ( nConversionType == TextConversionType::TO_SCHINESE || nConversionType == TextConversionType::TO_TCHINESE) ) {
-
- aLocale=rLocale;
- bool toSChinese = nConversionType == TextConversionType::TO_SCHINESE;
-
- if (nConversionOptions & TextConversionOption::CHARACTER_BY_CHARACTER)
- // char to char dictionary
- return getCharConversion(aText, nStartPos, nLength, toSChinese, nConversionOptions);
- else {
- Sequence <sal_Int32> offset;
- // word to word dictionary
- return getWordConversion(aText, nStartPos, nLength, toSChinese, nConversionOptions, offset);
- }
- } else
+ if (rLocale.Language != "zh" || ( nConversionType != TextConversionType::TO_SCHINESE && nConversionType != TextConversionType::TO_TCHINESE) )
throw NoSupportException(); // Conversion type is not supported in this service.
+
+ aLocale=rLocale;
+ bool toSChinese = nConversionType == TextConversionType::TO_SCHINESE;
+
+ if (nConversionOptions & TextConversionOption::CHARACTER_BY_CHARACTER)
+ // char to char dictionary
+ return getCharConversion(aText, nStartPos, nLength, toSChinese, nConversionOptions);
+ else {
+ Sequence <sal_Int32> offset;
+ // word to word dictionary
+ return getWordConversion(aText, nStartPos, nLength, toSChinese, nConversionOptions, offset);
+ }
}
OUString SAL_CALL
TextConversion_zh::getConversionWithOffset( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions, Sequence<sal_Int32>& offset)
{
- if (rLocale.Language == "zh" && ( nConversionType == TextConversionType::TO_SCHINESE || nConversionType == TextConversionType::TO_TCHINESE) ) {
+ if (rLocale.Language != "zh" || ( nConversionType != TextConversionType::TO_SCHINESE && nConversionType != TextConversionType::TO_TCHINESE) )
+ throw NoSupportException(); // Conversion type is not supported in this service.
- aLocale=rLocale;
- bool toSChinese = nConversionType == TextConversionType::TO_SCHINESE;
+ aLocale=rLocale;
+ bool toSChinese = nConversionType == TextConversionType::TO_SCHINESE;
- if (nConversionOptions & TextConversionOption::CHARACTER_BY_CHARACTER) {
- offset.realloc(0);
- // char to char dictionary
- return getCharConversion(aText, nStartPos, nLength, toSChinese, nConversionOptions);
- } else {
- if (offset.getLength() < 2*nLength)
- offset.realloc(2*nLength);
- // word to word dictionary
- return getWordConversion(aText, nStartPos, nLength, toSChinese, nConversionOptions, offset);
- }
- } else
- throw NoSupportException(); // Conversion type is not supported in this service.
+ if (nConversionOptions & TextConversionOption::CHARACTER_BY_CHARACTER) {
+ offset.realloc(0);
+ // char to char dictionary
+ return getCharConversion(aText, nStartPos, nLength, toSChinese, nConversionOptions);
+ } else {
+ if (offset.getLength() < 2*nLength)
+ offset.realloc(2*nLength);
+ // word to word dictionary
+ return getWordConversion(aText, nStartPos, nLength, toSChinese, nConversionOptions, offset);
+ }
}
sal_Bool SAL_CALL