Allow starts-/endsWith* to also return the rest of the matched string
...as there are many cases where the code later wants to obtain this part, and esp. for the string literal variants it is awkward to calculate the length of the literal again if this is coded with a following copy() call. Adapt some code to use this new feature. (Strictly speaking, the @since tags for the---backwards-compatibly---modified functions are no longer accurate of course. Also, clean up some sal_Bool and SAL_THROWS(()) that are unnecesssary cargo-cult here, and where the clean-up should have no practical compatibility consequences.) Change-Id: I43e5c578c8c4b44cb47fd08f170b5c69322ad641
This commit is contained in:
parent
bb20def9f6
commit
57af2ee947
@ -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()] == '_'))
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user