diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-08-28 00:17:42 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-08-29 09:56:06 +0100 |
commit | 14d2a60053e30dcb7e6956637fe8d57d18563e3f (patch) | |
tree | a395e8185afde2031fa255094ee9b0d23f11afe9 | |
parent | 65302eb1bed16db8f06cbb048d03ba6d644b3fb6 (diff) |
remove ByteString::IsAlphaNumericAscii and refactor a bit
-rw-r--r-- | basic/source/app/app.cxx | 2 | ||||
-rw-r--r-- | comphelper/inc/comphelper/string.hxx | 52 | ||||
-rw-r--r-- | comphelper/qa/string/test_string.cxx | 31 | ||||
-rw-r--r-- | comphelper/source/misc/string.cxx | 32 | ||||
-rw-r--r-- | l10ntools/source/gsicheck.cxx | 6 | ||||
-rw-r--r-- | rsc/source/rsc/rsc.cxx | 2 | ||||
-rw-r--r-- | sfx2/source/appl/appdde.cxx | 15 | ||||
-rw-r--r-- | svtools/bmpmaker/bmpcore.cxx | 2 | ||||
-rw-r--r-- | svtools/source/filter/sgvtext.cxx | 4 | ||||
-rw-r--r-- | tools/inc/tools/string.hxx | 1 | ||||
-rw-r--r-- | tools/source/fsys/dirent.cxx | 6 | ||||
-rw-r--r-- | tools/source/inet/inetmsg.cxx | 2 | ||||
-rw-r--r-- | tools/source/string/tstring.cxx | 23 |
13 files changed, 125 insertions, 53 deletions
diff --git a/basic/source/app/app.cxx b/basic/source/app/app.cxx index 392d2465f662..de61a3ee7185 100644 --- a/basic/source/app/app.cxx +++ b/basic/source/app/app.cxx @@ -375,7 +375,7 @@ IMPL_LINK( BasicApp, LateInit, void *, pDummy ) { if ( (i+1) < Application::GetCommandLineParamCount() ) { - if ( comphelper::string::isAsciiDecimalString(Application::GetCommandLineParam(i+1)) ) + if ( comphelper::string::isdigitAsciiString(Application::GetCommandLineParam(i+1)) ) { MsgEdit::SetMaxLogLen( sal::static_int_cast< sal_uInt16 >( Application::GetCommandLineParam( i+1 ).ToInt32() ) ); } diff --git a/comphelper/inc/comphelper/string.hxx b/comphelper/inc/comphelper/string.hxx index 3e74ca452aaa..4daa01b00b6f 100644 --- a/comphelper/inc/comphelper/string.hxx +++ b/comphelper/inc/comphelper/string.hxx @@ -268,25 +268,65 @@ public: const ::com::sun::star::lang::Locale& getLocale() const { return m_aLocale; } }; -/** Determine if an OString contains solely ascii numeric digits +/** 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 + the ASCII '0'-'9' range true otherwise, including for empty string */ -COMPHELPER_DLLPUBLIC bool isAsciiDecimalString(const rtl::OString &rString); +COMPHELPER_DLLPUBLIC bool isdigitAsciiString(const rtl::OString &rString); -/** Determine if an OUString contains solely ascii numeric digits +/** 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 + the ASCII '0'-'9' range true otherwise, including for empty string */ -COMPHELPER_DLLPUBLIC bool isAsciiDecimalString(const rtl::OUString &rString); +COMPHELPER_DLLPUBLIC bool isdigitAsciiString(const rtl::OUString &rString); + +/** Determine if an OString contains solely ASCII alphanumeric digits + + @param rString An OString + + @return false if string contains any characters outside + the ASCII 'a'-'z', 'A'-'Z' and '0'-'9' ranges + true otherwise, including for empty string + */ +COMPHELPER_DLLPUBLIC bool isalnumAsciiString(const rtl::OString &rString); + +/** Determine if an OUString contains solely ASCII alphanumeric digits + + @param rString An OUString + + @return false if string contains any characters outside + the ASCII 'a'-'z', 'A'-'Z' and '0'-'9' ranges + true otherwise, including for empty string + */ +COMPHELPER_DLLPUBLIC bool isalnumAsciiString(const rtl::OString &rString); + +COMPHELPER_DLLPUBLIC inline bool isdigitAscii(sal_Unicode c) +{ + return ((c >= '0') && (c <= '9')); +} + +COMPHELPER_DLLPUBLIC inline bool islowerAscii(sal_Unicode c) +{ + return ((c >= 'a') && (c <= 'z')); +} + +COMPHELPER_DLLPUBLIC inline bool isupperAscii(sal_Unicode c) +{ + return ((c >= 'A') && (c <= 'Z')); +} + +COMPHELPER_DLLPUBLIC inline bool isalnumAscii(sal_Unicode c) +{ + return isdigitAscii(c) || islowerAscii(c) || isupperAscii(c); +} } } diff --git a/comphelper/qa/string/test_string.cxx b/comphelper/qa/string/test_string.cxx index 4ac96dccc5f7..d7187e04fd75 100644 --- a/comphelper/qa/string/test_string.cxx +++ b/comphelper/qa/string/test_string.cxx @@ -46,6 +46,8 @@ public: void testReplace(); void testToken(); void testDecimalStringToNumber(); + void testIsdigitAsciiString(); + void testIsalnumAsciiString(); CPPUNIT_TEST_SUITE(TestString); CPPUNIT_TEST(testSearchAndReplaceAsciiL); @@ -53,6 +55,8 @@ public: CPPUNIT_TEST(testReplace); CPPUNIT_TEST(testToken); CPPUNIT_TEST(testDecimalStringToNumber); + CPPUNIT_TEST(testIsdigitAsciiString); + CPPUNIT_TEST(testIsalnumAsciiString); CPPUNIT_TEST_SUITE_END(); }; @@ -98,6 +102,33 @@ void TestString::testDecimalStringToNumber() CPPUNIT_ASSERT_EQUAL((sal_uInt32)81, comphelper::string::decimalStringToNumber(s1)); } +void TestString::testIsdigitAsciiString() +{ + rtl::OString s1(RTL_CONSTASCII_STRINGPARAM("1234")); + CPPUNIT_ASSERT_EQUAL(comphelper::string::isdigitAsciiString(s1), true); + + rtl::OString s2(RTL_CONSTASCII_STRINGPARAM("1A34")); + CPPUNIT_ASSERT_EQUAL(comphelper::string::isdigitAsciiString(s2), false); + + rtl::OString s3; + CPPUNIT_ASSERT_EQUAL(comphelper::string::isdigitAsciiString(s3), true); +} + +void TestString::testIsalnumAsciiString() +{ + rtl::OString s1(RTL_CONSTASCII_STRINGPARAM("1234")); + CPPUNIT_ASSERT_EQUAL(comphelper::string::isalnumAsciiString(s1), true); + + rtl::OString s2(RTL_CONSTASCII_STRINGPARAM("1A34")); + CPPUNIT_ASSERT_EQUAL(comphelper::string::isalnumAsciiString(s2), true); + + rtl::OString s3; + CPPUNIT_ASSERT_EQUAL(comphelper::string::isalnumAsciiString(s3), true); + + rtl::OString s4(RTL_CONSTASCII_STRINGPARAM("1A[4")); + CPPUNIT_ASSERT_EQUAL(comphelper::string::isalnumAsciiString(s4), false); +} + using namespace ::com::sun::star; class testCollator : public cppu::WeakImplHelper1< i18n::XCollator > diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx index b31d11549815..0138cc672ed8 100644 --- a/comphelper/source/misc/string.cxx +++ b/comphelper/source/misc/string.cxx @@ -354,25 +354,45 @@ NaturalStringSorter::NaturalStringSorter( namespace { - template <typename T> bool tmpl_isAsciiDecimalString(const T &rString) + template <typename T> bool tmpl_isalnumAsciiString(const T &rString) { for (sal_Int32 i = 0; i < rString.getLength(); ++i) { - if ((rString[i] < '0') || (rString[i] > '9')) + if (!isalnumAscii(rString[i])) return false; } return true; } + + template <typename T> bool tmpl_isdigitAsciiString(const T &rString) + { + for (sal_Int32 i = 0; i < rString.getLength(); ++i) + { + if (!isdigitAscii(rString[i])) + return false; + } + return true; + } +} + +bool isalnumAsciiString(const rtl::OString &rString) +{ + return tmpl_isalnumAsciiString(rString); +} + +bool isalnumAsciiString(const rtl::OUString &rString) +{ + return tmpl_isalnumAsciiString(rString); } -bool isAsciiDecimalString(const rtl::OString &rString) +bool isdigitAsciiString(const rtl::OString &rString) { - return tmpl_isAsciiDecimalString(rString); + return tmpl_isdigitAsciiString(rString); } -bool isAsciiDecimalString(const rtl::OUString &rString) +bool isdigitAsciiString(const rtl::OUString &rString) { - return tmpl_isAsciiDecimalString(rString); + return tmpl_isdigitAsciiString(rString); } } } diff --git a/l10ntools/source/gsicheck.cxx b/l10ntools/source/gsicheck.cxx index da305db9ca04..5fc52baba086 100644 --- a/l10ntools/source/gsicheck.cxx +++ b/l10ntools/source/gsicheck.cxx @@ -67,7 +67,7 @@ sal_Bool LanguageOK( ByteString aLang ) if ( !aLang.Len() ) return sal_False; - if (comphelper::string::isAsciiDecimalString(aLang)) + if (comphelper::string::isdigitAsciiString(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 (!comphelper::string::isAsciiDecimalString(rLine.GetToken(8, '\t'))) + if (!comphelper::string::isdigitAsciiString(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 (comphelper::string::isAsciiDecimalString(aID) && aID.Len() >= 5) + if (comphelper::string::isdigitAsciiString(aID) && aID.Len() >= 5) bIsKeyID = sal_True; } diff --git a/rsc/source/rsc/rsc.cxx b/rsc/source/rsc/rsc.cxx index 168d93dc904b..e8c6045fcfff 100644 --- a/rsc/source/rsc/rsc.cxx +++ b/rsc/source/rsc/rsc.cxx @@ -1199,7 +1199,7 @@ void RscCompiler::PreprocessSrsFile( const RscCmdLine::OutputFile& rOutputFile, aLine.EraseLeadingChars( '\t' ); aLine.EraseAllChars( ';' ); - if (comphelper::string::isAsciiDecimalString(aLine)) + if (comphelper::string::isdigitAsciiString(aLine)) { ByteString aBaseFileName( aPrefix ); sal_Int32 nNumber = atoi( aLine.GetBuffer() ); diff --git a/sfx2/source/appl/appdde.cxx b/sfx2/source/appl/appdde.cxx index cb3f03a00321..1c93a6336e97 100644 --- a/sfx2/source/appl/appdde.cxx +++ b/sfx2/source/appl/appdde.cxx @@ -52,19 +52,22 @@ #include <sfx2/sfxsids.hrc> #include "helper.hxx" #include <sfx2/docfile.hxx> +#include <comphelper/string.hxx> //======================================================================== String SfxDdeServiceName_Impl( const String& sIn ) { - ByteString sTemp = U2S( sIn ); - ByteString sReturn; + String sReturn; - for ( sal_uInt16 n = sTemp.Len(); n; --n ) - if ( sTemp.Copy( n-1, 1 ).IsAlphaNumericAscii() ) - sReturn += sTemp.GetChar(n-1); + for ( sal_uInt16 n = sIn.Len(); n; --n ) + { + sal_Unicode cChar = sIn.GetChar(n-1); + if (comphelper::string::isalnumAscii(cChar)) + sReturn += cChar; + } - return S2U( sReturn ); + return sReturn; } diff --git a/svtools/bmpmaker/bmpcore.cxx b/svtools/bmpmaker/bmpcore.cxx index c4f8db80f356..c6b13db704f0 100644 --- a/svtools/bmpmaker/bmpcore.cxx +++ b/svtools/bmpmaker/bmpcore.cxx @@ -134,7 +134,7 @@ void BmpCreator::ImplCreate( const ::std::vector< DirEntry >& rInDirs, aLine.EraseLeadingChars( '\t' ); aLine.EraseAllChars( ';' ); - if (comphelper::string::isAsciiDecimalString(aLine)) + if (comphelper::string::isdigitAsciiString(aLine)) { aString = aPrefix; diff --git a/svtools/source/filter/sgvtext.cxx b/svtools/source/filter/sgvtext.cxx index f303ebfa4ac0..820cdd9ac168 100644 --- a/svtools/source/filter/sgvtext.cxx +++ b/svtools/source/filter/sgvtext.cxx @@ -1209,7 +1209,7 @@ void SgfFontOne::ReadOne( const rtl::OString& rID, ByteString& Dsc ) else if (matchL(s, RTL_CONSTASCII_USTRINGPARAM("MAC"))) SVChSet=RTL_TEXTENCODING_APPLE_ROMAN; else if (matchL(s, RTL_CONSTASCII_USTRINGPARAM("SYMBOL"))) SVChSet=RTL_TEXTENCODING_SYMBOL; else if (matchL(s, RTL_CONSTASCII_USTRINGPARAM("SYSTEM"))) SVChSet = osl_getThreadTextEncoding(); - else if (comphelper::string::isAsciiDecimalString(s) ) SVWidth=sal::static_int_cast< sal_uInt16 >(s.toInt32()); + else if (comphelper::string::isdigitAsciiString(s) ) SVWidth=sal::static_int_cast< sal_uInt16 >(s.toInt32()); } } } @@ -1268,7 +1268,7 @@ void SgfFontLst::ReadList() FID = aCfg.GetKeyName( i ); FID = FID.EraseAllChars(); // Leerzeichen weg Dsc = aCfg.ReadKey( i ); - if (comphelper::string::isAsciiDecimalString(FID)) + if (comphelper::string::isdigitAsciiString(FID)) { P=new SgfFontOne; // neuer Eintrag if (Last!=NULL) Last->Next=P; else pList=P; Last=P; // einklinken diff --git a/tools/inc/tools/string.hxx b/tools/inc/tools/string.hxx index fc03584c6de1..b9e66763e799 100644 --- a/tools/inc/tools/string.hxx +++ b/tools/inc/tools/string.hxx @@ -256,7 +256,6 @@ public: sal_Bool IsLowerAscii() const; sal_Bool IsUpperAscii() const; sal_Bool IsAlphaAscii() const; - sal_Bool IsAlphaNumericAscii() const; ByteString& ToLowerAscii(); ByteString& ToUpperAscii(); diff --git a/tools/source/fsys/dirent.cxx b/tools/source/fsys/dirent.cxx index 64d2319828c1..14548558e107 100644 --- a/tools/source/fsys/dirent.cxx +++ b/tools/source/fsys/dirent.cxx @@ -65,7 +65,7 @@ #include <osl/file.hxx> #include <rtl/instance.hxx> - +#include <comphelper/string.hxx> using namespace osl; @@ -333,12 +333,14 @@ ByteString ImplCutPath( const ByteString& rStr, sal_uInt16 nMax, char cAccDel ) if ( aCutPath.Len() > nMaxPathLen ) { for ( sal_uInt16 n = nMaxPathLen; n > nMaxPathLen/2; --n ) - if ( !ByteString(aCutPath.GetChar(n)).IsAlphaNumericAscii() ) + { + if (!comphelper::string::isalnumAscii(aCutPath.GetChar(n))) { aCutPath.Erase( n ); aCutPath += "..."; break; } + } } if ( bInsertPrefix ) diff --git a/tools/source/inet/inetmsg.cxx b/tools/source/inet/inetmsg.cxx index 24e564240529..11bd5dbcefd9 100644 --- a/tools/source/inet/inetmsg.cxx +++ b/tools/source/inet/inetmsg.cxx @@ -414,7 +414,7 @@ sal_Bool INetRFC822Message::ParseDateField ( } } } - else if (comphelper::string::isAsciiDecimalString(aDateField)) + else if (comphelper::string::isdigitAsciiString(aDateField)) { // Format: delta seconds. Time aDelta (0); diff --git a/tools/source/string/tstring.cxx b/tools/source/string/tstring.cxx index 833e0d4fa9c7..5b3d41de6265 100644 --- a/tools/source/string/tstring.cxx +++ b/tools/source/string/tstring.cxx @@ -152,29 +152,6 @@ sal_Bool ByteString::IsAlphaAscii() const return sal_True; } -// ----------------------------------------------------------------------- - -sal_Bool ByteString::IsAlphaNumericAscii() 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 >= 97) && (*pStr <= 122)) || - ((*pStr >= 65) && (*pStr <= 90)) || - ((*pStr >= 48) && (*pStr <= 57))) ) - return sal_False; - - ++pStr, - ++nIndex; - } - - return sal_True; -} - void STRING::SearchAndReplaceAll( const STRCODE* pCharStr, const STRING& rRepStr ) { DBG_CHKTHIS( STRING, DBGCHECKSTRING ); |