summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--comphelper/inc/comphelper/string.hxx27
-rw-r--r--comphelper/qa/string/test_string.cxx19
-rw-r--r--tools/source/fsys/dirent.cxx50
3 files changed, 71 insertions, 25 deletions
diff --git a/comphelper/inc/comphelper/string.hxx b/comphelper/inc/comphelper/string.hxx
index 31414e5519ff..00a1664016cf 100644
--- a/comphelper/inc/comphelper/string.hxx
+++ b/comphelper/inc/comphelper/string.hxx
@@ -272,6 +272,33 @@ COMPHELPER_DLLPUBLIC inline sal_Bool matchL(const rtl::OString& rStr, const char
}
/**
+ Match against a substring appearing in this string, ignoring the case of
+ ASCII letters.
+
+ The result is true if and only if the second string appears as a substring
+ of this string, at the given position.
+ Character values between 65 and 90 (ASCII A-Z) are interpreted as
+ values between 97 and 122 (ASCII a-z).
+ This function can't be used for language specific comparison.
+
+ @param rStr The string that pMatch will be compared to.
+ @param pMatch The substring rStr is to be compared against
+ @param nMatchLen The length of pMatch
+ @param fromIndex the index to start the comparion from.
+ The index must be greater or equal than 0
+ and less or equal as the string length.
+ @return sal_True if str match with the characters in the string
+ at the given position;
+ sal_False, otherwise.
+*/
+COMPHELPER_DLLPUBLIC inline sal_Bool matchIgnoreAsciiCaseL(const rtl::OString& rStr, const char *pMatch, sal_Int32 nMatchLen, sal_Int32 fromIndex = 0) SAL_THROW(())
+{
+ return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( rStr.pData->buffer+fromIndex, rStr.pData->length-fromIndex,
+ pMatch, nMatchLen,
+ nMatchLen ) == 0;
+}
+
+/**
Returns the index within this string of the first occurrence of the
specified substring, starting at the specified index.
diff --git a/comphelper/qa/string/test_string.cxx b/comphelper/qa/string/test_string.cxx
index 110638164506..2ce6f2cff1bb 100644
--- a/comphelper/qa/string/test_string.cxx
+++ b/comphelper/qa/string/test_string.cxx
@@ -55,6 +55,7 @@ public:
void testIsalnumAsciiString();
void testIsupperAsciiString();
void testIndexOfL();
+ void testMatchIgnoreAsciiCaseL();
CPPUNIT_TEST_SUITE(TestString);
CPPUNIT_TEST(testSearchAndReplaceAsciiL);
@@ -67,6 +68,7 @@ public:
CPPUNIT_TEST(testIsalnumAsciiString);
CPPUNIT_TEST(testIsupperAsciiString);
CPPUNIT_TEST(testIndexOfL);
+ CPPUNIT_TEST(testMatchIgnoreAsciiCaseL);
CPPUNIT_TEST_SUITE_END();
};
@@ -168,6 +170,23 @@ void TestString::testIndexOfL()
RTL_CONSTASCII_STRINGPARAM("two"), 5), static_cast<sal_Int32>(-1));
}
+void TestString::testMatchIgnoreAsciiCaseL()
+{
+ rtl::OString s1(RTL_CONSTASCII_STRINGPARAM("one two three"));
+
+ CPPUNIT_ASSERT_EQUAL(comphelper::string::matchIgnoreAsciiCaseL(s1,
+ RTL_CONSTASCII_STRINGPARAM("one")), sal_True);
+
+ CPPUNIT_ASSERT_EQUAL(comphelper::string::matchIgnoreAsciiCaseL(s1,
+ RTL_CONSTASCII_STRINGPARAM("ONE")), sal_True);
+
+ CPPUNIT_ASSERT_EQUAL(comphelper::string::matchIgnoreAsciiCaseL(s1,
+ RTL_CONSTASCII_STRINGPARAM("two")), sal_False);
+
+ CPPUNIT_ASSERT_EQUAL(comphelper::string::matchIgnoreAsciiCaseL(s1,
+ RTL_CONSTASCII_STRINGPARAM("two"), 4), sal_True);
+}
+
using namespace ::com::sun::star;
class testCollator : public cppu::WeakImplHelper1< i18n::XCollator >
diff --git a/tools/source/fsys/dirent.cxx b/tools/source/fsys/dirent.cxx
index 647dcfcd924f..286260358faf 100644
--- a/tools/source/fsys/dirent.cxx
+++ b/tools/source/fsys/dirent.cxx
@@ -673,7 +673,7 @@ DirEntry::DirEntry( const String& rInitName, FSysPathStyle eStyle )
}
rtl::OString aTmpName(rtl::OUStringToOString(rInitName, osl_getThreadTextEncoding()));
- if (aTmpName.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("file:")))
+ if (comphelper::string::matchIgnoreAsciiCaseL(aTmpName, RTL_CONSTASCII_STRINGPARAM("file:")))
{
#ifndef BOOTSTRAP
DBG_WARNING( "File URLs are not permitted but accepted" );
@@ -692,7 +692,7 @@ DirEntry::DirEntry( const String& rInitName, FSysPathStyle eStyle )
}
#ifdef DBG_UTIL
- if (eStyle == FSYS_STYLE_HOST && aTmpName.indexOf( "://" ) != STRING_NOTFOUND)
+ if (eStyle == FSYS_STYLE_HOST && aTmpName.indexOf( "://" ) != -1)
{
rtl::OStringBuffer aErr(RTL_CONSTASCII_STRINGPARAM("DirEntries akzeptieren nur File URLS: "));
aErr.append(aTmpName);
@@ -727,7 +727,7 @@ DirEntry::DirEntry( const rtl::OString& rInitName, FSysPathStyle eStyle )
}
rtl::OString aTmpName( rInitName );
- if (rInitName.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("file:")))
+ if (comphelper::string::matchIgnoreAsciiCaseL(aTmpName, RTL_CONSTASCII_STRINGPARAM("file:")))
{
#ifndef BOOTSTRAP
DBG_WARNING( "File URLs are not permitted but accepted" );
@@ -1760,27 +1760,27 @@ FSysError DirEntry::ImpParseUnixName( const rtl::OString& rPfad, FSysPathStyle e
/* do nothing */;
#ifdef UNX
- // stellt der Name das User-Dir dar?
- else if ( aName == "~" )
- {
- DirEntry aHome( String( (const char *) getenv( "HOME" ), osl_getThreadTextEncoding()) );
- for ( sal_uInt16 n = aHome.Level(); n; --n )
- aStack.Push( new DirEntry( aHome[ (sal_uInt16) n-1 ] ) );
- }
+ // stellt der Name das User-Dir dar?
+ else if ( aName == "~" )
+ {
+ DirEntry aHome( String( (const char *) getenv( "HOME" ), osl_getThreadTextEncoding()) );
+ for ( sal_uInt16 n = aHome.Level(); n; --n )
+ aStack.Push( new DirEntry( aHome[ (sal_uInt16) n-1 ] ) );
+ }
#endif
-
- // stellt der Name die Parent-Directory dar?
+ // stellt der Name die Parent-Directory dar?
else if ( aName == ".." )
{
// ist nichts, ein Parent oder eine relative Root
// auf dem Stack?
- if ( ( aStack.Empty() ) ||
- ( aStack.Top()->eFlag == FSYS_FLAG_PARENT ) )
+ if ( ( aStack.Empty() ) || ( aStack.Top()->eFlag == FSYS_FLAG_PARENT ) )
+ {
// fuehrende Parents kommen auf den Stack
aStack.Push( new DirEntry(rtl::OString(), FSYS_FLAG_PARENT, eStyle) );
-
+ }
// ist es eine absolute Root
- else if ( aStack.Top()->eFlag == FSYS_FLAG_ABSROOT ) {
+ else if ( aStack.Top()->eFlag == FSYS_FLAG_ABSROOT )
+ {
// die hat keine Parent-Directory
return FSYS_ERR_NOTEXISTS;
}
@@ -1792,16 +1792,16 @@ FSysError DirEntry::ImpParseUnixName( const rtl::OString& rPfad, FSysPathStyle e
{
DirEntry *pNew = NULL;
// normalen Entries kommen auf den Stack
- pNew = new DirEntry( aName, FSYS_FLAG_NORMAL, eStyle );
- if ( !pNew->IsValid() )
- {
- aName = rPfad;
- ErrCode eErr = pNew->GetError();
- delete pNew;
- return eErr;
- }
+ pNew = new DirEntry( aName, FSYS_FLAG_NORMAL, eStyle );
+ if ( !pNew->IsValid() )
+ {
+ aName = rPfad;
+ ErrCode eErr = pNew->GetError();
+ delete pNew;
+ return eErr;
+ }
aStack.Push( pNew );
- }
+ }
}
// den Restpfad bestimmen