diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-07 19:59:47 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-08 11:01:14 +0200 |
commit | 32343bcbb786168df62f85a57e30c620c3d3bdb4 (patch) | |
tree | a38537c56f5e708a88c9371dcd5c6dd14055eab6 /i18npool/source | |
parent | f2053a6accc2e68aa2920d4d3f46f82909415666 (diff) |
loplugin:flatten in i18npool
and workaround a clang crash
Change-Id: Ida94c8abb4b2e997d38a7f430e59f73aadf8fcc8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91844
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'i18npool/source')
-rw-r--r-- | i18npool/source/breakiterator/breakiterator_unicode.cxx | 24 | ||||
-rw-r--r-- | i18npool/source/calendar/calendar_gregorian.cxx | 35 | ||||
-rw-r--r-- | i18npool/source/calendar/calendar_hijri.cxx | 31 | ||||
-rw-r--r-- | i18npool/source/calendar/calendar_jewish.cxx | 27 | ||||
-rw-r--r-- | i18npool/source/nativenumber/nativenumbersupplier.cxx | 29 |
5 files changed, 75 insertions, 71 deletions
diff --git a/i18npool/source/breakiterator/breakiterator_unicode.cxx b/i18npool/source/breakiterator/breakiterator_unicode.cxx index 22d8a8b50568..b756fbbdbee2 100644 --- a/i18npool/source/breakiterator/breakiterator_unicode.cxx +++ b/i18npool/source/breakiterator/breakiterator_unicode.cxx @@ -307,23 +307,23 @@ void BreakIterator_Unicode::loadICUBreakIterator(const css::lang::Locale& rLocal bNewBreak=true; } - if (bNewBreak || icuBI->mpValue->maICUText.pData != rText.pData) - { - const UChar *pText = reinterpret_cast<const UChar *>(rText.getStr()); + if (!(bNewBreak || icuBI->mpValue->maICUText.pData != rText.pData)) + return; - status = U_ZERO_ERROR; - icuBI->mpValue->mpUt = utext_openUChars(icuBI->mpValue->mpUt, pText, rText.getLength(), &status); + const UChar *pText = reinterpret_cast<const UChar *>(rText.getStr()); - if (!U_SUCCESS(status)) - throw uno::RuntimeException(); + status = U_ZERO_ERROR; + icuBI->mpValue->mpUt = utext_openUChars(icuBI->mpValue->mpUt, pText, rText.getLength(), &status); - icuBI->mpValue->mpBreakIterator->setText(icuBI->mpValue->mpUt, status); + if (!U_SUCCESS(status)) + throw uno::RuntimeException(); - if (!U_SUCCESS(status)) - throw uno::RuntimeException(); + icuBI->mpValue->mpBreakIterator->setText(icuBI->mpValue->mpUt, status); - icuBI->mpValue->maICUText = rText; - } + if (!U_SUCCESS(status)) + throw uno::RuntimeException(); + + icuBI->mpValue->maICUText = rText; } sal_Int32 SAL_CALL BreakIterator_Unicode::nextCharacters( const OUString& Text, diff --git a/i18npool/source/calendar/calendar_gregorian.cxx b/i18npool/source/calendar/calendar_gregorian.cxx index a4eaf3dcde9f..b7ae49fbd96e 100644 --- a/i18npool/source/calendar/calendar_gregorian.cxx +++ b/i18npool/source/calendar/calendar_gregorian.cxx @@ -394,27 +394,28 @@ bool Calendar_gregorian::setTimeZone( const OUString& rTimeZone ) // By using eraArray, it can take care Japanese and Taiwan ROC calendar. void Calendar_gregorian::mapFromGregorian() { - if (eraArray) { - sal_Int16 e, y, m, d; + if (!eraArray) + return; - e = fieldValue[CalendarFieldIndex::ERA]; - y = fieldValue[CalendarFieldIndex::YEAR]; - m = fieldValue[CalendarFieldIndex::MONTH] + 1; - d = fieldValue[CalendarFieldIndex::DAY_OF_MONTH]; + sal_Int16 e, y, m, d; - // since the year is reversed for first era, it is reversed again here for Era compare. - if (e == 0) - y = 1 - y; + e = fieldValue[CalendarFieldIndex::ERA]; + y = fieldValue[CalendarFieldIndex::YEAR]; + m = fieldValue[CalendarFieldIndex::MONTH] + 1; + d = fieldValue[CalendarFieldIndex::DAY_OF_MONTH]; - for (e = 0; eraArray[e].year; e++) - if ((y != eraArray[e].year) ? y < eraArray[e].year : - (m != eraArray[e].month) ? m < eraArray[e].month : d < eraArray[e].day) - break; + // since the year is reversed for first era, it is reversed again here for Era compare. + if (e == 0) + y = 1 - y; - fieldValue[CalendarFieldIndex::ERA] = e; - fieldValue[CalendarFieldIndex::YEAR] = - sal::static_int_cast<sal_Int16>( (e == 0) ? (eraArray[0].year - y) : (y - eraArray[e-1].year + 1) ); - } + for (e = 0; eraArray[e].year; e++) + if ((y != eraArray[e].year) ? y < eraArray[e].year : + (m != eraArray[e].month) ? m < eraArray[e].month : d < eraArray[e].day) + break; + + fieldValue[CalendarFieldIndex::ERA] = e; + fieldValue[CalendarFieldIndex::YEAR] = + sal::static_int_cast<sal_Int16>( (e == 0) ? (eraArray[0].year - y) : (y - eraArray[e-1].year + 1) ); } #define FIELDS ((1 << CalendarFieldIndex::ERA) | (1 << CalendarFieldIndex::YEAR)) diff --git a/i18npool/source/calendar/calendar_hijri.cxx b/i18npool/source/calendar/calendar_hijri.cxx index ce48dac0f127..dca8b95836fc 100644 --- a/i18npool/source/calendar/calendar_hijri.cxx +++ b/i18npool/source/calendar/calendar_hijri.cxx @@ -68,21 +68,22 @@ Calendar_hijri::Calendar_hijri() // map field value from hijri calendar to gregorian calendar void Calendar_hijri::mapToGregorian() { - if (fieldSet & FIELDS) { - sal_Int32 day = static_cast<sal_Int32>(fieldSetValue[CalendarFieldIndex::DAY_OF_MONTH]); - sal_Int32 month = static_cast<sal_Int32>(fieldSetValue[CalendarFieldIndex::MONTH]) + 1; - sal_Int32 year = static_cast<sal_Int32>(fieldSetValue[CalendarFieldIndex::YEAR]); - if (fieldSetValue[CalendarFieldIndex::ERA] == 0) - year *= -1; - - ToGregorian(&day, &month, &year); - - fieldSetValue[CalendarFieldIndex::ERA] = year <= 0 ? 0 : 1; - fieldSetValue[CalendarFieldIndex::MONTH] = sal::static_int_cast<sal_Int16>(month - 1); - fieldSetValue[CalendarFieldIndex::DAY_OF_MONTH] = static_cast<sal_Int16>(day); - fieldSetValue[CalendarFieldIndex::YEAR] = static_cast<sal_Int16>(abs(year)); - fieldSet |= FIELDS; - } + if (!(fieldSet & FIELDS)) + return; + + sal_Int32 day = static_cast<sal_Int32>(fieldSetValue[CalendarFieldIndex::DAY_OF_MONTH]); + sal_Int32 month = static_cast<sal_Int32>(fieldSetValue[CalendarFieldIndex::MONTH]) + 1; + sal_Int32 year = static_cast<sal_Int32>(fieldSetValue[CalendarFieldIndex::YEAR]); + if (fieldSetValue[CalendarFieldIndex::ERA] == 0) + year *= -1; + + ToGregorian(&day, &month, &year); + + fieldSetValue[CalendarFieldIndex::ERA] = year <= 0 ? 0 : 1; + fieldSetValue[CalendarFieldIndex::MONTH] = sal::static_int_cast<sal_Int16>(month - 1); + fieldSetValue[CalendarFieldIndex::DAY_OF_MONTH] = static_cast<sal_Int16>(day); + fieldSetValue[CalendarFieldIndex::YEAR] = static_cast<sal_Int16>(abs(year)); + fieldSet |= FIELDS; } // map field value from gregorian calendar to hijri calendar diff --git a/i18npool/source/calendar/calendar_jewish.cxx b/i18npool/source/calendar/calendar_jewish.cxx index ee35c5d90cf9..ab5a32a221d8 100644 --- a/i18npool/source/calendar/calendar_jewish.cxx +++ b/i18npool/source/calendar/calendar_jewish.cxx @@ -272,19 +272,20 @@ void Calendar_jewish::mapFromGregorian() // map field value from other calendar to gregorian calendar, it should be implemented. void Calendar_jewish::mapToGregorian() { - if (fieldSet & FIELDS) { - sal_Int16 y = fieldSetValue[CalendarFieldIndex::YEAR]; - if (fieldSetValue[CalendarFieldIndex::ERA] == 0) - y = 1 - y; - HebrewDate Temp(fieldSetValue[CalendarFieldIndex::MONTH] + 1, fieldSetValue[CalendarFieldIndex::DAY_OF_MONTH], y); - GregorianDate gd(Temp.GetAbsoluteDate()); - - fieldSetValue[CalendarFieldIndex::ERA] = gd.GetYear() <= 0 ? 0 : 1; - fieldSetValue[CalendarFieldIndex::MONTH] = sal::static_int_cast<sal_Int16>( gd.GetMonth() - 1 ); - fieldSetValue[CalendarFieldIndex::DAY_OF_MONTH] = static_cast<sal_Int16>(gd.GetDay()); - fieldSetValue[CalendarFieldIndex::YEAR] = static_cast<sal_Int16>(gd.GetYear() <= 0 ? 1 - gd.GetYear() : gd.GetYear()); - fieldSet |= FIELDS; - } + if (!(fieldSet & FIELDS)) + return; + + sal_Int16 y = fieldSetValue[CalendarFieldIndex::YEAR]; + if (fieldSetValue[CalendarFieldIndex::ERA] == 0) + y = 1 - y; + HebrewDate Temp(fieldSetValue[CalendarFieldIndex::MONTH] + 1, fieldSetValue[CalendarFieldIndex::DAY_OF_MONTH], y); + GregorianDate gd(Temp.GetAbsoluteDate()); + + fieldSetValue[CalendarFieldIndex::ERA] = gd.GetYear() <= 0 ? 0 : 1; + fieldSetValue[CalendarFieldIndex::MONTH] = sal::static_int_cast<sal_Int16>( gd.GetMonth() - 1 ); + fieldSetValue[CalendarFieldIndex::DAY_OF_MONTH] = static_cast<sal_Int16>(gd.GetDay()); + fieldSetValue[CalendarFieldIndex::YEAR] = static_cast<sal_Int16>(gd.GetYear() <= 0 ? 1 - gd.GetYear() : gd.GetYear()); + fieldSet |= FIELDS; } // Methods in XExtendedCalendar diff --git a/i18npool/source/nativenumber/nativenumbersupplier.cxx b/i18npool/source/nativenumber/nativenumbersupplier.cxx index ff521145045e..8579c51035d8 100644 --- a/i18npool/source/nativenumber/nativenumbersupplier.cxx +++ b/i18npool/source/nativenumber/nativenumbersupplier.cxx @@ -1168,21 +1168,22 @@ static void makeCyrillicNumber(sal_Int64 value, OUStringBuffer& output, bool add } } - if (addTitlo) { - if (output.getLength() == 1) { + if (!addTitlo) + return; + + if (output.getLength() == 1) { + output.append(cyrillicTitlo); + } else if (output.getLength() == 2) { + if (value > 800 && value < 900) { output.append(cyrillicTitlo); - } else if (output.getLength() == 2) { - if (value > 800 && value < 900) { - output.append(cyrillicTitlo); - } else { - output.insert(1, cyrillicTitlo); - } - } else if (output.getLength() > 2) { - if (output.indexOf(" ") == output.getLength() - 2) { - output.append(cyrillicTitlo); - } else { - output.insert(output.getLength() - 1, cyrillicTitlo); - } + } else { + output.insert(1, cyrillicTitlo); + } + } else if (output.getLength() > 2) { + if (output.indexOf(" ") == output.getLength() - 2) { + output.append(cyrillicTitlo); + } else { + output.insert(output.getLength() - 1, cyrillicTitlo); } } } |