summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2015-08-06 18:22:16 +0200
committerAndras Timar <andras.timar@collabora.com>2015-09-28 10:06:44 +0200
commitaa19d78a09ab90ee58e79af15c52baf1f01df640 (patch)
tree3734ef1b2147777506ac7bccddea765a984a1759
parent853255aef611be01e2a887cbd6cc177953cdea14 (diff)
Resolves: tdf#93080 short day name and month name may interfere
(cherry picked from commit c7d66949beecab92dc8f1380c54751710aa0b7a2) Conflicts: svl/source/numbers/zforfind.cxx Change-Id: I088633e4cff278e1add8eeea8828f9ba9c9fb140 Reviewed-on: https://gerrit.libreoffice.org/17546 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> (cherry picked from commit d81179c7abeb0601a545e5512e5311b84cb3816a)
-rw-r--r--svl/source/numbers/zforfind.cxx57
-rw-r--r--svl/source/numbers/zforfind.hxx1
2 files changed, 52 insertions, 6 deletions
diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx
index 9bdee3a0ff81..8caafb0b5ac5 100644
--- a/svl/source/numbers/zforfind.cxx
+++ b/svl/source/numbers/zforfind.cxx
@@ -110,6 +110,7 @@ void ImpSvNumberInputScan::Reset()
{
nMonth = 0;
nMonthPos = 0;
+ nDayOfWeek = 0;
nTimePos = 0;
nSign = 0;
nESign = 0;
@@ -2100,6 +2101,33 @@ bool ImpSvNumberInputScan::ScanStartString( const OUString& rString,
{
const sal_Int32 nMonthStart = nPos;
short nTempMonth = GetMonth(rString, nPos);
+ if (nTempMonth < 0)
+ {
+ // Short month and day names may be identical in some locales, e.g.
+ // "mar" for "martes" or "marzo" in Spanish.
+ // Do not let a month name immediately take precedence if a day
+ // name was meant instead. Assume that both could be valid, until
+ // encountered differently or the final evaluation in
+ // IsNumberFormat() checks, but continue with weighing the month
+ // name higher unless we have both day of week and month name here.
+ sal_Int32 nTempPos = nMonthStart;
+ nDayOfWeek = GetDayOfWeek( rString, nTempPos);
+ if (nDayOfWeek < 0)
+ {
+ SkipChar( '.', rString, nTempPos ); // abbreviated
+ SkipString( pFormatter->GetLocaleData()->getLongDateDayOfWeekSep(), rString, nTempPos );
+ SkipBlanks( rString, nTempPos);
+ short nTempTempMonth = GetMonth( rString, nTempPos);
+ if (nTempTempMonth)
+ {
+ // Fall into the else branch below that handles both.
+ nTempMonth = 0;
+ nPos = nMonthStart;
+ nDayOfWeek = 0;
+ // Do not set nDayOfWeek hereafter, anywhere.
+ }
+ }
+ }
if ( nTempMonth ) // month (Jan 1)?
{
if (nPos < rString.getLength()) // Jan1 without separator is not a date
@@ -2120,14 +2148,14 @@ bool ImpSvNumberInputScan::ScanStartString( const OUString& rString,
}
else
{
- int nDayOfWeek = GetDayOfWeek( rString, nPos );
- if ( nDayOfWeek )
+ int nTempDayOfWeek = GetDayOfWeek( rString, nPos );
+ if ( nTempDayOfWeek )
{
// day of week is just parsed away
eScannedType = NUMBERFORMAT_DATE; // !!! it IS a date !!!
if ( nPos < rString.getLength() )
{
- if ( nDayOfWeek < 0 )
+ if ( nTempDayOfWeek < 0 )
{
// abbreviated
if ( rString[ nPos ] == (sal_Unicode)'.' )
@@ -2801,12 +2829,12 @@ bool ImpSvNumberInputScan::ScanEndString( const OUString& rString,
nPos = nPos + rSep.getLength();
SkipBlanks(rString, nPos);
}
- int nDayOfWeek = GetDayOfWeek( rString, nPos );
- if ( nDayOfWeek )
+ int nTempDayOfWeek = GetDayOfWeek( rString, nPos );
+ if ( nTempDayOfWeek )
{
if ( nPos < rString.getLength() )
{
- if ( nDayOfWeek < 0 )
+ if ( nTempDayOfWeek < 0 )
{ // short
if ( rString[ nPos ] == (sal_Unicode)'.' )
{
@@ -3497,6 +3525,14 @@ bool ImpSvNumberInputScan::IsNumberFormat( const OUString& rString, // s
break;
case NUMBERFORMAT_DATE:
+ if (nMonth < 0 && nDayOfWeek < 0 && nAnzNums == 3)
+ {
+ // If both, short month name and day of week name were
+ // detected, and also numbers for full date, assume that we
+ // have a day of week instead of month name.
+ nMonth = 0;
+ nMonthPos = 0;
+ }
if (nMonth)
{ // month name and numbers
if (nAnzNums > 2)
@@ -3543,6 +3579,15 @@ bool ImpSvNumberInputScan::IsNumberFormat( const OUString& rString, // s
break;
case NUMBERFORMAT_DATETIME:
+ if (nMonth < 0 && nDayOfWeek < 0 && nAnzNums >= 5)
+ {
+ // If both, abbreviated month name and day of week name
+ // were detected, and also at least numbers for full date
+ // plus time including minutes, assume that we have a day
+ // of week instead of month name.
+ nMonth = 0;
+ nMonthPos = 0;
+ }
if (nMonth)
{ // month name and numbers
if (nDecPos)
diff --git a/svl/source/numbers/zforfind.hxx b/svl/source/numbers/zforfind.hxx
index 1f03fb9e15ff..8ceeee61fb03 100644
--- a/svl/source/numbers/zforfind.hxx
+++ b/svl/source/numbers/zforfind.hxx
@@ -108,6 +108,7 @@ private:
// negative => short format
short nMonthPos; // 1 = front, 2 = middle
// 3 = end
+ int nDayOfWeek; // Temporary (!) day of week (1..7,-1..-7) if date
sal_uInt16 nTimePos; // Index of first time separator (+1)
short nDecPos; // Index of substring containing "," (+1)
short nNegCheck; // '( )' for negative