diff options
-rw-r--r-- | configmgr/source/access.cxx | 10 | ||||
-rw-r--r-- | configmgr/source/components.cxx | 16 | ||||
-rw-r--r-- | include/rtl/string.hxx | 47 | ||||
-rw-r--r-- | include/rtl/ustring.hxx | 109 | ||||
-rw-r--r-- | unoidl/source/sourceprovider-parser.y | 7 | ||||
-rw-r--r-- | unoidl/source/unoidl-read.cxx | 3 | ||||
-rw-r--r-- | unoidl/source/unoidl-write.cxx | 3 |
7 files changed, 135 insertions, 60 deletions
diff --git a/configmgr/source/access.cxx b/configmgr/source/access.cxx index 31c632c453a2..a181d6216583 100644 --- a/configmgr/source/access.cxx +++ b/configmgr/source/access.cxx @@ -1398,9 +1398,11 @@ rtl::Reference< Node > Access::getParentNode() { } rtl::Reference< ChildAccess > Access::getChild(OUString const & name) { - if (getNode()->kind() == Node::KIND_LOCALIZED_PROPERTY && name.match("*")) { - OUString locale(name.copy(1)); - if (locale.match("*")) { + OUString locale; + if (getNode()->kind() == Node::KIND_LOCALIZED_PROPERTY + && name.startsWith("*", &locale)) + { + if (locale.startsWith("*")) { SAL_WARN( "configmgr", ("access best-matching localized property value via" @@ -1443,7 +1445,7 @@ rtl::Reference< ChildAccess > Access::getChild(OUString const & name) { i != children.end(); ++i) { OUString name2((*i)->getNameInternal()); - if (name2.match(locale) && + if (name2.startsWith(locale) && (name2.getLength() == locale.getLength() || name2[locale.getLength()] == '-' || name2[locale.getLength()] == '_')) diff --git a/configmgr/source/components.cxx b/configmgr/source/components.cxx index b5b38b5b9371..85865fd00e7d 100644 --- a/configmgr/source/components.cxx +++ b/configmgr/source/components.cxx @@ -43,9 +43,7 @@ #include "osl/mutex.hxx" #include "rtl/bootstrap.hxx" #include "rtl/ref.hxx" -#include "rtl/string.h" #include "rtl/ustrbuf.hxx" -#include "rtl/ustring.h" #include "rtl/ustring.hxx" #include "rtl/instance.hxx" #include "sal/log.hxx" @@ -639,9 +637,7 @@ void Components::parseFiles( parseFiles(layer, extension, parseFile, stat.getFileURL(), true); } else { OUString file(stat.getFileName()); - if (file.getLength() >= extension.getLength() && - file.match(extension, file.getLength() - extension.getLength())) - { + if (file.endsWith(extension)) { try { parseFileLeniently( parseFile, stat.getFileURL(), layer, data_, 0, 0, 0); @@ -718,14 +714,8 @@ void Components::parseXcdFiles(int layer, OUString const & url) { } if (stat.getFileType() != osl::FileStatus::Directory) { //TODO: symlinks OUString file(stat.getFileName()); - if (file.getLength() >= RTL_CONSTASCII_LENGTH(".xcd") && - file.matchAsciiL( - RTL_CONSTASCII_STRINGPARAM(".xcd"), - file.getLength() - RTL_CONSTASCII_LENGTH(".xcd"))) - { - OUString name( - file.copy( - 0, file.getLength() - RTL_CONSTASCII_LENGTH(".xcd"))); + OUString name; + if (file.endsWith(".xcd", &name)) { existingDeps.insert(name); rtl::Reference< ParseManager > manager; try { diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx index e54ce8e7fc29..e9c6350c006d 100644 --- a/include/rtl/string.hxx +++ b/include/rtl/string.hxx @@ -682,15 +682,22 @@ public: /** Check whether this string starts with a given substring. - @param str the substring to be compared + @param str the substring to be compared + + @param rest if non-null, and this function returns true, then assign a + copy of the remainder of this string to *rest @return true if and only if the given str appears as a substring at the start of this string @since LibreOffice 4.0 */ - bool startsWith(OString const & str) const { - return match(str, 0); + bool startsWith(OString const & str, OString * rest = 0) const { + bool b = match(str, 0); + if (b && rest != 0) { + *rest = copy(str.getLength()); + } + return b; } /** @@ -699,25 +706,37 @@ public: @since LibreOffice 4.0 */ template< typename T > - typename internal::ConstCharArrayDetector< T, bool >::Type startsWith( T& literal ) const + typename internal::ConstCharArrayDetector< T, bool >::Type startsWith( + T & literal, OString * rest = 0) const { RTL_STRING_CONST_FUNCTION - return match(literal, 0); + bool b = match(literal, 0); + if (b && rest != 0) { + *rest = copy(internal::ConstCharArrayDetector< T, void >::size - 1); + } + return b; } /** Check whether this string ends with a given substring. - @param str the substring to be compared + @param str the substring to be compared + + @param rest if non-null, and this function returns true, then assign a + copy of the remainder of this string to *rest @return true if and only if the given str appears as a substring at the end of this string @since LibreOffice 3.6 */ - bool endsWith(OString const & str) const { - return str.getLength() <= getLength() + bool endsWith(OString const & str, OString * rest = 0) const { + bool b = str.getLength() <= getLength() && match(str, getLength() - str.getLength()); + if (b && rest != 0) { + *rest = copy(0, getLength() - str.getLength()); + } + return b; } /** @@ -726,12 +745,20 @@ public: @since LibreOffice 3.6 */ template< typename T > - typename internal::ConstCharArrayDetector< T, bool >::Type endsWith( T& literal ) const + typename internal::ConstCharArrayDetector< T, bool >::Type endsWith( + T & literal, OString * rest = 0) const { RTL_STRING_CONST_FUNCTION assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 ); - return internal::ConstCharArrayDetector< T, void >::size - 1 <= getLength() + bool b = internal::ConstCharArrayDetector< T, void >::size - 1 <= getLength() && match(literal, getLength() - ( internal::ConstCharArrayDetector< T, void >::size - 1 )); + if (b && rest != 0) { + *rest = copy( + 0, + (getLength() + - (internal::ConstCharArrayDetector< T, void >::size - 1))); + } + return b; } /** diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx index daa0ff52ea43..ba8c3588aa58 100644 --- a/include/rtl/ustring.hxx +++ b/include/rtl/ustring.hxx @@ -923,15 +923,22 @@ public: /** Check whether this string starts with a given substring. - @param str the substring to be compared + @param str the substring to be compared + + @param rest if non-null, and this function returns true, then assign a + copy of the remainder of this string to *rest @return true if and only if the given str appears as a substring at the start of this string @since LibreOffice 4.0 */ - bool startsWith(OUString const & str) const { - return match(str, 0); + bool startsWith(OUString const & str, OUString * rest = 0) const { + bool b = match(str, 0); + if (b && rest != 0) { + *rest = copy(str.getLength()); + } + return b; } /** @@ -940,12 +947,17 @@ public: @since LibreOffice 4.0 */ template< typename T > - typename internal::ConstCharArrayDetector< T, bool >::Type startsWith( T& literal ) const + typename internal::ConstCharArrayDetector< T, bool >::Type startsWith( + T & literal, OUString * rest = 0) const { assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 ); - return internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length + bool b = internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length && rtl_ustr_asciil_reverseEquals_WithLength( pData->buffer, literal, internal::ConstCharArrayDetector< T, void >::size - 1); + if (b && rest != 0) { + *rest = copy(internal::ConstCharArrayDetector< T, void >::size - 1); + } + return b; } /** @@ -956,14 +968,25 @@ public: values between 97 and 122 (ASCII a-z). This function can't be used for language specific comparison. - @param str the object (substring) to be compared. - @return true if this string starts with str, ignoring the case of ASCII - letters ("A"--"Z" and "a"--"z"); otherwise, false is returned + @param str the substring to be compared + + @param rest if non-null, and this function returns true, then assign a + copy of the remainder of this string to *rest + + @return true if and only if the given str appears as a substring at the + start of this string, ignoring the case of ASCII letters ("A"--"Z" and + "a"--"z") + @since LibreOffice 4.0 */ - sal_Bool startsWithIgnoreAsciiCase( const OUString & str ) const SAL_THROW(()) + bool startsWithIgnoreAsciiCase(OUString const & str, OUString * rest = 0) + const { - return matchIgnoreAsciiCase(str, 0); + bool b = matchIgnoreAsciiCase(str, 0); + if (b && rest != 0) { + *rest = copy(str.getLength()); + } + return b; } /** @@ -972,29 +995,41 @@ public: @since LibreOffice 4.0 */ template< typename T > - typename internal::ConstCharArrayDetector< T, bool >::Type startsWithIgnoreAsciiCase( T& literal ) const SAL_THROW(()) + typename internal::ConstCharArrayDetector< T, bool >::Type + startsWithIgnoreAsciiCase(T & literal, OUString * rest = 0) const { assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 ); - return (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths( + bool b = (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths( pData->buffer, internal::ConstCharArrayDetector< T, void >::size - 1, literal, internal::ConstCharArrayDetector< T, void >::size - 1) == 0); + if (b && rest != 0) { + *rest = copy(internal::ConstCharArrayDetector< T, void >::size - 1); + } + return b; } /** Check whether this string ends with a given substring. - @param str the substring to be compared + @param str the substring to be compared + + @param rest if non-null, and this function returns true, then assign a + copy of the remainder of this string to *rest @return true if and only if the given str appears as a substring at the end of this string @since LibreOffice 3.6 */ - bool endsWith(OUString const & str) const { - return str.getLength() <= getLength() + bool endsWith(OUString const & str, OUString * rest = 0) const { + bool b = str.getLength() <= getLength() && match(str, getLength() - str.getLength()); + if (b && rest != 0) { + *rest = copy(0, getLength() - str.getLength()); + } + return b; } /** @@ -1003,13 +1038,21 @@ public: @since LibreOffice 3.6 */ template< typename T > - typename internal::ConstCharArrayDetector< T, bool >::Type endsWith( T& literal ) const + typename internal::ConstCharArrayDetector< T, bool >::Type + endsWith(T & literal, OUString * rest = 0) const { assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 ); - return internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length + bool b = internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length && rtl_ustr_asciil_reverseEquals_WithLength( pData->buffer + pData->length - ( internal::ConstCharArrayDetector< T, void >::size - 1 ), literal, internal::ConstCharArrayDetector< T, void >::size - 1); + if (b && rest != 0) { + *rest = copy( + 0, + (getLength() + - (internal::ConstCharArrayDetector< T, void >::size - 1))); + } + return b; } /** @@ -1040,15 +1083,25 @@ public: values between 97 and 122 (ASCII a-z). This function can't be used for language specific comparison. - @param str the object (substring) to be compared. - @return true if this string ends with str, ignoring the case of ASCII - letters ("A"--"Z" and "a"--"z"); otherwise, false is returned + @param str the substring to be compared + + @param rest if non-null, and this function returns true, then assign a + copy of the remainder of this string to *rest + + @return true if and only if the given str appears as a substring at the + end of this string, ignoring the case of ASCII letters ("A"--"Z" and + "a"--"z") + @since LibreOffice 3.6 */ - sal_Bool endsWithIgnoreAsciiCase( const OUString & str ) const SAL_THROW(()) + bool endsWithIgnoreAsciiCase(OUString const & str, OUString * rest) const { - return str.getLength() <= getLength() + bool b = str.getLength() <= getLength() && matchIgnoreAsciiCase(str, getLength() - str.getLength()); + if (b && rest != 0) { + *rest = copy(0, getLength() - str.getLength()); + } + return b; } /** @@ -1057,15 +1110,23 @@ public: @since LibreOffice 3.6 */ template< typename T > - typename internal::ConstCharArrayDetector< T, bool >::Type endsWithIgnoreAsciiCase( T& literal ) const SAL_THROW(()) + typename internal::ConstCharArrayDetector< T, bool >::Type + endsWithIgnoreAsciiCase(T & literal, OUString * rest = 0) const { assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 ); - return internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length + bool b = internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths( pData->buffer + pData->length - ( internal::ConstCharArrayDetector< T, void >::size - 1 ), internal::ConstCharArrayDetector< T, void >::size - 1, literal, internal::ConstCharArrayDetector< T, void >::size - 1) == 0); + if (b && rest != 0) { + *rest = copy( + 0, + (getLength() + - (internal::ConstCharArrayDetector< T, void >::size - 1))); + } + return b; } /** diff --git a/unoidl/source/sourceprovider-parser.y b/unoidl/source/sourceprovider-parser.y index 6512e4a69d64..8f813c3a6c45 100644 --- a/unoidl/source/sourceprovider-parser.y +++ b/unoidl/source/sourceprovider-parser.y @@ -261,9 +261,7 @@ unoidl::detail::SourceProviderEntity * findEntity_( assert(data != 0); assert(name != 0); OUString n; - if (name->startsWith(".")) { - n = name->copy(1); - } else { + if (!name->startsWith(".", &n)) { for (std::vector<OUString>::const_reverse_iterator i(data->modules.rbegin()); i != data->modules.rend(); ++i) { @@ -345,7 +343,7 @@ Found findEntity( static_cast<unoidl::TypedefEntity *>(e->entity.get()) ->getType()); typeNucleus = t; - while (typeNucleus.startsWith("[]")) { + while (typeNucleus.startsWith("[]", &typeNucleus)) { if (!args.empty()) { error( location, yyscanner, @@ -363,7 +361,6 @@ Found findEntity( return FOUND_ERROR; } ++rank; - typeNucleus = typeNucleus.copy(2); } sal_Int32 i = typeNucleus.indexOf('<'); if (i != -1) { diff --git a/unoidl/source/unoidl-read.cxx b/unoidl/source/unoidl-read.cxx index 2bbe8b672dba..1a7633535579 100644 --- a/unoidl/source/unoidl-read.cxx +++ b/unoidl/source/unoidl-read.cxx @@ -91,9 +91,8 @@ OUString decomposeType( OUString nucl(type); *rank = 0; typeArguments->clear(); - while (nucl.startsWith("[]")) { + while (nucl.startsWith("[]", &nucl)) { ++*rank; - nucl = nucl.copy(2); } sal_Int32 i = nucl.indexOf('<'); if (i != -1) { diff --git a/unoidl/source/unoidl-write.cxx b/unoidl/source/unoidl-write.cxx index ad9268e59a6e..8b3b3bf4b287 100644 --- a/unoidl/source/unoidl-write.cxx +++ b/unoidl/source/unoidl-write.cxx @@ -57,12 +57,11 @@ void badUsage() { OUString getArgumentUri(sal_uInt32 argument, bool * entities) { OUString arg; rtl_getAppCommandArg(argument, &arg.pData); - if (arg.startsWith("@")) { + if (arg.startsWith("@", &arg)) { if (entities == 0) { badUsage(); } *entities = true; - arg = arg.copy(1); } else if (entities != 0) { *entities = false; } |