summaryrefslogtreecommitdiff
path: root/svtools/source/numbers
diff options
context:
space:
mode:
authorEike Rathke <er@openoffice.org>2000-11-23 12:00:06 +0000
committerEike Rathke <er@openoffice.org>2000-11-23 12:00:06 +0000
commit9b419039d9d967ab0d15d1142b27d24851baebeb (patch)
treed0b21652640ce889be298c3c63f58be4f6854ac4 /svtools/source/numbers
parentd00869a12a84a2f1c7d9738e23a34dfcb3a713a5 (diff)
#80660# new format codes AAA, AAAA, E, EE, G, GG, GGG for day names, years and era names
Diffstat (limited to 'svtools/source/numbers')
-rw-r--r--svtools/source/numbers/zformat.cxx66
-rw-r--r--svtools/source/numbers/zforscan.cxx203
-rw-r--r--svtools/source/numbers/zforscan.hxx15
3 files changed, 194 insertions, 90 deletions
diff --git a/svtools/source/numbers/zformat.cxx b/svtools/source/numbers/zformat.cxx
index 288cfe0346f2..046e16f3504e 100644
--- a/svtools/source/numbers/zformat.cxx
+++ b/svtools/source/numbers/zformat.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: zformat.cxx,v $
*
- * $Revision: 1.6 $
+ * $Revision: 1.7 $
*
- * last change: $Author: er $ $Date: 2000-11-18 21:46:43 $
+ * last change: $Author: er $ $Date: 2000-11-23 13:00:06 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -186,7 +186,8 @@ void ImpSvNumberformatInfo::Save(SvStream& rStream, USHORT nAnz) const
for (USHORT i = 0; i < nAnz; i++)
{
rStream.WriteByteString( sStrArray[i], rStream.GetStreamCharSet() );
- switch ( nTypeArray[i] )
+ short nType = nTypeArray[i];
+ switch ( nType )
{ // der Krampf fuer Versionen vor SV_NUMBERFORMATTER_VERSION_NEW_CURR
case SYMBOLTYPE_CURRENCY :
rStream << short( SYMBOLTYPE_STRING );
@@ -196,7 +197,10 @@ void ImpSvNumberformatInfo::Save(SvStream& rStream, USHORT nAnz) const
rStream << short(0); // werden ignoriert (hoffentlich..)
break;
default:
- rStream << nTypeArray[i];
+ if ( nType > NF_KEY_LASTKEYWORD_SO5 )
+ rStream << short( SYMBOLTYPE_STRING ); // all new keywords are string
+ else
+ rStream << nType;
}
}
@@ -2235,7 +2239,7 @@ BOOL SvNumberformat::ImpGetDateOutput(double fNumber,
break;
case NF_KEY_JJ: // JJ
{
- //! TODO: what about negative values? abs and era?
+//! TODO: what about negative values? abs and append era?
sal_Int16 nVal = rCal.getValue( CalendarFieldIndex::YEAR );
if ( 99 < nVal )
nVal %= 100;
@@ -2245,11 +2249,28 @@ BOOL SvNumberformat::ImpGetDateOutput(double fNumber,
}
break;
case NF_KEY_JJJJ: // JJJJ
- //! TODO: what about negative values? abs and era?
+//! TODO: what about negative values? abs and append era?
OutString += String::CreateFromInt32( rCal.getValue(
CalendarFieldIndex::YEAR ) );
break;
+ case NF_KEY_EC: // E
+ {
+//! TODO: what about negative values? abs and append era?
+ sal_Int16 nVal = rCal.getValue( CalendarFieldIndex::YEAR );
+ OutString += String::CreateFromInt32( nVal );
+ }
+ break;
+ case NF_KEY_EEC: // EE
+ {
+//! TODO: what about negative values? abs and append era?
+ sal_Int16 nVal = rCal.getValue( CalendarFieldIndex::YEAR );
+ if ( nVal < 10 )
+ OutString += '0';
+ OutString += String::CreateFromInt32( nVal );
+ }
+ break;
case NF_KEY_NN: // NN
+ case NF_KEY_AAA: // AAA
{
sal_Int16 nVal = rCal.getValue( CalendarFieldIndex::DAY_OF_WEEK );
OutString += rCal.getDisplayName( CalendarDisplayIndex::DAY,
@@ -2257,6 +2278,7 @@ BOOL SvNumberformat::ImpGetDateOutput(double fNumber,
}
break;
case NF_KEY_NNN: // NNN
+ case NF_KEY_AAAA: // AAAA
{
sal_Int16 nVal = rCal.getValue( CalendarFieldIndex::DAY_OF_WEEK );
OutString += rCal.getDisplayName( CalendarDisplayIndex::DAY,
@@ -2275,6 +2297,38 @@ BOOL SvNumberformat::ImpGetDateOutput(double fNumber,
OutString += String::CreateFromInt32( rCal.getValue(
CalendarFieldIndex::WEEK_OF_YEAR ) );
break;
+ case NF_KEY_G: // G
+ {
+ sal_Int16 nVal = rCal.getValue( CalendarFieldIndex::ERA );
+//! TODO: is this right? what if the calendar is not Japanese?
+ sal_Unicode cEra;
+ switch ( nVal )
+ {
+ case 0 : cEra = 'M'; break;
+ case 1 : cEra = 'T'; break;
+ case 2 : cEra = 'S'; break;
+ case 3 : cEra = 'H'; break;
+ default:
+ cEra = '?';
+ DBG_ERRORFILE( "SvNumberformat::ImpGetDateOutput: which era is it?" );
+ }
+ OutString += cEra;
+ }
+ break;
+ case NF_KEY_GG: // GG
+ {
+ sal_Int16 nVal = rCal.getValue( CalendarFieldIndex::ERA );
+ OutString += rCal.getDisplayName( CalendarDisplayIndex::ERA,
+ nVal, 0 );
+ }
+ break;
+ case NF_KEY_GGG: // GGG
+ {
+ sal_Int16 nVal = rCal.getValue( CalendarFieldIndex::ERA );
+ OutString += rCal.getDisplayName( CalendarDisplayIndex::ERA,
+ nVal, 1 );
+ }
+ break;
default:
break;
}
diff --git a/svtools/source/numbers/zforscan.cxx b/svtools/source/numbers/zforscan.cxx
index 041c451db01e..bb8c0dc59aa6 100644
--- a/svtools/source/numbers/zforscan.cxx
+++ b/svtools/source/numbers/zforscan.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: zforscan.cxx,v $
*
- * $Revision: 1.10 $
+ * $Revision: 1.11 $
*
- * last change: $Author: er $ $Date: 2000-11-18 21:46:43 $
+ * last change: $Author: er $ $Date: 2000-11-23 13:00:06 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -160,6 +160,15 @@ void ImpSvNumberformatScan::SetDependentKeywords()
sNameStandardFormat = aFormat.Code;
sKeyword[NF_KEY_GENERAL] = pCharClass->upper( sNameStandardFormat );
+ // preset new calendar keywords
+ sKeyword[NF_KEY_AAA].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "AAA" ) );
+ sKeyword[NF_KEY_AAAA].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "AAAA" ) );
+ sKeyword[NF_KEY_EC].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "E" ) );
+ sKeyword[NF_KEY_EEC].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "EE" ) );
+ sKeyword[NF_KEY_G].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "G" ) );
+ sKeyword[NF_KEY_GG].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GG" ) );
+ sKeyword[NF_KEY_GGG].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GGG" ) );
+
switch ( eLang )
{
case LANGUAGE_GERMAN:
@@ -197,7 +206,7 @@ void ImpSvNumberformatScan::SetDependentKeywords()
break;
default:
{
- // Tag
+ // day
switch ( eLang )
{
case LANGUAGE_ITALIAN :
@@ -206,6 +215,10 @@ void ImpSvNumberformatScan::SetDependentKeywords()
sKeyword[NF_KEY_TT].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GG" ) );
sKeyword[NF_KEY_TTT].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GGG" ) );
sKeyword[NF_KEY_TTTT].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GGGG" ) );
+ // must exchange the era code, same as Xcl
+ sKeyword[NF_KEY_G].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "X" ) );
+ sKeyword[NF_KEY_GG].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "XX" ) );
+ sKeyword[NF_KEY_GGG].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "XXX" ) );
break;
case LANGUAGE_FRENCH :
case LANGUAGE_FRENCH_BELGIAN :
@@ -230,7 +243,7 @@ void ImpSvNumberformatScan::SetDependentKeywords()
sKeyword[NF_KEY_TTT].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "DDD" ) );
sKeyword[NF_KEY_TTTT].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "DDDD" ) );
}
- // Monat
+ // month
switch ( eLang )
{
case LANGUAGE_FINNISH :
@@ -245,7 +258,7 @@ void ImpSvNumberformatScan::SetDependentKeywords()
sKeyword[NF_KEY_MMM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MMM" ) );
sKeyword[NF_KEY_MMMM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MMMM" ) );
}
- // Jahr
+ // year
switch ( eLang )
{
case LANGUAGE_ITALIAN :
@@ -280,6 +293,9 @@ void ImpSvNumberformatScan::SetDependentKeywords()
case LANGUAGE_SPANISH_PUERTO_RICO :
sKeyword[NF_KEY_JJ].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "AA" ) );
sKeyword[NF_KEY_JJJJ].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "AAAA" ) );
+ // must exchange the day of week name code, same as Xcl
+ sKeyword[NF_KEY_AAA].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "OOO" ) );
+ sKeyword[NF_KEY_AAAA].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "OOOO" ) );
break;
case LANGUAGE_DUTCH :
case LANGUAGE_DUTCH_BELGIAN :
@@ -294,7 +310,7 @@ void ImpSvNumberformatScan::SetDependentKeywords()
sKeyword[NF_KEY_JJ].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "YY" ) );
sKeyword[NF_KEY_JJJJ].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "YYYY" ) );
}
- // Stunde
+ // hour
switch ( eLang )
{
case LANGUAGE_DUTCH :
@@ -316,9 +332,9 @@ void ImpSvNumberformatScan::SetDependentKeywords()
sKeyword[NF_KEY_H].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "H" ) );
sKeyword[NF_KEY_HH].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "HH" ) );
}
- // Logisch
+ // boolean
sKeyword[NF_KEY_BOOLEAN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "BOOLEAN" ) );
- // Farbe
+ // colours
sKeyword[NF_KEY_COLOR].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "COLOR" ) );
sKeyword[NF_KEY_BLACK].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "BLACK" ) );
sKeyword[NF_KEY_BLUE].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "BLUE" ) );
@@ -436,22 +452,35 @@ void ImpSvNumberformatScan::ChangeIntl()
SetDependentKeywords();
}
-USHORT ImpSvNumberformatScan::GetKeyWord(const String& sSymbol)
+
+short ImpSvNumberformatScan::GetKeyWord( const String& sSymbol, xub_StrLen nPos )
{
- USHORT i = NF_KEY_LASTKEYWORD; // unbedingt rueckwaerts!!
- String sString = pFormatter->GetCharClass()->upper(sSymbol);
- while (i > 0 && sString.Search(sKeyword[i]) != 0)
- i--; // unbedingt rueckwaerts!!
- if ( i > NF_KEY_LASTOLDKEYWORD && sString != sKeyword[i] )
- { // vielleicht doch noch was anderes?
- // z.B. wird neues NNN in NNNN gefunden, NNNN muss also weitersuchen
- USHORT j = i - 1;
- while (j > 0 && sString.Search(sKeyword[j]) != 0)
- j--; // unbedingt rueckwaerts!!
- if ( j )
- return j;
+ String sString = pFormatter->GetCharClass()->toUpper( sSymbol, nPos, sSymbol.Len() - nPos );
+ // #77026# for the Xcl perverts: the GENERAL keyword is recognized anywhere
+ if ( sString.Search( sKeyword[NF_KEY_GENERAL] ) == 0 )
+ return NF_KEY_GENERAL;
+ //! MUST be a reverse search to find longer strings first
+ short i = NF_KEYWORD_ENTRIES_COUNT-1;
+ BOOL bFound;
+ while ( i > NF_KEY_LASTKEYWORD_SO5 && !(bFound = (sString.Search(sKeyword[i]) == 0)) )
+ i--;
+ // new keywords take precedence over old keywords
+ if ( !bFound )
+ { // skip the gap of colors et al between new and old keywords and search on
+ i = NF_KEY_LASTKEYWORD;
+ while ( i > 0 && sString.Search(sKeyword[i]) != 0 )
+ i--;
+ if ( i > NF_KEY_LASTOLDKEYWORD && sString != sKeyword[i] )
+ { // maybe something else?
+ // e.g. new NNN is found in NNNN, NNNN must search on
+ short j = i - 1;
+ while ( j > 0 && sString.Search(sKeyword[j]) != 0 )
+ j--;
+ if ( j )
+ return j;
+ }
}
- return i; // 0 => nicht gefunden
+ return i; // 0 => not found
}
//---------------------------------------------------------------------------
@@ -586,13 +615,46 @@ short ImpSvNumberformatScan::Next_Symbol( const String& rStr,
default :
{
if ( pChrCls->isLetter( rStr, nPos-1 ) )
- eState = SsGetWord;
+ {
+ short nTmpType = GetKeyWord( rStr, nPos-1 );
+ if ( nTmpType )
+ {
+ eType = nTmpType;
+ xub_StrLen nLen = sKeyword[eType].Len();
+ sSymbol = rStr.Copy( nPos-1, nLen );
+ if ( eType == NF_KEY_E || IsAmbiguousE( eType ) )
+ {
+ sal_Unicode cNext = rStr.GetChar(nPos);
+ switch ( cNext )
+ {
+ case '+' :
+ case '-' : // E+ E- combine to one symbol
+ sSymbol += cNext;
+ eType = NF_KEY_E;
+ nPos++;
+ break;
+ case '0' :
+ case '#' : // scientific E without sign
+ eType = NF_KEY_E;
+ break;
+ }
+ }
+ nPos--;
+ nPos += nLen;
+ eState = SsStop;
+ }
+ else
+ {
+ eState = SsGetWord;
+ sSymbol += cToken;
+ }
+ }
else
{
eType = SYMBOLTYPE_STRING;
eState = SsStop;
+ sSymbol += cToken;
}
- sSymbol += cToken;
}
break;
}
@@ -608,31 +670,29 @@ short ImpSvNumberformatScan::Next_Symbol( const String& rStr,
{
if (cToken == '"')
eState = SsStop;
-// else
- sSymbol += cToken;
+ sSymbol += cToken;
}
break;
case SsGetWord:
{
if ( pChrCls->isLetter( rStr, nPos-1 ) )
- sSymbol += cToken;
+ {
+ short nTmpType = GetKeyWord( rStr, nPos-1 );
+ if ( nTmpType )
+ { // beginning of keyword, stop scan and put back
+ eType = SYMBOLTYPE_STRING;
+ eState = SsStop;
+ nPos--;
+ }
+ else
+ sSymbol += cToken;
+ }
else
{
BOOL bDontStop = FALSE;
switch (cToken)
{
- case '+':
- case '-': // E+ E-
- {
- eType = GetKeyWord(sSymbol);
- if (eType == NF_KEY_E)
- {
- sSymbol += cToken;
- eState = SsStop;
- }
- }
- break;
- case '.': // Sf. Waehrung
+ case '.': // Sf. currency
{
String TestStr = pChrCls->upper(sSymbol);
TestStr += cToken;
@@ -668,18 +728,7 @@ short ImpSvNumberformatScan::Next_Symbol( const String& rStr,
{
eState = SsStop;
nPos--;
- eType = GetKeyWord(sSymbol);
- if (!eType)
- eType = SYMBOLTYPE_STRING;
- else
- {
- xub_StrLen nLen = sKeyword[eType].Len();
- if ( nPos > nStart + nLen )
- {
- nPos = nStart + nLen;
- sSymbol.Erase( nLen );
- }
- }
+ eType = SYMBOLTYPE_STRING;
}
}
}
@@ -688,7 +737,7 @@ short ImpSvNumberformatScan::Next_Symbol( const String& rStr,
{
eState = SsStop;
sSymbol += cToken;
- nRepPos = (nPos - nStart) - 1; // immer > 0!!
+ nRepPos = (nPos - nStart) - 1; // everytime > 0!!
}
break;
case SsGetBlank:
@@ -702,34 +751,7 @@ short ImpSvNumberformatScan::Next_Symbol( const String& rStr,
} // of switch
} // of while
if (eState == SsGetWord)
- {
- eType = GetKeyWord(sSymbol);
- if ( eType )
- {
- xub_StrLen nLen = sKeyword[eType].Len();
- if ( nPos > nStart + nLen )
- {
- nPos = nStart + nLen;
- sSymbol.Erase( nLen );
- }
- }
- else
- {
- eType = SYMBOLTYPE_STRING;
- // #77026# And now for the Xcl perverts: a word containing the
- // GENERAL keyword somewhere must be splitted.
- if ( sSymbol.Len() > sKeyword[NF_KEY_GENERAL].Len() )
- {
- String aUp( pFormatter->GetCharClass()->upper( sSymbol ) );
- xub_StrLen nFound = aUp.Search( sKeyword[NF_KEY_GENERAL], 1 );
- if ( nFound != STRING_NOTFOUND )
- {
- nPos = nStart + nFound;
- sSymbol.Erase( nFound );
- }
- }
- }
- }
+ eType = SYMBOLTYPE_STRING;
return eType;
}
@@ -1013,6 +1035,13 @@ xub_StrLen ImpSvNumberformatScan::ScanType(const String& rString)
case NF_KEY_NNN: // NNN
case NF_KEY_NNNN: // NNNN
case NF_KEY_WW : // WW
+ case NF_KEY_AAA : // AA
+ case NF_KEY_AAAA : // AAA
+ case NF_KEY_EC : // E
+ case NF_KEY_EEC : // EE
+ case NF_KEY_G : // G
+ case NF_KEY_GG : // GG
+ case NF_KEY_GGG : // GGG
eNewType = NUMBERFORMAT_DATE;
break;
case NF_KEY_CCC: // CCC
@@ -1933,6 +1962,13 @@ xub_StrLen ImpSvNumberformatScan::FinalScan( String& rString, String& rComment )
case NF_KEY_NNN: // NNN
case NF_KEY_NNNN: // NNNN
case NF_KEY_WW : // WW
+ case NF_KEY_AAA : // AA
+ case NF_KEY_AAAA : // AAA
+ case NF_KEY_EC : // E
+ case NF_KEY_EEC : // EE
+ case NF_KEY_G : // G
+ case NF_KEY_GG : // GG
+ case NF_KEY_GGG : // GGG
sStrArray[i] = sKeyword[nTypeArray[i]]; // tTtT -> TTTT
break;
default: // andere Keywords
@@ -2146,6 +2182,13 @@ xub_StrLen ImpSvNumberformatScan::FinalScan( String& rString, String& rComment )
case NF_KEY_NNN: // NNN
case NF_KEY_NNNN: // NNNN
case NF_KEY_WW : // WW
+ case NF_KEY_AAA : // AA
+ case NF_KEY_AAAA : // AAA
+ case NF_KEY_EC : // E
+ case NF_KEY_EEC : // EE
+ case NF_KEY_G : // G
+ case NF_KEY_GG : // GG
+ case NF_KEY_GGG : // GGG
sStrArray[i] = sKeyword[nTypeArray[i]]; // tTtT -> TTTT
break;
default: // andere Keywords
diff --git a/svtools/source/numbers/zforscan.hxx b/svtools/source/numbers/zforscan.hxx
index 80df815c298b..54e73d678afa 100644
--- a/svtools/source/numbers/zforscan.hxx
+++ b/svtools/source/numbers/zforscan.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: zforscan.hxx,v $
*
- * $Revision: 1.6 $
+ * $Revision: 1.7 $
*
- * last change: $Author: er $ $Date: 2000-11-18 21:46:43 $
+ * last change: $Author: er $ $Date: 2000-11-23 13:00:06 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -235,8 +235,15 @@ private: // ---- privater Teil
// mehr bis zum '/'
void Reset(); // Reset aller Variablen
// vor Analysestart
- USHORT GetKeyWord(const String& sSymbol); // Vergleicht mit den Keywords
- // return 0 <=> nicht gefunden
+ short GetKeyWord( const String& sSymbol, // determine keyword at nPos
+ xub_StrLen nPos ); // return 0 <=> not found
+
+ inline BOOL IsAmbiguousE( short nKey ) // whether nKey is ambiguous E of NF_KEY_E/NF_KEY_EC
+ {
+ return (nKey == NF_KEY_EC || nKey == NF_KEY_E) &&
+ (sKeyword[NF_KEY_EC] == sKeyword[NF_KEY_E]);
+ }
+
short Next_Symbol(const String& rStr,
xub_StrLen& nPos,
String& sSymbol); // Naechstes Symbol