Commits

Anonymous committed 0a67df6

sw34bf04: #i46648#: define class for NfKeywordTable
* * *
#i46648#: Use specific NfKeywordTabl

  • Participants
  • Parent commits 440fcb3

Comments (0)

Files changed (8)

File svl/inc/svl/nfkeytab.hxx

 #ifndef INCLUDED_SVTOOLS_NFKEYTAB_HXX
 #define INCLUDED_SVTOOLS_NFKEYTAB_HXX
 
+#include <vector>
 #include <tools/string.hxx>
 
 //! For ImpSvNumberformatScan: first the short symbols, then the long symbols!
     NF_KEYWORD_ENTRIES_COUNT
 };
 
-typedef String NfKeywordTable [NF_KEYWORD_ENTRIES_COUNT];
+class NfKeywordTable
+{
+    typedef ::std::vector<String> Keywords_t;
+    Keywords_t m_keywords;
+
+public:
+    NfKeywordTable() : m_keywords(NF_KEYWORD_ENTRIES_COUNT) {};
+    virtual ~NfKeywordTable() {}
+
+    String & operator[] (Keywords_t::size_type n) { return m_keywords[n]; }
+    const String & operator[] (Keywords_t::size_type n) const { return m_keywords[n]; }
+};
 
 #endif // INCLUDED_SVTOOLS_NFKEYTAB_HXX
 

File svl/source/numbers/zforlist.cxx

         LanguageType eLang )
 {
 	ChangeIntl( eLang );
-    const String* pTable = pFormatScanner->GetKeywords();
+    const NfKeywordTable & rTable = pFormatScanner->GetKeywords();
 	for ( sal_uInt16 i = 0; i < NF_KEYWORD_ENTRIES_COUNT; ++i )
     {
-        rKeywords[i] = pTable[i];
+        rKeywords[i] = rTable[i];
     }
 }
 
 String SvNumberFormatter::GetKeyword( LanguageType eLnge, sal_uInt16 nIndex )
 {
 	ChangeIntl(eLnge);
-    const String* pTable = pFormatScanner->GetKeywords();
-	if ( pTable && nIndex < NF_KEYWORD_ENTRIES_COUNT )
-		return pTable[nIndex];
+    const NfKeywordTable & rTable = pFormatScanner->GetKeywords();
+	if ( nIndex < NF_KEYWORD_ENTRIES_COUNT )
+		return rTable[nIndex];
 
 	DBG_ERROR("GetKeyword: invalid index");
 	return String();
 		CLOffset + SetIndexTable( NF_FRACTION_2, ZF_STANDARD_FRACTION+1 ));
 
 	// Week of year   must be appended here because of nNewExtended
-    const String* pKeyword = pFormatScanner->GetKeywords();
-	aSingleFormatCode.Code = pKeyword[NF_KEY_WW];
+    const NfKeywordTable & rKeyword = pFormatScanner->GetKeywords();
+	aSingleFormatCode.Code = rKeyword[NF_KEY_WW];
 	ImpInsertNewStandardFormat( aSingleFormatCode,
 		CLOffset + SetIndexTable( NF_DATE_WW, nNewExtended++ ),
 		SV_NUMBERFORMATTER_VERSION_NF_DATE_WW );

File svl/source/numbers/zformat.cxx

     xub_StrLen nLen = rString.Len();
     ScanState eState = SsStart;
     sSymbol.Erase();
-    const String* pKeywords = rScan.GetKeywords();
+    const NfKeywordTable & rKeywords = rScan.GetKeywords();
     while (nPos < nLen && eState != SsStop)
     {
         cToken = rString.GetChar(nPos);
                                 BRACKET_SYMBOLTYPE_DBNUM1 - (cDBNum - '1'));
                             eState = SsGetPrefix;
                         }
