diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-06-17 21:01:05 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-06-18 15:13:51 +0100 |
commit | 06e2005ed83567452783003e3113ad6a92190c2d (patch) | |
tree | bb3a92154bb0bbaeda1e6d548f467229206dd49d /unotools | |
parent | 8e01e881451333eadb8e23f619e2b4014de1442a (diff) |
convert LocaleDataWrapper to OUString
Change-Id: Icb5f5adf9139d1c0f0e86d8128ea6742ce20b138
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/inc/unotools/localedatawrapper.hxx | 250 | ||||
-rw-r--r-- | unotools/source/i18n/localedatawrapper.cxx | 211 |
2 files changed, 227 insertions, 234 deletions
diff --git a/unotools/inc/unotools/localedatawrapper.hxx b/unotools/inc/unotools/localedatawrapper.hxx index 6474ba05277b..0743c5be2491 100644 --- a/unotools/inc/unotools/localedatawrapper.hxx +++ b/unotools/inc/unotools/localedatawrapper.hxx @@ -30,16 +30,14 @@ #define _UNOTOOLS_LOCALEDATAWRAPPER_HXX #include <boost/noncopyable.hpp> -#include <tools/string.hxx> +#include <boost/shared_ptr.hpp> #include <com/sun/star/i18n/XLocaleData4.hpp> #include <com/sun/star/i18n/LocaleItem.hpp> #include <com/sun/star/i18n/reservedWords.hpp> +#include <rtl/ustring.hxx> #include <unotools/readwritemutexguard.hxx> #include "unotools/unotoolsdllapi.h" -#include <boost/shared_ptr.hpp> - - namespace com { namespace sun { namespace star { namespace lang { class XMultiServiceFactory; @@ -75,10 +73,10 @@ class UNOTOOLS_DLLPUBLIC LocaleDataWrapper : private boost::noncopyable ::com::sun::star::uno::Sequence< ::rtl::OUString > aReservedWordSeq; ::com::sun::star::uno::Sequence< sal_Int32 > aGrouping; // cached items - String aLocaleItem[::com::sun::star::i18n::LocaleItem::COUNT]; - String aReservedWord[::com::sun::star::i18n::reservedWords::COUNT]; - String aCurrSymbol; - String aCurrBankSymbol; + rtl::OUString aLocaleItem[::com::sun::star::i18n::LocaleItem::COUNT]; + rtl::OUString aReservedWord[::com::sun::star::i18n::reservedWords::COUNT]; + rtl::OUString aCurrSymbol; + rtl::OUString aCurrBankSymbol; int nDateFormat; int nLongDateFormat; sal_uInt16 nCurrPositiveFormat; @@ -92,32 +90,32 @@ class UNOTOOLS_DLLPUBLIC LocaleDataWrapper : private boost::noncopyable sal_Unicode cCurrZeroChar; // whenever Locale changes - void invalidateData(); + void invalidateData(); - void getOneLocaleItemImpl( sal_Int16 nItem ); - const String& getOneLocaleItem( sal_Int16 nItem ) const; + void getOneLocaleItemImpl( sal_Int16 nItem ); + const rtl::OUString& getOneLocaleItem( sal_Int16 nItem ) const; - void getOneReservedWordImpl( sal_Int16 nWord ); - const String& getOneReservedWord( sal_Int16 nWord ) const; + void getOneReservedWordImpl( sal_Int16 nWord ); + const rtl::OUString& getOneReservedWord( sal_Int16 nWord ) const; - void getCurrSymbolsImpl(); - void getCurrFormatsImpl(); + void getCurrSymbolsImpl(); + void getCurrFormatsImpl(); - void scanCurrFormatImpl( const String& rCode, - xub_StrLen nStart, xub_StrLen& nSign, - xub_StrLen& nPar, xub_StrLen& nNum, - xub_StrLen& nBlank, xub_StrLen& nSym ); + void scanCurrFormatImpl( const rtl::OUString& rCode, + sal_Int32 nStart, sal_Int32& nSign, + sal_Int32& nPar, sal_Int32& nNum, + sal_Int32& nBlank, sal_Int32& nSym ); - void getDateFormatsImpl(); - DateFormat scanDateFormatImpl( const String& rCode ); + void getDateFormatsImpl(); + DateFormat scanDateFormatImpl( const rtl::OUString& rCode ); - void getDefaultCalendarImpl(); + void getDefaultCalendarImpl(); - sal_Unicode* ImplAddFormatNum( sal_Unicode* pBuf, - sal_Int64 nNumber, sal_uInt16 nDecimals, - sal_Bool bUseThousandSep, sal_Bool bTrailingZeros ) const; + sal_Unicode* ImplAddFormatNum( sal_Unicode* pBuf, + sal_Int64 nNumber, sal_uInt16 nDecimals, + sal_Bool bUseThousandSep, sal_Bool bTrailingZeros ) const; - void getDigitGroupingImpl(); + void getDigitGroupingImpl(); public: LocaleDataWrapper( @@ -172,7 +170,7 @@ public: static ::com::sun::star::uno::Sequence< sal_uInt16 > getInstalledLanguageTypes(); /// maps the LocaleData string to the International enum - MeasurementSystem mapMeasurementStringToEnum( const String& rMS ) const; + MeasurementSystem mapMeasurementStringToEnum( const rtl::OUString& rMS ) const; /// Convenience method to obtain the default calendar. const ::boost::shared_ptr< ::com::sun::star::i18n::Calendar2 > getDefaultCalendar() const; @@ -197,107 +195,107 @@ public: // Functionality of class International methods, LocaleItem - inline const String& getDateSep() const + const rtl::OUString& getDateSep() const { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::DATE_SEPARATOR ); } - inline const String& getNumThousandSep() const + const rtl::OUString& getNumThousandSep() const { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::THOUSAND_SEPARATOR ); } - inline const String& getNumDecimalSep() const + const rtl::OUString& getNumDecimalSep() const { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::DECIMAL_SEPARATOR ); } - inline const String& getTimeSep() const + const rtl::OUString& getTimeSep() const { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::TIME_SEPARATOR ); } - inline const String& getTime100SecSep() const + const rtl::OUString& getTime100SecSep() const { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::TIME_100SEC_SEPARATOR ); } - inline const String& getListSep() const - { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::LIST_SEPARATOR ); } - inline const String& getQuotationMarkStart() const - { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::SINGLE_QUOTATION_START ); } - inline const String& getQuotationMarkEnd() const - { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::SINGLE_QUOTATION_END ); } - inline const String& getDoubleQuotationMarkStart() const - { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::DOUBLE_QUOTATION_START ); } - inline const String& getDoubleQuotationMarkEnd() const - { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::DOUBLE_QUOTATION_END ); } - inline const String& getMeasurementSystem() const - { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::MEASUREMENT_SYSTEM ); } - inline MeasurementSystem getMeasurementSystemEnum() const - { return mapMeasurementStringToEnum( getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::MEASUREMENT_SYSTEM ) ); } - inline const String& getTimeAM() const - { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::TIME_AM ); } - inline const String& getTimePM() const - { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::TIME_PM ); } - inline const String& getLongDateDayOfWeekSep() const - { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::LONG_DATE_DAY_OF_WEEK_SEPARATOR ); } - inline const String& getLongDateDaySep() const - { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::LONG_DATE_DAY_SEPARATOR ); } - inline const String& getLongDateMonthSep() const - { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::LONG_DATE_MONTH_SEPARATOR ); } - inline const String& getLongDateYearSep() const - { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::LONG_DATE_YEAR_SEPARATOR ); } + const rtl::OUString& getListSep() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::LIST_SEPARATOR ); } + const rtl::OUString& getQuotationMarkStart() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::SINGLE_QUOTATION_START ); } + const rtl::OUString& getQuotationMarkEnd() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::SINGLE_QUOTATION_END ); } + const rtl::OUString& getDoubleQuotationMarkStart() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::DOUBLE_QUOTATION_START ); } + const rtl::OUString& getDoubleQuotationMarkEnd() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::DOUBLE_QUOTATION_END ); } + const rtl::OUString& getMeasurementSystem() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::MEASUREMENT_SYSTEM ); } + MeasurementSystem getMeasurementSystemEnum() const + { return mapMeasurementStringToEnum( getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::MEASUREMENT_SYSTEM ) ); } + const rtl::OUString& getTimeAM() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::TIME_AM ); } + const rtl::OUString& getTimePM() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::TIME_PM ); } + const rtl::OUString& getLongDateDayOfWeekSep() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::LONG_DATE_DAY_OF_WEEK_SEPARATOR ); } + const rtl::OUString& getLongDateDaySep() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::LONG_DATE_DAY_SEPARATOR ); } + const rtl::OUString& getLongDateMonthSep() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::LONG_DATE_MONTH_SEPARATOR ); } + const rtl::OUString& getLongDateYearSep() const + { return getOneLocaleItem( ::com::sun::star::i18n::LocaleItem::LONG_DATE_YEAR_SEPARATOR ); } // currency - const String& getCurrSymbol() const; - const String& getCurrBankSymbol() const; - sal_uInt16 getCurrPositiveFormat() const; - sal_uInt16 getCurrNegativeFormat() const; - sal_uInt16 getCurrDigits() const; + const rtl::OUString& getCurrSymbol() const; + const rtl::OUString& getCurrBankSymbol() const; + sal_uInt16 getCurrPositiveFormat() const; + sal_uInt16 getCurrNegativeFormat() const; + sal_uInt16 getCurrDigits() const; // simple date and time formatting - DateFormat getDateFormat() const; - DateFormat getLongDateFormat() const; - /// only numerical values of Gregorian calendar - String getDate( const Date& rDate ) const; - String getTime( const Time& rTime, sal_Bool bSec = sal_True, - sal_Bool b100Sec = sal_False ) const; - String getDuration( const Time& rTime, - sal_Bool bSec = sal_True, sal_Bool b100Sec = sal_False ) const; - - /** The CalendarWrapper already <b>MUST</b> - have loaded a calendar. - @param nDisplayDayOfWeek - 0 := abbreviated name - 1 := full name - @param bDayOfMonthWithLeadingZero - <FALSE/> := without leading zero - <TRUE/> := with leading zero if <10 - @param nDisplayMonth - 0 := abbreviated name - 1 := full name - @param bTwoDigitYear - <FALSE/> := full year - <TRUE/> := year % 100 - */ - String getLongDate( const Date& rDate, - CalendarWrapper& rCal, - sal_Int16 nDisplayDayOfWeek = 1, - sal_Bool bDayOfMonthWithLeadingZero = sal_False, - sal_Int16 nDisplayMonth = 1, - sal_Bool bTwoDigitYear = sal_False - ) const; - - /** Simple number formatting - @param nNumber - value * 10**nDecimals - @param bTrailingZeros - </sal_True> := always display trailing zeros in - decimal places, even if integer value. - </sal_False> := trailing zeros are only displayed - if the value is not an integer value. - */ - String getNum( sal_Int64 nNumber, sal_uInt16 nDecimals, - sal_Bool bUseThousandSep = sal_True, - sal_Bool bTrailingZeros = sal_True ) const; - - /// "Secure" currency formatted string. - String getCurr( sal_Int64 nNumber, sal_uInt16 nDecimals, - const String& rCurrencySymbol, - sal_Bool bUseThousandSep = sal_True ) const; - /** Default currency formatted string, use with - care as default currency may change in any - locale, for example, DEM -> EUR */ - String getCurr( sal_Int64 nNumber, sal_uInt16 nDecimals, - sal_Bool bUseThousandSep = sal_True ) const - { return getCurr( nNumber, nDecimals, - getCurrSymbol(), bUseThousandSep ); } + DateFormat getDateFormat() const; + DateFormat getLongDateFormat() const; + /// only numerical values of Gregorian calendar + rtl::OUString getDate( const Date& rDate ) const; + rtl::OUString getTime( const Time& rTime, sal_Bool bSec = sal_True, + sal_Bool b100Sec = sal_False ) const; + rtl::OUString getDuration( const Time& rTime, + sal_Bool bSec = sal_True, sal_Bool b100Sec = sal_False ) const; + + /** The CalendarWrapper already <b>MUST</b> + have loaded a calendar. + @param nDisplayDayOfWeek + 0 := abbreviated name + 1 := full name + @param bDayOfMonthWithLeadingZero + <FALSE/> := without leading zero + <TRUE/> := with leading zero if <10 + @param nDisplayMonth + 0 := abbreviated name + 1 := full name + @param bTwoDigitYear + <FALSE/> := full year + <TRUE/> := year % 100 + */ + rtl::OUString getLongDate( const Date& rDate, + CalendarWrapper& rCal, + sal_Int16 nDisplayDayOfWeek = 1, + sal_Bool bDayOfMonthWithLeadingZero = sal_False, + sal_Int16 nDisplayMonth = 1, + sal_Bool bTwoDigitYear = sal_False + ) const; + + /** Simple number formatting + @param nNumber + value * 10**nDecimals + @param bTrailingZeros + </sal_True> := always display trailing zeros in + decimal places, even if integer value. + </sal_False> := trailing zeros are only displayed + if the value is not an integer value. + */ + rtl::OUString getNum( sal_Int64 nNumber, sal_uInt16 nDecimals, + sal_Bool bUseThousandSep = sal_True, + sal_Bool bTrailingZeros = sal_True ) const; + + /// "Secure" currency formatted string. + rtl::OUString getCurr( sal_Int64 nNumber, sal_uInt16 nDecimals, + const rtl::OUString& rCurrencySymbol, + sal_Bool bUseThousandSep = sal_True ) const; + /** Default currency formatted string, use with + care as default currency may change in any + locale, for example, DEM -> EUR */ + rtl::OUString getCurr( sal_Int64 nNumber, sal_uInt16 nDecimals, + sal_Bool bUseThousandSep = sal_True ) const + { return getCurr( nNumber, nDecimals, + getCurrSymbol(), bUseThousandSep ); } // dummy returns, to be implemented inline sal_Unicode getCurrZeroChar() const @@ -313,19 +311,19 @@ public: // reserved words - inline const String& getTrueWord() const + const rtl::OUString& getTrueWord() const { return getOneReservedWord( ::com::sun::star::i18n::reservedWords::TRUE_WORD ); } - inline const String& getFalseWord() const + const rtl::OUString& getFalseWord() const { return getOneReservedWord( ::com::sun::star::i18n::reservedWords::FALSE_WORD ); } /// return a quarter string matching nQuarter (0..3) => "1st quarter" .. "4th quarter" - inline const String& getQuarterWord( sal_Int16 nQuarter ) const + const rtl::OUString& getQuarterWord( sal_Int16 nQuarter ) const { return getOneReservedWord( ::com::sun::star::i18n::reservedWords::QUARTER1_WORD + nQuarter ); } - inline const String& getAboveWord() const + const rtl::OUString& getAboveWord() const { return getOneReservedWord( ::com::sun::star::i18n::reservedWords::ABOVE_WORD ); } - inline const String& getBelowWord() const + const rtl::OUString& getBelowWord() const { return getOneReservedWord( ::com::sun::star::i18n::reservedWords::BELOW_WORD ); } /// return a quarter abbreviation string matching nQuarter (0..3) => "Q1" .. "Q2" - inline const String& getQuarterAbbreviation( sal_Int16 nQuarter ) const + const rtl::OUString& getQuarterAbbreviation( sal_Int16 nQuarter ) const { return getOneReservedWord( ::com::sun::star::i18n::reservedWords::QUARTER1_ABBREVIATION + nQuarter ); } /** Return whether locale data checks are enabled. @@ -347,7 +345,7 @@ public: /** Ouput a message during locale data checking. The (UTF-8) string is written to stderr and in a non-product build or if DBG_UTIL is enabled also raised as an assertion message box. */ - static void outputCheckMessage( const String& rMsg ); + static void outputCheckMessage( const rtl::OUString& rMsg ); static void outputCheckMessage( const char* pStr); private: diff --git a/unotools/source/i18n/localedatawrapper.cxx b/unotools/source/i18n/localedatawrapper.cxx index 1e2ee1562465..698a457d6724 100644 --- a/unotools/source/i18n/localedatawrapper.cxx +++ b/unotools/source/i18n/localedatawrapper.cxx @@ -110,24 +110,20 @@ const ::com::sun::star::lang::Locale& LocaleDataWrapper::getLocale() const void LocaleDataWrapper::invalidateData() { - aCurrSymbol.Erase(); - aCurrBankSymbol.Erase(); + aCurrSymbol = rtl::OUString(); + aCurrBankSymbol = rtl::OUString(); nDateFormat = nLongDateFormat = nDateFormatInvalid; nCurrPositiveFormat = nCurrNegativeFormat = nCurrDigits = nCurrFormatInvalid; if ( bLocaleDataItemValid ) { - for ( sal_Int32 j=0; j<LocaleItem::COUNT; j++ ) - { - aLocaleItem[j].Erase(); - } + for (sal_Int32 j=0; j<LocaleItem::COUNT; ++j) + aLocaleItem[j] = rtl::OUString(); bLocaleDataItemValid = sal_False; } if ( bReservedWordValid ) { - for ( sal_Int16 j=0; j<reservedWords::COUNT; j++ ) - { - aReservedWord[j].Erase(); - } + for ( sal_Int16 j=0; j<reservedWords::COUNT; ++j ) + aReservedWord[j] = rtl::OUString(); bReservedWordValid = sal_False; } xDefaultCalendar.reset(); @@ -370,7 +366,7 @@ void LocaleDataWrapper::invalidateData() return rInstalledLanguageTypes; } -const String& LocaleDataWrapper::getOneLocaleItem( sal_Int16 nItem ) const +const rtl::OUString& LocaleDataWrapper::getOneLocaleItem( sal_Int16 nItem ) const { ::utl::ReadWriteGuard aGuard( aMutex ); if ( nItem >= LocaleItem::COUNT ) @@ -378,7 +374,7 @@ const String& LocaleDataWrapper::getOneLocaleItem( sal_Int16 nItem ) const SAL_WARN( "unotools", "getOneLocaleItem: bounds" ); return aLocaleItem[0]; } - if ( aLocaleItem[nItem].Len() == 0 ) + if (aLocaleItem[nItem].isEmpty()) { // no cached content aGuard.changeReadToWrite(); ((LocaleDataWrapper*)this)->getOneLocaleItemImpl( nItem ); @@ -466,7 +462,7 @@ void LocaleDataWrapper::getOneReservedWordImpl( sal_Int16 nWord ) } -const String& LocaleDataWrapper::getOneReservedWord( sal_Int16 nWord ) const +const rtl::OUString& LocaleDataWrapper::getOneReservedWord( sal_Int16 nWord ) const { ::utl::ReadWriteGuard aGuard( aMutex ); if ( nWord < 0 || nWord >= reservedWords::COUNT ) @@ -474,7 +470,7 @@ const String& LocaleDataWrapper::getOneReservedWord( sal_Int16 nWord ) const SAL_WARN( "unotools", "getOneReservedWord: bounds" ); nWord = reservedWords::FALSE_WORD; } - if ( aReservedWord[nWord].Len() == 0 ) + if (aReservedWord[nWord].isEmpty()) { // no cached content aGuard.changeReadToWrite(); ((LocaleDataWrapper*)this)->getOneReservedWordImpl( nWord ); @@ -483,10 +479,10 @@ const String& LocaleDataWrapper::getOneReservedWord( sal_Int16 nWord ) const } -MeasurementSystem LocaleDataWrapper::mapMeasurementStringToEnum( const String& rMS ) const +MeasurementSystem LocaleDataWrapper::mapMeasurementStringToEnum( const rtl::OUString& rMS ) const { //! TODO: could be cached too - if ( rMS.EqualsIgnoreCaseAscii( "metric" ) ) + if ( rMS.equalsIgnoreAsciiCase( "metric" ) ) return MEASURE_METRIC; //! TODO: other measurement systems? => extend enum MeasurementSystem return MEASURE_US; @@ -543,10 +539,10 @@ const ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem2 > L // --- currencies ----------------------------------------------------- -const String& LocaleDataWrapper::getCurrSymbol() const +const rtl::OUString& LocaleDataWrapper::getCurrSymbol() const { ::utl::ReadWriteGuard aGuard( aMutex ); - if ( !aCurrSymbol.Len() ) + if (aCurrSymbol.isEmpty()) { aGuard.changeReadToWrite(); ((LocaleDataWrapper*)this)->getCurrSymbolsImpl(); @@ -555,10 +551,10 @@ const String& LocaleDataWrapper::getCurrSymbol() const } -const String& LocaleDataWrapper::getCurrBankSymbol() const +const rtl::OUString& LocaleDataWrapper::getCurrBankSymbol() const { ::utl::ReadWriteGuard aGuard( aMutex ); - if ( !aCurrBankSymbol.Len() ) + if (aCurrBankSymbol.isEmpty()) { aGuard.changeReadToWrite(); ((LocaleDataWrapper*)this)->getCurrSymbolsImpl(); @@ -628,7 +624,7 @@ void LocaleDataWrapper::getCurrSymbolsImpl() if (areChecksEnabled()) outputCheckMessage( String( RTL_CONSTASCII_USTRINGPARAM( "LocaleDataWrapper::getCurrSymbolsImpl: no currency at all, using ShellsAndPebbles"))); - aCurrSymbol.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "ShellsAndPebbles" ) ); + aCurrSymbol = rtl::OUString("ShellsAndPebbles"); aCurrBankSymbol = aCurrSymbol; nCurrPositiveFormat = nCurrNegativeFormat = nCurrFormatDefault; nCurrDigits = 2; @@ -641,13 +637,13 @@ void LocaleDataWrapper::getCurrSymbolsImpl() } -void LocaleDataWrapper::scanCurrFormatImpl( const String& rCode, - xub_StrLen nStart, xub_StrLen& nSign, xub_StrLen& nPar, - xub_StrLen& nNum, xub_StrLen& nBlank, xub_StrLen& nSym ) +void LocaleDataWrapper::scanCurrFormatImpl( const rtl::OUString& rCode, + sal_Int32 nStart, sal_Int32& nSign, sal_Int32& nPar, + sal_Int32& nNum, sal_Int32& nBlank, sal_Int32& nSym ) { - nSign = nPar = nNum = nBlank = nSym = STRING_NOTFOUND; - const sal_Unicode* const pStr = rCode.GetBuffer(); - const sal_Unicode* const pStop = pStr + rCode.Len(); + nSign = nPar = nNum = nBlank = nSym = -1; + const sal_Unicode* const pStr = rCode.getStr(); + const sal_Unicode* const pStop = pStr + rCode.getLength(); const sal_Unicode* p = pStr + nStart; int nInSection = 0; sal_Bool bQuote = sal_False; @@ -667,17 +663,17 @@ void LocaleDataWrapper::scanCurrFormatImpl( const String& rCode, bQuote = sal_True; break; case '-' : - if ( !nInSection && nSign == STRING_NOTFOUND ) - nSign = (xub_StrLen)(p - pStr); + if (!nInSection && nSign == -1) + nSign = p - pStr; break; case '(' : - if ( !nInSection && nPar == STRING_NOTFOUND ) - nPar = (xub_StrLen)(p - pStr); + if (!nInSection && nPar == -1) + nPar = p - pStr; break; case '0' : case '#' : - if ( !nInSection && nNum == STRING_NOTFOUND ) - nNum = (xub_StrLen)(p - pStr); + if (!nInSection && nNum == -1) + nNum = p - pStr; break; case '[' : nInSection++; @@ -686,17 +682,17 @@ void LocaleDataWrapper::scanCurrFormatImpl( const String& rCode, if ( nInSection ) { nInSection--; - if ( !nInSection && nBlank == STRING_NOTFOUND - && nSym != STRING_NOTFOUND && p < pStop-1 && *(p+1) == ' ' ) - nBlank = (xub_StrLen)(p - pStr + 1); + if (!nInSection && nBlank == -1 + && nSym != -1 && p < pStop-1 && *(p+1) == ' ' ) + nBlank = p - pStr + 1; } break; case '$' : - if ( nSym == STRING_NOTFOUND && nInSection && *(p-1) == '[' ) + if (nSym == -1 && nInSection && *(p-1) == '[') { - nSym = (xub_StrLen)(p - pStr + 1); - if ( nNum != STRING_NOTFOUND && *(p-2) == ' ' ) - nBlank = (xub_StrLen)(p - pStr - 2); + nSym = p - pStr + 1; + if (nNum != -1 && *(p-2) == ' ') + nBlank = p - pStr - 2; } break; case ';' : @@ -704,14 +700,14 @@ void LocaleDataWrapper::scanCurrFormatImpl( const String& rCode, p = pStop; break; default: - if ( !nInSection && nSym == STRING_NOTFOUND && rCode.Equals( aCurrSymbol, (xub_StrLen)(p-pStr), aCurrSymbol.Len() ) ) + if (!nInSection && nSym == -1 && String(rCode).Equals( aCurrSymbol, (xub_StrLen)(p-pStr), aCurrSymbol.getLength())) { // currency symbol not surrounded by [$...] - nSym = (xub_StrLen)(p - pStr); - if ( nBlank == STRING_NOTFOUND && pStr < p && *(p-1) == ' ' ) - nBlank = (xub_StrLen)(p - pStr - 1); - p += aCurrSymbol.Len() - 1; - if ( nBlank == STRING_NOTFOUND && p < pStop-2 && *(p+2) == ' ' ) - nBlank = (xub_StrLen)(p - pStr + 2); + nSym = p - pStr; + if (nBlank == -1 && pStr < p && *(p-1) == ' ') + nBlank = p - pStr - 1; + p += aCurrSymbol.getLength() - 1; + if (nBlank == -1 && p < pStop-2 && *(p+2) == ' ') + nBlank = p - pStr + 2; } } } @@ -719,7 +715,6 @@ void LocaleDataWrapper::scanCurrFormatImpl( const String& rCode, } } - void LocaleDataWrapper::getCurrFormatsImpl() { NumberFormatCodeWrapper aNumberFormatCode( xSMgr, getLocale() ); @@ -772,18 +767,18 @@ void LocaleDataWrapper::getCurrFormatsImpl() // make sure it's loaded getCurrSymbol(); - xub_StrLen nSign, nPar, nNum, nBlank, nSym; + sal_Int32 nSign, nPar, nNum, nBlank, nSym; // positive format nElem = (nDef >= 0 ? nDef : (nNeg >= 0 ? nNeg : 0)); scanCurrFormatImpl( pFormatArr[nElem].Code, 0, nSign, nPar, nNum, nBlank, nSym ); - if (areChecksEnabled() && (nNum == STRING_NOTFOUND || nSym == STRING_NOTFOUND)) + if (areChecksEnabled() && (nNum == -1 || nSym == -1)) { rtl::OUString aMsg( RTL_CONSTASCII_USTRINGPARAM( "LocaleDataWrapper::getCurrFormatsImpl: CurrPositiveFormat?")); outputCheckMessage( appendLocaleInfo( aMsg ) ); } - if ( nBlank == STRING_NOTFOUND ) + if (nBlank == -1) { if ( nSym < nNum ) nCurrPositiveFormat = 0; // $1 @@ -804,17 +799,17 @@ void LocaleDataWrapper::getCurrFormatsImpl() else { const ::rtl::OUString& rCode = pFormatArr[nNeg].Code; - xub_StrLen nDelim = (xub_StrLen)rCode.indexOf( ';' ); + sal_Int32 nDelim = rCode.indexOf(';'); scanCurrFormatImpl( rCode, nDelim+1, nSign, nPar, nNum, nBlank, nSym ); - if (areChecksEnabled() && (nNum == STRING_NOTFOUND || - nSym == STRING_NOTFOUND || (nPar == STRING_NOTFOUND && - nSign == STRING_NOTFOUND))) + if (areChecksEnabled() && (nNum == -1 || + nSym == -1 || (nPar == -1 && + nSign == -1))) { rtl::OUString aMsg( RTL_CONSTASCII_USTRINGPARAM( "LocaleDataWrapper::getCurrFormatsImpl: CurrNegativeFormat?")); outputCheckMessage( appendLocaleInfo( aMsg ) ); } - if ( nBlank == STRING_NOTFOUND ) + if (nBlank == -1) { if ( nSym < nNum ) { @@ -894,7 +889,7 @@ DateFormat LocaleDataWrapper::getLongDateFormat() const } -DateFormat LocaleDataWrapper::scanDateFormatImpl( const String& rCode ) +DateFormat LocaleDataWrapper::scanDateFormatImpl( const rtl::OUString& rCode ) { // Only some european versions were translated, the ones with different // keyword combinations are: @@ -902,35 +897,35 @@ DateFormat LocaleDataWrapper::scanDateFormatImpl( const String& rCode ) // Dutch DMJ, Finnish PKV // default is English keywords for every other language - xub_StrLen nDay = rCode.Search( 'D' ); - xub_StrLen nMonth = rCode.Search( 'M' ); - xub_StrLen nYear = rCode.Search( 'Y' ); - if ( nDay == STRING_NOTFOUND || nMonth == STRING_NOTFOUND || nYear == STRING_NOTFOUND ) + sal_Int32 nDay = rCode.indexOf('D'); + sal_Int32 nMonth = rCode.indexOf('M'); + sal_Int32 nYear = rCode.indexOf('Y'); + if (nDay == -1 || nMonth == -1 || nYear == -1) { // This algorithm assumes that all three parts (DMY) are present - if ( nMonth == STRING_NOTFOUND ) + if (nMonth == -1) { // only Finnish has something else than 'M' for month - nMonth = rCode.Search( 'K' ); - if ( nMonth != STRING_NOTFOUND ) + nMonth = rCode.indexOf('K'); + if (nMonth != -1) { - nDay = rCode.Search( 'P' ); - nYear = rCode.Search( 'V' ); + nDay = rCode.indexOf('P'); + nYear = rCode.indexOf('V'); } } - else if ( nDay == STRING_NOTFOUND ) + else if (nDay == -1) { // We have a month 'M' if we reach this branch. // Possible languages containing 'M' but no 'D': // German, French, Italian - nDay = rCode.Search( 'T' ); // German - if ( nDay != STRING_NOTFOUND ) - nYear = rCode.Search( 'J' ); + nDay = rCode.indexOf('T'); // German + if (nDay != -1) + nYear = rCode.indexOf('J'); else { - nYear = rCode.Search( 'A' ); // French, Italian - if ( nYear != STRING_NOTFOUND ) + nYear = rCode.indexOf('A'); // French, Italian + if (nYear != -1) { - nDay = rCode.Search( 'J' ); // French - if ( nDay == STRING_NOTFOUND ) - nDay = rCode.Search( 'G' ); // Italian + nDay = rCode.indexOf('J'); // French + if (nDay == -1) + nDay = rCode.indexOf('G'); // Italian } } } @@ -938,11 +933,11 @@ DateFormat LocaleDataWrapper::scanDateFormatImpl( const String& rCode ) { // We have a month 'M' and a day 'D'. // Possible languages containing 'D' and 'M' but not 'Y': // Spanish, Dutch - nYear = rCode.Search( 'A' ); // Spanish - if ( nYear == STRING_NOTFOUND ) - nYear = rCode.Search( 'J' ); // Dutch + nYear = rCode.indexOf('A'); // Spanish + if (nYear == -1) + nYear = rCode.indexOf('J'); // Dutch } - if ( nDay == STRING_NOTFOUND || nMonth == STRING_NOTFOUND || nYear == STRING_NOTFOUND ) + if (nDay == -1 || nMonth == -1 || nYear == -1) { if (areChecksEnabled()) { @@ -950,17 +945,17 @@ DateFormat LocaleDataWrapper::scanDateFormatImpl( const String& rCode ) "LocaleDataWrapper::scanDateFormat: not all DMY present")); outputCheckMessage( appendLocaleInfo( aMsg ) ); } - if ( nDay == STRING_NOTFOUND ) - nDay = rCode.Len(); - if ( nMonth == STRING_NOTFOUND ) - nMonth = rCode.Len(); - if ( nYear == STRING_NOTFOUND ) - nYear = rCode.Len(); + if (nDay == -1) + nDay = rCode.getLength(); + if (nMonth == -1) + nMonth = rCode.getLength(); + if (nYear == -1) + nYear = rCode.getLength(); } } - // compare with <= because each position may equal rCode.Len() + // compare with <= because each position may equal rCode.getLength() if ( nDay <= nMonth && nMonth <= nYear ) - return DMY; // also if every position equals rCode.Len() + return DMY; // also if every position equals rCode.getLength() else if ( nMonth <= nDay && nDay <= nYear ) return MDY; else if ( nYear <= nMonth && nMonth <= nDay ) @@ -1210,16 +1205,16 @@ static sal_Unicode* ImplAdd2UNum( sal_Unicode* pBuf, sal_uInt16 nNumber, int bLe } -inline sal_Unicode* ImplAddString( sal_Unicode* pBuf, const String& rStr ) +inline sal_Unicode* ImplAddString( sal_Unicode* pBuf, const rtl::OUString& rStr ) { - if ( rStr.Len() == 1 ) - *pBuf++ = rStr.GetChar(0); - else if ( rStr.Len() == 0 ) + if ( rStr.getLength() == 1 ) + *pBuf++ = rStr[0]; + else if (rStr.isEmpty()) ; else { - memcpy( pBuf, rStr.GetBuffer(), rStr.Len() * sizeof(sal_Unicode) ); - pBuf += rStr.Len(); + memcpy( pBuf, rStr.getStr(), rStr.getLength() * sizeof(sal_Unicode) ); + pBuf += rStr.getLength(); } return pBuf; } @@ -1302,7 +1297,7 @@ sal_Unicode* LocaleDataWrapper::ImplAddFormatNum( sal_Unicode* pBuf, } else { - const String& rThoSep = getNumThousandSep(); + const rtl::OUString& rThoSep = getNumThousandSep(); // copy number to buffer (excluding decimals) sal_uInt16 nNumLen2 = nNumLen-nDecimals; @@ -1350,7 +1345,7 @@ sal_Unicode* LocaleDataWrapper::ImplAddFormatNum( sal_Unicode* pBuf, // --- simple date and time formatting -------------------------------- -String LocaleDataWrapper::getDate( const Date& rDate ) const +rtl::OUString LocaleDataWrapper::getDate( const Date& rDate ) const { ::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nBlockCritical ); //!TODO: leading zeros et al @@ -1393,11 +1388,11 @@ String LocaleDataWrapper::getDate( const Date& rDate ) const pBuf = ImplAdd2UNum( pBuf, nDay, sal_True /* IsDateDayLeadingZero() */ ); } - return String( aBuf, (xub_StrLen)(sal_uLong)(pBuf-aBuf) ); + return rtl::OUString(aBuf, pBuf-aBuf); } -String LocaleDataWrapper::getTime( const Time& rTime, sal_Bool bSec, sal_Bool b100Sec ) const +rtl::OUString LocaleDataWrapper::getTime( const Time& rTime, sal_Bool bSec, sal_Bool b100Sec ) const { ::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nBlockCritical ); //!TODO: leading zeros et al @@ -1431,7 +1426,7 @@ String LocaleDataWrapper::getTime( const Time& rTime, sal_Bool bSec, sal_Bool b1 } } - String aStr( aBuf, (xub_StrLen)(sal_uLong)(pBuf-aBuf) ); + rtl::OUString aStr(aBuf, pBuf - aBuf); if ( bHour12 ) { @@ -1445,7 +1440,7 @@ String LocaleDataWrapper::getTime( const Time& rTime, sal_Bool bSec, sal_Bool b1 } -String LocaleDataWrapper::getLongDate( const Date& rDate, CalendarWrapper& rCal, +rtl::OUString LocaleDataWrapper::getLongDate( const Date& rDate, CalendarWrapper& rCal, sal_Int16 nDisplayDayOfWeek, sal_Bool bDayOfMonthWithLeadingZero, sal_Int16 nDisplayMonth, sal_Bool bTwoDigitYear ) const { @@ -1502,7 +1497,7 @@ String LocaleDataWrapper::getLongDate( const Date& rDate, CalendarWrapper& rCal, } -String LocaleDataWrapper::getDuration( const Time& rTime, sal_Bool bSec, sal_Bool b100Sec ) const +rtl::OUString LocaleDataWrapper::getDuration( const Time& rTime, sal_Bool bSec, sal_Bool b100Sec ) const { ::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nBlockCritical ); sal_Unicode aBuf[128]; @@ -1541,13 +1536,13 @@ inline size_t ImplGetNumberStringLengthGuess( const LocaleDataWrapper& rLoc, sal const size_t nDig = ((sizeof(sal_Int64) * 8) / 3) + 1; // digits, separators (pessimized for insane "every digit may be grouped"), leading zero, sign size_t nGuess = ((nDecimals < nDig) ? - (((nDig - nDecimals) * rLoc.getNumThousandSep().Len()) + nDig) : - nDecimals) + rLoc.getNumDecimalSep().Len() + 3; + (((nDig - nDecimals) * rLoc.getNumThousandSep().getLength()) + nDig) : + nDecimals) + rLoc.getNumDecimalSep().getLength() + 3; return nGuess; } -String LocaleDataWrapper::getNum( sal_Int64 nNumber, sal_uInt16 nDecimals, +rtl::OUString LocaleDataWrapper::getNum( sal_Int64 nNumber, sal_uInt16 nDecimals, sal_Bool bUseThousandSep, sal_Bool bTrailingZeros ) const { ::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nBlockCritical ); @@ -1567,8 +1562,8 @@ String LocaleDataWrapper::getNum( sal_Int64 nNumber, sal_uInt16 nDecimals, } -String LocaleDataWrapper::getCurr( sal_Int64 nNumber, sal_uInt16 nDecimals, - const String& rCurrencySymbol, sal_Bool bUseThousandSep ) const +rtl::OUString LocaleDataWrapper::getCurr( sal_Int64 nNumber, sal_uInt16 nDecimals, + const rtl::OUString& rCurrencySymbol, sal_Bool bUseThousandSep ) const { ::utl::ReadWriteGuard aGuard( aMutex, ::utl::ReadWriteGuardMode::nBlockCritical ); sal_Unicode aBuf[192]; @@ -1581,8 +1576,8 @@ String LocaleDataWrapper::getCurr( sal_Int64 nNumber, sal_uInt16 nDecimals, new sal_Unicode[nGuess + 16]); sal_Unicode* const pBuffer = - ((size_t(rCurrencySymbol.Len()) + nGuess + 20) < SAL_N_ELEMENTS(aBuf) ? aBuf : - new sal_Unicode[ rCurrencySymbol.Len() + nGuess + 20 ]); + ((size_t(rCurrencySymbol.getLength()) + nGuess + 20) < SAL_N_ELEMENTS(aBuf) ? aBuf : + new sal_Unicode[ rCurrencySymbol.getLength() + nGuess + 20 ]); sal_Unicode* pBuf = pBuffer; sal_Bool bNeg; @@ -1797,7 +1792,7 @@ rtl::OUString LocaleDataWrapper::appendLocaleInfo(const rtl::OUString& rDebugMsg // static -void LocaleDataWrapper::outputCheckMessage( const String& rMsg ) +void LocaleDataWrapper::outputCheckMessage( const rtl::OUString& rMsg ) { outputCheckMessage(rtl::OUStringToOString(rMsg, RTL_TEXTENCODING_UTF8).getStr()); } |