diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-08-14 01:37:52 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-08-15 09:21:48 +0100 |
commit | 9124003eb1e398957a85c5c009ac5eddf5e6f28e (patch) | |
tree | d1348216600b18f3daa08224a4d4492b53337813 | |
parent | a6825d680c7f49dd462a858cc8691757a6dd4cba (diff) |
ByteString::IsNumericAscii->comphelper::string::isAsciiDecimalString
shrink ByteString api, remove need for intermediate OString/ByteString
with random-ish encoding solely for check
-rw-r--r-- | basctl/source/basicide/baside2b.cxx | 3 | ||||
-rw-r--r-- | basic/source/app/app.cxx | 5 | ||||
-rw-r--r-- | comphelper/inc/comphelper/string.hxx | 21 | ||||
-rw-r--r-- | comphelper/source/misc/string.cxx | 23 | ||||
-rw-r--r-- | cui/source/options/optinet2.cxx | 5 | ||||
-rw-r--r-- | l10ntools/source/gsicheck.cxx | 8 | ||||
-rw-r--r-- | l10ntools/source/makefile.mk | 1 | ||||
-rw-r--r-- | rsc/Executable_rsc.mk | 1 | ||||
-rw-r--r-- | rsc/source/rsc/rsc.cxx | 3 | ||||
-rw-r--r-- | sc/source/ui/app/inputwin.cxx | 3 | ||||
-rw-r--r-- | sc/source/ui/unoobj/docuno.cxx | 3 | ||||
-rw-r--r-- | sc/source/ui/view/tabvwsh3.cxx | 4 | ||||
-rw-r--r-- | sd/source/filter/ppt/pptin.cxx | 5 | ||||
-rw-r--r-- | sd/source/ui/dlg/tpoption.cxx | 24 | ||||
-rw-r--r-- | svtools/Executable_bmp.mk | 1 | ||||
-rw-r--r-- | svtools/bmpmaker/bmpcore.cxx | 3 | ||||
-rw-r--r-- | svtools/source/filter/sgvtext.cxx | 5 | ||||
-rw-r--r-- | sw/source/core/doc/docnum.cxx | 5 | ||||
-rw-r--r-- | tools/inc/tools/string.hxx | 1 | ||||
-rw-r--r-- | tools/source/inet/inetmsg.cxx | 70 | ||||
-rw-r--r-- | tools/source/string/tstring.cxx | 21 |
21 files changed, 125 insertions, 90 deletions
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx index 28df6b14ccea..e6cf7b1b0c0e 100644 --- a/basctl/source/basicide/baside2b.cxx +++ b/basctl/source/basicide/baside2b.cxx @@ -60,6 +60,7 @@ #include <com/sun/star/script/XLibraryContainer2.hpp> #include <comphelper/processfactory.hxx> +#include <comphelper/string.hxx> using namespace ::com::sun::star; @@ -268,7 +269,7 @@ void EditorWindow::RequestHelp( const HelpEvent& rHEvt ) TextPaM aCursor = GetEditView()->GetTextEngine()->GetPaM( aDocPos, sal_False ); TextPaM aStartOfWord; String aWord = GetEditView()->GetTextEngine()->GetWord( aCursor, &aStartOfWord ); - if ( aWord.Len() && !ByteString( aWord, RTL_TEXTENCODING_UTF8 ).IsNumericAscii() ) + if ( aWord.Len() && !comphelper::string::isAsciiDecimalString(aWord) ) { sal_uInt16 nLastChar =aWord.Len()-1; if ( strchr( cSuffixes, aWord.GetChar( nLastChar ) ) ) diff --git a/basic/source/app/app.cxx b/basic/source/app/app.cxx index f605e9510813..6509ad8a54ff 100644 --- a/basic/source/app/app.cxx +++ b/basic/source/app/app.cxx @@ -61,6 +61,7 @@ #include <ucbhelper/configurationkeys.hxx> #include <comphelper/regpathhelper.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/string.hxx> #include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/lang/XComponent.hpp> #include <cppuhelper/bootstrap.hxx> @@ -374,11 +375,11 @@ IMPL_LINK( BasicApp, LateInit, void *, pDummy ) { if ( (i+1) < Application::GetCommandLineParamCount() ) { - if ( ByteString( Application::GetCommandLineParam( i+1 ), osl_getThreadTextEncoding() ).IsNumericAscii() ) + if ( comphelper::string::isAsciiDecimalString(Application::GetCommandLineParam(i+1)) ) { MsgEdit::SetMaxLogLen( sal::static_int_cast< sal_uInt16 >( Application::GetCommandLineParam( i+1 ).ToInt32() ) ); } - i++; + ++i; } } } diff --git a/comphelper/inc/comphelper/string.hxx b/comphelper/inc/comphelper/string.hxx index e71a008c5e3e..dd3261bef085 100644 --- a/comphelper/inc/comphelper/string.hxx +++ b/comphelper/inc/comphelper/string.hxx @@ -193,6 +193,27 @@ public: const ::com::sun::star::lang::Locale& getLocale() const { return m_aLocale; } }; +/** Determine if an OString contains solely ascii numeric digits + + @param rString An OString + + @return false if string contains any characters outside + the ascii '0'-'9' range + true otherwise, including for empty string + */ +COMPHELPER_DLLPUBLIC bool isAsciiDecimalString(const rtl::OString &rString); + +/** Determine if an OUString contains solely ascii numeric digits + + @param rString An OUString + + @return false if string contains any characters outside + the ascii '0'-'9' range + true otherwise, including for empty string + */ +COMPHELPER_DLLPUBLIC bool isAsciiDecimalString(const rtl::OUString &rString); + + } } #endif diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx index 18ad6ad4fe9f..249ef2e87800 100644 --- a/comphelper/source/misc/string.cxx +++ b/comphelper/source/misc/string.cxx @@ -308,6 +308,29 @@ NaturalStringSorter::NaturalStringSorter( uno::UNO_QUERY_THROW); } +namespace +{ + template <typename T> bool tmpl_isAsciiDecimalString(const T &rString) + { + for (sal_Int32 i = 0; i < rString.getLength(); ++i) + { + if ((rString[i] < '0') || (rString[i] > '9')) + return false; + } + return true; + } +} + +bool isAsciiDecimalString(const rtl::OString &rString) +{ + return tmpl_isAsciiDecimalString(rString); +} + +bool isAsciiDecimalString(const rtl::OUString &rString) +{ + return tmpl_isAsciiDecimalString(rString); +} + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cui/source/options/optinet2.cxx b/cui/source/options/optinet2.cxx index cb093d415442..4b80409e2f36 100644 --- a/cui/source/options/optinet2.cxx +++ b/cui/source/options/optinet2.cxx @@ -93,6 +93,7 @@ #include <com/sun/star/beans/XPropertyState.hpp> #include <com/sun/star/util/XChangesBatch.hpp> #include <comphelper/processfactory.hxx> +#include <comphelper/string.hxx> #include "com/sun/star/ui/dialogs/TemplateDescription.hpp" #include "com/sun/star/task/XMasterPasswordHandling2.hpp" @@ -164,7 +165,7 @@ void SvxNoSpaceEdit::Modify() { XubString aValue = GetText(); - if ( !ByteString(::rtl::OUStringToOString(aValue,RTL_TEXTENCODING_UTF8)).IsNumericAscii() || (long)aValue.ToInt32() > USHRT_MAX ) + if ( !comphelper::string::isAsciiDecimalString(aValue) || (long)aValue.ToInt32() > USHRT_MAX ) // der H�chstwert einer Portnummer ist USHRT_MAX ErrorBox( this, CUI_RES( RID_SVXERR_OPT_PROXYPORTS ) ).Execute(); } @@ -628,7 +629,7 @@ IMPL_LINK( SvxProxyTabPage, LoseFocusHdl_Impl, Edit *, pEdit ) { XubString aValue = pEdit->GetText(); - if ( !ByteString(::rtl::OUStringToOString(aValue,RTL_TEXTENCODING_UTF8)).IsNumericAscii() || (long)aValue.ToInt32() > USHRT_MAX ) + if ( !comphelper::string::isAsciiDecimalString(aValue) || (long)aValue.ToInt32() > USHRT_MAX ) pEdit->SetText( '0' ); return 0; } diff --git a/l10ntools/source/gsicheck.cxx b/l10ntools/source/gsicheck.cxx index 2fd8b8b540b1..da305db9ca04 100644 --- a/l10ntools/source/gsicheck.cxx +++ b/l10ntools/source/gsicheck.cxx @@ -33,7 +33,7 @@ #include <tools/stream.hxx> #include <rtl/strbuf.hxx> - +#include <comphelper/string.hxx> #include "tagtest.hxx" #include "gsicheck.hxx" @@ -67,7 +67,7 @@ sal_Bool LanguageOK( ByteString aLang ) if ( !aLang.Len() ) return sal_False; - if ( aLang.IsNumericAscii() ) + if (comphelper::string::isAsciiDecimalString(aLang)) return sal_True; if ( aLang.GetTokenCount( '-' ) == 1 ) @@ -153,7 +153,7 @@ GSILine::GSILine( const ByteString &rLine, sal_uLong nLine ) aTitle = rLine.GetToken( 13, '\t' ); // do some more format checks here - if ( !rLine.GetToken( 8, '\t' ).IsNumericAscii() ) + if (!comphelper::string::isAsciiDecimalString(rLine.GetToken(8, '\t'))) { PrintError( "The length field does not contain a number!", "Line format", rLine.GetToken( 8, '\t' ), sal_True, GetLineNumber(), GetUniqId() ); NotOK(); @@ -491,7 +491,7 @@ sal_Bool GSIBlock::IsUTF8( const ByteString &aTestee, sal_Bool bFixTags, sal_uIn if ( aID.Len() > 0 && aID.GetChar(aID.Len()-1) == '*' ) aID.Erase( aID.Len()-1 ); - if ( aID.IsNumericAscii() && aID.Len() >= 5 ) + if (comphelper::string::isAsciiDecimalString(aID) && aID.Len() >= 5) bIsKeyID = sal_True; } diff --git a/l10ntools/source/makefile.mk b/l10ntools/source/makefile.mk index 86bcea3cbd0e..5ab3c4fdf23c 100644 --- a/l10ntools/source/makefile.mk +++ b/l10ntools/source/makefile.mk @@ -98,6 +98,7 @@ APP3STDLIBS+= \ APP5TARGET= gsicheck APP5OBJS= $(OBJ)$/gsicheck.obj $(OBJ)$/tagtest.obj APP5STDLIBS+= \ + $(COMPHELPERLIB) \ $(TOOLSLIB) \ $(SALLIB) diff --git a/rsc/Executable_rsc.mk b/rsc/Executable_rsc.mk index d4b175c44bbe..ec8945fea2e9 100644 --- a/rsc/Executable_rsc.mk +++ b/rsc/Executable_rsc.mk @@ -48,6 +48,7 @@ $(eval $(call gb_Executable_add_defs,rsc,\ $(eval $(call gb_Executable_add_linked_libs,rsc,\ i18nisolang1 \ + comphelper \ sal \ tl \ $(gb_STDLIBS) \ diff --git a/rsc/source/rsc/rsc.cxx b/rsc/source/rsc/rsc.cxx index 6dbf71c3983c..26520bbc2abd 100644 --- a/rsc/source/rsc/rsc.cxx +++ b/rsc/source/rsc/rsc.cxx @@ -65,6 +65,7 @@ #include <rtl/strbuf.hxx> #include <rtl/tencinfo.h> #include <rtl/textenc.h> +#include <comphelper/string.hxx> #include <vector> #include <algorithm> @@ -1197,7 +1198,7 @@ void RscCompiler::PreprocessSrsFile( const RscCmdLine::OutputFile& rOutputFile, aLine.EraseLeadingChars( '\t' ); aLine.EraseAllChars( ';' ); - if( aLine.IsNumericAscii() ) + if (comphelper::string::isAsciiDecimalString(aLine)) { ByteString aBaseFileName( aPrefix ); sal_Int32 nNumber = atoi( aLine.GetBuffer() ); diff --git a/sc/source/ui/app/inputwin.cxx b/sc/source/ui/app/inputwin.cxx index d9efd94e0535..401d68c44c45 100644 --- a/sc/source/ui/app/inputwin.cxx +++ b/sc/source/ui/app/inputwin.cxx @@ -76,6 +76,7 @@ #include "AccessibleEditObject.hxx" #include "AccessibleText.hxx" #include <svtools/miscopt.hxx> +#include <comphelper/string.hxx> #define TEXT_STARTPOS 3 #define TEXT_MULTI_STARTPOS 5 @@ -1789,7 +1790,7 @@ ScNameInputType lcl_GetInputType( const String& rText ) eRet = SC_NAME_INPUT_NAMEDRANGE; else if ( aRangeUtil.MakeRangeFromName( rText, pDoc, nTab, aRange, RUTL_DBASE, eConv ) ) eRet = SC_NAME_INPUT_DATABASE; - else if ( ByteString( rText, RTL_TEXTENCODING_ASCII_US ).IsNumericAscii() && + else if ( comphelper::string::isAsciiDecimalString( rText ) && ( nNumeric = rText.ToInt32() ) > 0 && nNumeric <= MAXROW+1 ) eRet = SC_NAME_INPUT_ROW; else if ( pDoc->GetTable( rText, nNameTab ) ) diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index 8645e9f44ed3..11ef07a27674 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -67,6 +67,7 @@ #include <com/sun/star/reflection/XIdlClassProvider.hpp> #include <comphelper/processfactory.hxx> #include <comphelper/servicehelper.hxx> +#include <comphelper/string.hxx> #include "docuno.hxx" #include "cellsuno.hxx" @@ -701,7 +702,7 @@ bool lcl_ParseTarget( const String& rTarget, ScRange& rTargetRange, Rectangle& r { bRangeValid = true; // named range or database range } - else if ( ByteString( rTarget, RTL_TEXTENCODING_ASCII_US ).IsNumericAscii() && + else if ( comphelper::string::isAsciiDecimalString(rTarget) && ( nNumeric = rTarget.ToInt32() ) > 0 && nNumeric <= MAXROW+1 ) { // row number is always mapped to cell A(row) on the same sheet diff --git a/sc/source/ui/view/tabvwsh3.cxx b/sc/source/ui/view/tabvwsh3.cxx index 922e31cb7eca..43775adb70ef 100644 --- a/sc/source/ui/view/tabvwsh3.cxx +++ b/sc/source/ui/view/tabvwsh3.cxx @@ -78,6 +78,7 @@ #include <svx/zoomslideritem.hxx> #include <svx/svxdlg.hxx> #include <svx/dialogs.hrc> +#include <comphelper/string.hxx> #include "scabstdlg.hxx" #include <memory> @@ -327,8 +328,7 @@ void ScTabViewShell::Execute( SfxRequest& rReq ) } } - if ( !(nResult & SCA_VALID) && - ByteString(aAddress, RTL_TEXTENCODING_ASCII_US).IsNumericAscii() ) + if ( !(nResult & SCA_VALID) && comphelper::string::isAsciiDecimalString(aAddress) ) { sal_Int32 nNumeric = aAddress.ToInt32(); if ( nNumeric > 0 && nNumeric <= MAXROW+1 ) diff --git a/sd/source/filter/ppt/pptin.cxx b/sd/source/filter/ppt/pptin.cxx index bae84f0f735b..0e4dab8fab85 100644 --- a/sd/source/filter/ppt/pptin.cxx +++ b/sd/source/filter/ppt/pptin.cxx @@ -102,6 +102,7 @@ #include <comphelper/processfactory.hxx> #include <comphelper/componentcontext.hxx> +#include <comphelper/string.hxx> using namespace ::com::sun::star; @@ -445,7 +446,7 @@ sal_Bool ImplSdPPTImport::Import() // first pass, searching for a SlideId for( nToken = 0; nToken < nTokenCount; nToken++ ) { - if ( aStringAry[ nToken ].IsNumericAscii() ) + if (comphelper::string::isAsciiDecimalString(aStringAry[nToken])) { sal_Int32 nNumber = aStringAry[ nToken ].ToInt32(); if ( nNumber & ~0xff ) @@ -483,7 +484,7 @@ sal_Bool ImplSdPPTImport::Import() { // third pass, searching for a slide number for ( nToken = 0; nToken < nTokenCount; nToken++ ) { - if ( aStringAry[ nToken ].IsNumericAscii() ) + if (comphelper::string::isAsciiDecimalString(aStringAry[nToken])) { sal_Int32 nNumber = aStringAry[ nToken ].ToInt32(); if ( ( nNumber & ~0xff ) == 0 ) diff --git a/sd/source/ui/dlg/tpoption.cxx b/sd/source/ui/dlg/tpoption.cxx index 1ed3d3d9b8c7..f0f2fd2b1953 100644 --- a/sd/source/ui/dlg/tpoption.cxx +++ b/sd/source/ui/dlg/tpoption.cxx @@ -40,6 +40,7 @@ #include <com/sun/star/lang/XComponent.hpp> #include <com/sun/star/container/XEnumerationAccess.hpp> #include <comphelper/processfactory.hxx> +#include <comphelper/string.hxx> #include <com/sun/star/uno/Exception.hpp> #include <sfx2/module.hxx> #include <sfx2/app.hxx> @@ -758,28 +759,25 @@ sal_Bool SdTpOptionsMisc::SetScale( const String& aScale, sal_Int32& rX, sal_Int if( aScale.GetTokenCount( TOKEN ) != 2 ) return( sal_False ); - ByteString aTmp( aScale.GetToken( 0, TOKEN ), RTL_TEXTENCODING_ASCII_US ); - if( !aTmp.IsNumericAscii() ) - return( sal_False ); + rtl::OUString aTmp(aScale.GetToken( 0, TOKEN )); + if (!comphelper::string::isAsciiDecimalString(aTmp)) + return sal_False; - rX = (long) aTmp.ToInt32(); + rX = (long) aTmp.toInt32(); if( rX == 0 ) return( sal_False ); - aTmp = ByteString( aScale.GetToken( 1, TOKEN ), RTL_TEXTENCODING_ASCII_US ); - if( !aTmp.IsNumericAscii() ) - return( sal_False ); + aTmp = aScale.GetToken( 1, TOKEN ); + if (!comphelper::string::isAsciiDecimalString(aTmp)) + return sal_False; - rY = (long) aTmp.ToInt32(); + rY = (long) aTmp.toInt32(); if( rY == 0 ) - return( sal_False ); + return sal_False; - return( sal_True ); + return sal_True; } - - - void SdTpOptionsMisc::UpdateCompatibilityControls (void) { // Disable the compatibility controls by default. Enable them only when diff --git a/svtools/Executable_bmp.mk b/svtools/Executable_bmp.mk index c65ff4c2e2c9..b75fd603f29c 100644 --- a/svtools/Executable_bmp.mk +++ b/svtools/Executable_bmp.mk @@ -46,6 +46,7 @@ $(eval $(call gb_Executable_add_api,bmp,\ $(eval $(call gb_Executable_add_linked_libs,bmp,\ sal \ + comphelper \ tl \ vcl \ $(gb_STDLIBS) \ diff --git a/svtools/bmpmaker/bmpcore.cxx b/svtools/bmpmaker/bmpcore.cxx index 622cce494a71..c4f8db80f356 100644 --- a/svtools/bmpmaker/bmpcore.cxx +++ b/svtools/bmpmaker/bmpcore.cxx @@ -29,6 +29,7 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_svtools.hxx" +#include <comphelper/string.hxx> #include <tools/color.hxx> #include <vcl/bmpacc.hxx> #include <vcl/bitmapex.hxx> @@ -133,7 +134,7 @@ void BmpCreator::ImplCreate( const ::std::vector< DirEntry >& rInDirs, aLine.EraseLeadingChars( '\t' ); aLine.EraseAllChars( ';' ); - if( aLine.IsNumericAscii() ) + if (comphelper::string::isAsciiDecimalString(aLine)) { aString = aPrefix; diff --git a/svtools/source/filter/sgvtext.cxx b/svtools/source/filter/sgvtext.cxx index c3dfeff557e2..20879f0bde99 100644 --- a/svtools/source/filter/sgvtext.cxx +++ b/svtools/source/filter/sgvtext.cxx @@ -30,6 +30,7 @@ #include "precompiled_svtools.hxx" #include <rtl/math.h> +#include <comphelper/string.hxx> #include <tools/config.hxx> #include <svtools/filter.hxx> #include "sgffilt.hxx" @@ -1207,7 +1208,7 @@ void SgfFontOne::ReadOne( ByteString& ID, ByteString& Dsc ) else if ( s.CompareTo( "MAC", 3 ) == COMPARE_EQUAL ) SVChSet=RTL_TEXTENCODING_APPLE_ROMAN; else if ( s.CompareTo( "SYMBOL", 6 ) == COMPARE_EQUAL ) SVChSet=RTL_TEXTENCODING_SYMBOL; else if ( s.CompareTo( "SYSTEM", 6 ) == COMPARE_EQUAL ) SVChSet = gsl_getSystemTextEncoding(); - else if ( s.IsNumericAscii() ) SVWidth=sal::static_int_cast< sal_uInt16 >(s.ToInt32()); + else if ( comphelper::string::isAsciiDecimalString(s) ) SVWidth=sal::static_int_cast< sal_uInt16 >(s.ToInt32()); } } } @@ -1266,7 +1267,7 @@ void SgfFontLst::ReadList() FID = aCfg.GetKeyName( i ); FID = FID.EraseAllChars(); // Leerzeichen weg Dsc = aCfg.ReadKey( i ); - if ( FID.IsNumericAscii() ) + if (comphelper::string::isAsciiDecimalString(FID)) { P=new SgfFontOne; // neuer Eintrag if (Last!=NULL) Last->Next=P; else pList=P; Last=P; // einklinken diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx index fa3761491dad..51d0eceeeada 100644 --- a/sw/source/core/doc/docnum.cxx +++ b/sw/source/core/doc/docnum.cxx @@ -63,6 +63,7 @@ #include <list.hxx> #include <listfunc.hxx> #include <switerator.hxx> +#include <comphelper/string.hxx> #include <map> @@ -641,7 +642,7 @@ sal_uInt16 lcl_FindOutlineNum( const SwNodes& rNds, String& rName ) nPos = 0; sNum = sName.GetToken( 0, '.', nPos ); // #i4533# without this check all parts delimited by a dot are treated as outline numbers - if(!ByteString(sNum, gsl_getSystemTextEncoding()).IsNumericAscii()) + if(!comphelper::string::isAsciiDecimalString(sNum)) nPos = STRING_NOTFOUND; } rName = sName; // das ist der nachfolgende Text. @@ -727,7 +728,7 @@ sal_Bool SwDoc::GotoOutline( SwPosition& rPos, const String& rName ) const String sTempNum; while(sExpandedText.Len() && (sTempNum = sExpandedText.GetToken(0, '.', nPos)).Len() && STRING_NOTFOUND != nPos && - ByteString(sTempNum, gsl_getSystemTextEncoding()).IsNumericAscii()) + comphelper::string::isAsciiDecimalString(sTempNum)) { sExpandedText.Erase(0, nPos); nPos = 0; diff --git a/tools/inc/tools/string.hxx b/tools/inc/tools/string.hxx index 1141cd3e2f42..fd89e28fd71e 100644 --- a/tools/inc/tools/string.hxx +++ b/tools/inc/tools/string.hxx @@ -258,7 +258,6 @@ public: sal_Bool IsLowerAscii() const; sal_Bool IsUpperAscii() const; sal_Bool IsAlphaAscii() const; - sal_Bool IsNumericAscii() const; sal_Bool IsAlphaNumericAscii() const; ByteString& ToLowerAscii(); diff --git a/tools/source/inet/inetmsg.cxx b/tools/source/inet/inetmsg.cxx index 1645e9ba7aea..d6b67fe06b4b 100644 --- a/tools/source/inet/inetmsg.cxx +++ b/tools/source/inet/inetmsg.cxx @@ -35,7 +35,7 @@ #include <tools/inetstrm.hxx> #include <rtl/instance.hxx> #include <rtl/strbuf.hxx> - +#include <comphelper/string.hxx> #include <stdio.h> //======================================================================= @@ -310,10 +310,10 @@ static sal_uInt16 ParseNumber (const ByteString& rStr, sal_uInt16& nIndex) sal_uInt16 n = nIndex; while ((n < rStr.Len()) && ascii_isDigit(rStr.GetChar(n))) n++; - ByteString aNum (rStr.Copy (nIndex, (n - nIndex))); + rtl::OString aNum (rStr.Copy (nIndex, (n - nIndex))); nIndex = n; - return (sal_uInt16)(aNum.ToInt32()); + return (sal_uInt16)(aNum.toInt32()); } static sal_uInt16 ParseMonth (const ByteString& rStr, sal_uInt16& nIndex) @@ -333,69 +333,71 @@ static sal_uInt16 ParseMonth (const ByteString& rStr, sal_uInt16& nIndex) sal_Bool INetRFC822Message::ParseDateField ( const UniString& rDateFieldW, DateTime& rDateTime) { - ByteString rDateField (rDateFieldW, RTL_TEXTENCODING_ASCII_US); - if (rDateField.Len() == 0) return sal_False; + rtl::OString aDateField(rtl::OUStringToOString(rDateFieldW, + RTL_TEXTENCODING_ASCII_US)); + + if (aDateField.isEmpty()) return sal_False; - if (rDateField.Search (':') != STRING_NOTFOUND) + if (aDateField.indexOf(':') != -1) { // Some DateTime format. sal_uInt16 nIndex = 0; // Skip over <Wkd> or <Weekday>, leading and trailing space. - while ((nIndex < rDateField.Len()) && - (rDateField.GetChar(nIndex) == ' ')) + while ((nIndex < aDateField.getLength()) && + (aDateField[nIndex] == ' ')) nIndex++; while ( - (nIndex < rDateField.Len()) && - (ascii_isLetter (rDateField.GetChar(nIndex)) || - (rDateField.GetChar(nIndex) == ',') )) + (nIndex < aDateField.getLength()) && + (ascii_isLetter (aDateField[nIndex]) || + (aDateField[nIndex] == ',') )) nIndex++; - while ((nIndex < rDateField.Len()) && - (rDateField.GetChar(nIndex) == ' ')) + while ((nIndex < aDateField.getLength()) && + (aDateField[nIndex] == ' ')) nIndex++; - if (ascii_isLetter (rDateField.GetChar(nIndex))) + if (ascii_isLetter (aDateField[nIndex])) { // Format: ctime(). - if ((rDateField.Len() - nIndex) < 20) return sal_False; + if ((aDateField.getLength() - nIndex) < 20) return sal_False; - rDateTime.SetMonth (ParseMonth (rDateField, nIndex)); nIndex++; - rDateTime.SetDay (ParseNumber (rDateField, nIndex)); nIndex++; + rDateTime.SetMonth (ParseMonth (aDateField, nIndex)); nIndex++; + rDateTime.SetDay (ParseNumber (aDateField, nIndex)); nIndex++; - rDateTime.SetHour (ParseNumber (rDateField, nIndex)); nIndex++; - rDateTime.SetMin (ParseNumber (rDateField, nIndex)); nIndex++; - rDateTime.SetSec (ParseNumber (rDateField, nIndex)); nIndex++; + rDateTime.SetHour (ParseNumber (aDateField, nIndex)); nIndex++; + rDateTime.SetMin (ParseNumber (aDateField, nIndex)); nIndex++; + rDateTime.SetSec (ParseNumber (aDateField, nIndex)); nIndex++; rDateTime.Set100Sec (0); - sal_uInt16 nYear = ParseNumber (rDateField, nIndex); + sal_uInt16 nYear = ParseNumber (aDateField, nIndex); if (nYear < 100) nYear += 1900; rDateTime.SetYear (nYear); } else { // Format: RFC1036 or RFC1123. - if ((rDateField.Len() - nIndex) < 17) return sal_False; + if ((aDateField.getLength() - nIndex) < 17) return sal_False; - rDateTime.SetDay (ParseNumber (rDateField, nIndex)); nIndex++; - rDateTime.SetMonth (ParseMonth (rDateField, nIndex)); nIndex++; + rDateTime.SetDay (ParseNumber (aDateField, nIndex)); nIndex++; + rDateTime.SetMonth (ParseMonth (aDateField, nIndex)); nIndex++; - sal_uInt16 nYear = ParseNumber (rDateField, nIndex); nIndex++; + sal_uInt16 nYear = ParseNumber (aDateField, nIndex); nIndex++; if (nYear < 100) nYear += 1900; rDateTime.SetYear (nYear); - rDateTime.SetHour (ParseNumber (rDateField, nIndex)); nIndex++; - rDateTime.SetMin (ParseNumber (rDateField, nIndex)); nIndex++; - rDateTime.SetSec (ParseNumber (rDateField, nIndex)); nIndex++; + rDateTime.SetHour (ParseNumber (aDateField, nIndex)); nIndex++; + rDateTime.SetMin (ParseNumber (aDateField, nIndex)); nIndex++; + rDateTime.SetSec (ParseNumber (aDateField, nIndex)); nIndex++; rDateTime.Set100Sec (0); - if ((rDateField.GetChar(nIndex) == '+') || - (rDateField.GetChar(nIndex) == '-') ) + if ((aDateField[nIndex] == '+') || + (aDateField[nIndex] == '-') ) { // Offset from GMT: "(+|-)HHMM". - sal_Bool bEast = (rDateField.GetChar(nIndex++) == '+'); - sal_uInt16 nOffset = ParseNumber (rDateField, nIndex); + sal_Bool bEast = (aDateField[nIndex++] == '+'); + sal_uInt16 nOffset = ParseNumber (aDateField, nIndex); if (nOffset > 0) { Time aDiff; @@ -412,11 +414,11 @@ sal_Bool INetRFC822Message::ParseDateField ( } } } - else if (rDateField.IsNumericAscii()) + else if (comphelper::string::isAsciiDecimalString(aDateField)) { // Format: delta seconds. Time aDelta (0); - aDelta.SetTime (rDateField.ToInt32() * 100); + aDelta.SetTime (aDateField.toInt32() * 100); DateTime aNow; aNow += aDelta; diff --git a/tools/source/string/tstring.cxx b/tools/source/string/tstring.cxx index 40310cf9591d..e0872ee66049 100644 --- a/tools/source/string/tstring.cxx +++ b/tools/source/string/tstring.cxx @@ -163,27 +163,6 @@ sal_Bool ByteString::IsAlphaAscii() const // ----------------------------------------------------------------------- -sal_Bool ByteString::IsNumericAscii() const -{ - DBG_CHKTHIS( ByteString, DbgCheckByteString ); - - sal_Int32 nIndex = 0; - sal_Int32 nLen = mpData->mnLen; - const sal_Char* pStr = mpData->maStr; - while ( nIndex < nLen ) - { - if ( !((*pStr >= 48) && (*pStr <= 57)) ) - return sal_False; - - ++pStr, - ++nIndex; - } - - return sal_True; -} - -// ----------------------------------------------------------------------- - sal_Bool ByteString::IsAlphaNumericAscii() const { DBG_CHKTHIS( ByteString, DbgCheckByteString ); |