-                        else if (cUpper == pKeywords[NF_KEY_H].GetChar(0)   ||  // H
-                            cUpper == pKeywords[NF_KEY_MI].GetChar(0)   ||  // M
-                            cUpper == pKeywords[NF_KEY_S].GetChar(0)    )   // S
+                        else if (cUpper == rKeywords[NF_KEY_H].GetChar(0)   ||  // H
+                            cUpper == rKeywords[NF_KEY_MI].GetChar(0)   ||  // M
+                            cUpper == rKeywords[NF_KEY_S].GetChar(0)    )   // S
                         {
                             sSymbol += cToken;
                             eState = SsGetTime;
                 else
                 {
                     sal_Unicode cUpper = rChrCls().toUpper( rString, nPos-1, 1 ).GetChar(0);
-                    if (cUpper == pKeywords[NF_KEY_H].GetChar(0)    ||  // H
-                        cUpper == pKeywords[NF_KEY_MI].GetChar(0)   ||  // M
-                        cUpper == pKeywords[NF_KEY_S].GetChar(0)    )   // S
+                    if (cUpper == rKeywords[NF_KEY_H].GetChar(0)    ||  // H
+                        cUpper == rKeywords[NF_KEY_MI].GetChar(0)   ||  // M
+                        cUpper == rKeywords[NF_KEY_S].GetChar(0)    )   // S
                     {
                         if (cLetter == cToken)
                         {
         const String& rColorName = NumFor[n].GetColorName();
         if ( rColorName.Len() )
         {
-            const String* pKey = rScan.GetKeywords() + NF_KEY_FIRSTCOLOR;
-            for ( int j=NF_KEY_FIRSTCOLOR; j<=NF_KEY_LASTCOLOR; j++, pKey++ )
+            const NfKeywordTable & rKey = rScan.GetKeywords();
+            for ( int j=NF_KEY_FIRSTCOLOR; j<=NF_KEY_LASTCOLOR; j++ )
             {
-                if ( *pKey == rColorName )
+                if ( rKey[j] == rColorName )
                 {
                     aPrefix += '[';
                     aPrefix += rKeywords[j];

File svl/source/numbers/zforscan.cxx

 Color* ImpSvNumberformatScan::GetColor(String& sStr)
 {
 	String sString = pFormatter->GetCharClass()->upper(sStr);
-    const String* pKeyword = GetKeywords();
+    const NfKeywordTable & rKeyword = GetKeywords();
 	size_t i = 0;
 	while (i < NF_MAX_DEFAULT_COLORS &&
-           sString != pKeyword[NF_KEY_FIRSTCOLOR+i] )
+           sString != rKeyword[NF_KEY_FIRSTCOLOR+i] )
 		i++;
     if ( i >= NF_MAX_DEFAULT_COLORS )
     {
     Color* pResult = NULL;
 	if (i >= NF_MAX_DEFAULT_COLORS)
 	{
-        const String& rColorWord = pKeyword[NF_KEY_COLOR];
+        const String& rColorWord = rKeyword[NF_KEY_COLOR];
 		xub_StrLen nPos = sString.Match(rColorWord);
 		if (nPos > 0)
 		{
 			pFormatter->ChangeIntl(eTmpLnge);
 		}
 		else
-            sStr = pKeyword[NF_KEY_FIRSTCOLOR+i];
+            sStr = rKeyword[NF_KEY_FIRSTCOLOR+i];
 
 		pResult = &(StandardColor[i]);
 	}
 short ImpSvNumberformatScan::GetKeyWord( const String& sSymbol, xub_StrLen nPos )
 {
 	String sString = pFormatter->GetCharClass()->toUpper( sSymbol, nPos, sSymbol.Len() - nPos );
-    const String* pKeyword = GetKeywords();
+    const NfKeywordTable & rKeyword = GetKeywords();
 	// #77026# for the Xcl perverts: the GENERAL keyword is recognized anywhere
-    if ( sString.Search( pKeyword[NF_KEY_GENERAL] ) == 0 )
+    if ( sString.Search( rKeyword[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;
 	sal_Bool bFound = sal_False;
     for ( ; i > NF_KEY_LASTKEYWORD_SO5; --i )
     {
-        bFound = sString.Search(pKeyword[i]) == 0;
+        bFound = sString.Search(rKeyword[i]) == 0;
         if ( bFound )
         {
             break;
 	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(pKeyword[i]) != 0 )
+        while ( i > 0 && sString.Search(rKeyword[i]) != 0 )
 			i--;
-        if ( i > NF_KEY_LASTOLDKEYWORD && sString != pKeyword[i] )
+        if ( i > NF_KEY_LASTOLDKEYWORD && sString != rKeyword[i] )
 		{	// found something, but maybe it's something else?
 			// e.g. new NNN is found in NNNN, for NNNN we must search on
 			short j = i - 1;
-            while ( j > 0 && sString.Search(pKeyword[j]) != 0 )
+            while ( j > 0 && sString.Search(rKeyword[j]) != 0 )
 				j--;
-            if ( j && pKeyword[j].Len() > pKeyword[i].Len() )
+            if ( j && rKeyword[j].Len() > rKeyword[i].Len() )
 				return j;
 		}
 	}

File svl/source/numbers/zforscan.hxx

 	const LocaleDataWrapper& GetLoc() const		{ return *pFormatter->GetLocaleData(); }
 	CalendarWrapper& GetCal() const				{ return *pFormatter->GetCalendar(); }
 
-    const String* GetKeywords() const
+    const NfKeywordTable & GetKeywords() const
         {
             if ( bKeywordsNeedInit )
                 InitKeywords();

File sw/source/filter/ww8/wrtww8.cxx

 
 MSWordExportBase::MSWordExportBase( SwDoc *pDocument, SwPaM *pCurrentPam, SwPaM *pOriginalPam )
     : aMainStg(sMainStream), pISet(0), pUsedNumTbl(0), mpTopNodeOfHdFtPage(0),
-    pBmpPal(0), pKeyMap(0), pOLEExp(0), pOCXExp(0), pOleMap(0), 
+    pBmpPal(0), pOLEExp(0), pOCXExp(0), pOleMap(0), 
     mpTableInfo(new ww8::WW8TableInfo()), nUniqueList(0),
     mnHdFtIndex(0), pAktPageDesc(0), pPapPlc(0), pChpPlc(0), pChpIter(0),
     pStyles( NULL ),
 MSWordExportBase::~MSWordExportBase()
 {
     delete pBmpPal;
-    if (pKeyMap)
-        delete[] (NfKeywordTable*)pKeyMap;
     delete pOLEExp;
     delete pOCXExp;
     delete pOleMap;
 #endif
 }
 
+const NfKeywordTable & MSWordExportBase::GetNfKeywordTable()
+{
+    if (pKeyMap.get() == NULL)
+    {
+        pKeyMap.reset(new NfKeywordTable);
+        NfKeywordTable & rKeywordTable = *pKeyMap;
+        rKeywordTable[NF_KEY_D] = ::rtl::OUString::createFromAscii("d");
+        rKeywordTable[NF_KEY_DD] = ::rtl::OUString::createFromAscii("dd");
+        rKeywordTable[NF_KEY_DDD] = ::rtl::OUString::createFromAscii("ddd");
+        rKeywordTable[NF_KEY_DDDD] = ::rtl::OUString::createFromAscii("dddd");
+        rKeywordTable[NF_KEY_M] = ::rtl::OUString::createFromAscii("M");
+        rKeywordTable[NF_KEY_MM] = ::rtl::OUString::createFromAscii("MM");
+        rKeywordTable[NF_KEY_MMM] = ::rtl::OUString::createFromAscii("MMM");
+        rKeywordTable[NF_KEY_MMMM] = ::rtl::OUString::createFromAscii("MMMM");
+        rKeywordTable[NF_KEY_NN] = ::rtl::OUString::createFromAscii("ddd");
+        rKeywordTable[NF_KEY_NNN] = ::rtl::OUString::createFromAscii("dddd");
+        rKeywordTable[NF_KEY_NNNN] = ::rtl::OUString::createFromAscii("dddd");
+        rKeywordTable[NF_KEY_YY] = ::rtl::OUString::createFromAscii("yy");
+        rKeywordTable[NF_KEY_YYYY] = ::rtl::OUString::createFromAscii("yyyy");
+        rKeywordTable[NF_KEY_H] = ::rtl::OUString::createFromAscii("H");
+        rKeywordTable[NF_KEY_HH] = ::rtl::OUString::createFromAscii("HH");
+        rKeywordTable[NF_KEY_MI] = ::rtl::OUString::createFromAscii("m");
+        rKeywordTable[NF_KEY_MMI] = ::rtl::OUString::createFromAscii("mm");
+        rKeywordTable[NF_KEY_S] = ::rtl::OUString::createFromAscii("s");
+        rKeywordTable[NF_KEY_SS] = ::rtl::OUString::createFromAscii("ss");
+        rKeywordTable[NF_KEY_AMPM] = ::rtl::OUString::createFromAscii("AM/PM");
+    }
+
+    return *pKeyMap;
+}
+
 /* vi:set tabstop=4 shiftwidth=4 expandtab: */

File sw/source/filter/ww8/wrtww8.hxx

     WW8_WrtBookmarks* pBkmks;
     WW8_WrtRedlineAuthor* pRedlAuthors;
     BitmapPalette* pBmpPal;
-    void* pKeyMap;
+    boost::shared_ptr<NfKeywordTable> pKeyMap;
     SvxMSExportOLEObjects* pOLEExp;
     SwMSConvertControls* pOCXExp;
     WW8OleMaps* pOleMap;
     bool GetBookmarks( const SwTxtNode& rNd, xub_StrLen nStt, xub_StrLen nEnd,
             IMarkVector& rArr );
 
+    const NfKeywordTable & GetNfKeywordTable();
+
 public:
     MSWordExportBase( SwDoc *pDocument, SwPaM *pCurrentPam, SwPaM *pOriginalPam );
     virtual ~MSWordExportBase();

File sw/source/filter/ww8/ww8atr.cxx

     const SvNumberformat* pNumFmt = pNFmtr->GetEntry( nFmtIdx );
     if( pNumFmt )
     {
-        //sal_uInt16 nLng = rFld.GetLanguage();
-        LocaleDataWrapper aLocDat( pNFmtr->GetServiceManager(),
-            MsLangId::convertLanguageToLocale( LANGUAGE_ENGLISH_US ) );
-
-        if( !pKeyMap )
-        {
-            pKeyMap = new NfKeywordTable;
-            NfKeywordTable& rKeyMap = *(NfKeywordTable*)pKeyMap;
-            pNFmtr->FillKeywordTable( rKeyMap, LANGUAGE_ENGLISH_US );
-        }
-
-        String sFmt(pNumFmt->GetMappedFormatstring(*(NfKeywordTable*)pKeyMap,
+        sal_uInt16 nLng = rFld.GetLanguage();
+        LocaleDataWrapper aLocDat(pNFmtr->GetServiceManager(),
+                                  MsLangId::convertLanguageToLocale(nLng));
+
+        String sFmt(pNumFmt->GetMappedFormatstring(GetNfKeywordTable(),
             aLocDat));
+
         if (sFmt.Len())
         {
             sw::ms::SwapQuotesInField(sFmt);