diff options
author | David Tardon <dtardon@redhat.com> | 2014-05-12 14:02:13 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2014-05-18 22:11:08 +0200 |
commit | 6015a51f49127b83b9e89e2b04ea4b1d4c2673cc (patch) | |
tree | e97b40d5f364c4997aab05871d043e570cf80cf9 /svl | |
parent | 267beb34c84a66bfded10854d27617d9a925c8c6 (diff) |
fdo#78119 find the longest match for month name
(cherry picked from commit 624e5c34ce815af6f65ce6699ad6b3f2aa1bf0da)
Change-Id: Idad7b083ce5528f5c735f3a8bd091819bf043fc8
Reviewed-on: https://gerrit.libreoffice.org/#/c/9329
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'svl')
-rw-r--r-- | svl/source/numbers/zforfind.cxx | 69 |
1 files changed, 48 insertions, 21 deletions
diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx index 3726c331cd71..840af0c52a88 100644 --- a/svl/source/numbers/zforfind.cxx +++ b/svl/source/numbers/zforfind.cxx @@ -561,6 +561,7 @@ short ImpSvNumberInputScan::GetMonth( const OUString& rString, sal_Int32& nPos ) static const OUString aSepShortened("SEP"); short res = 0; // no month found + int nMatchLen = 0; if (rString.getLength() > nPos) // only if needed { @@ -569,52 +570,78 @@ short ImpSvNumberInputScan::GetMonth( const OUString& rString, sal_Int32& nPos ) InitText(); } sal_Int16 nMonths = pFormatter->GetCalendar()->getNumberOfMonthsInYear(); + // Find the longest match. This is needed for, e.g., Czech, as Červen (June) + // is fully contained in Červenec (July), so the latter could never be found + // if we stopped at the first match. for ( sal_Int16 i = 0; i < nMonths; i++ ) { if ( bScanGenitiveMonths && StringContains( pUpperGenitiveMonthText[i], rString, nPos ) ) { // genitive full names first - nPos = nPos + pUpperGenitiveMonthText[i].getLength(); - res = i + 1; - break; // for + const int nMonthLen = pUpperGenitiveMonthText[i].getLength(); + if (nMonthLen > nMatchLen) + { + nMatchLen = nMonthLen; + res = i + 1; + } } else if ( bScanGenitiveMonths && StringContains( pUpperGenitiveAbbrevMonthText[i], rString, nPos ) ) { // genitive abbreviated - nPos = nPos + pUpperGenitiveAbbrevMonthText[i].getLength(); - res = sal::static_int_cast< short >(-(i+1)); // negative - break; // for + const int nMonthLen = pUpperGenitiveAbbrevMonthText[i].getLength(); + if (nMonthLen > nMatchLen) + { + nMatchLen = nMonthLen; + res = sal::static_int_cast< short >(-(i+1)); // negative + } } else if ( bScanPartitiveMonths && StringContains( pUpperPartitiveMonthText[i], rString, nPos ) ) { // partitive full names - nPos = nPos + pUpperPartitiveMonthText[i].getLength(); - res = i+1; - break; // for + const int nMonthLen = pUpperPartitiveMonthText[i].getLength(); + if (nMonthLen > nMatchLen) + { + nMatchLen = nMonthLen; + res = i+1; + } } else if ( bScanPartitiveMonths && StringContains( pUpperPartitiveAbbrevMonthText[i], rString, nPos ) ) { // partitive abbreviated - nPos = nPos + pUpperPartitiveAbbrevMonthText[i].getLength(); - res = sal::static_int_cast< short >(-(i+1)); // negative - break; // for + const int nMonthLen = pUpperPartitiveAbbrevMonthText[i].getLength(); + if (nMonthLen > nMatchLen) + { + nMatchLen = nMonthLen; + res = sal::static_int_cast< short >(-(i+1)); // negative + } } else if ( StringContains( pUpperMonthText[i], rString, nPos ) ) { // noun full names - nPos = nPos + pUpperMonthText[i].getLength(); - res = i+1; - break; // for + const int nMonthLen = pUpperMonthText[i].getLength(); + if (nMonthLen > nMatchLen) + { + nMatchLen = nMonthLen; + res = i+1; + } } else if ( StringContains( pUpperAbbrevMonthText[i], rString, nPos ) ) { // noun abbreviated - nPos = nPos + pUpperAbbrevMonthText[i].getLength(); - res = sal::static_int_cast< short >(-(i+1)); // negative - break; // for + const int nMonthLen = pUpperAbbrevMonthText[i].getLength(); + if (nMonthLen > nMatchLen) + { + nMatchLen = nMonthLen; + res = sal::static_int_cast< short >(-(i+1)); // negative + } } else if ( i == 8 && pUpperAbbrevMonthText[i] == aSeptCorrect && StringContains( aSepShortened, rString, nPos ) ) { // #102136# SEPT/SEP - nPos = nPos + aSepShortened.getLength(); - res = sal::static_int_cast< short >(-(i+1)); // negative - break; // for + const int nMonthLen = aSepShortened.getLength(); + if (nMonthLen > nMatchLen) + { + nMatchLen = nMonthLen; + res = sal::static_int_cast< short >(-(i+1)); // negative + } } } + + nPos += nMatchLen; } return res; |