summaryrefslogtreecommitdiff
path: root/sal/inc
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2012-09-06 13:51:21 +0200
committerLuboš Luňák <l.lunak@suse.cz>2012-09-06 13:51:21 +0200
commit095ffaf5efef5e8fdc4d7dfa8cd90fff7b768661 (patch)
tree55c50cd9e38b447df614e25948c82e5bb042938b /sal/inc
parent5c804dce946a928adcaf97533f5345b33e688ff5 (diff)
add O(U)String::startsWith() to complement endsWith()
There's match(), with the second argument defaulting to 0, which does the same, but that's pretty non-obvious. Change-Id: Idd4de9388f53e1b5dc5d48446d1001af32c0af3d
Diffstat (limited to 'sal/inc')
-rw-r--r--sal/inc/rtl/string.hxx26
-rw-r--r--sal/inc/rtl/ustring.hxx59
2 files changed, 85 insertions, 0 deletions
diff --git a/sal/inc/rtl/string.hxx b/sal/inc/rtl/string.hxx
index 497e4e3a9dc6..84ab48e05dc6 100644
--- a/sal/inc/rtl/string.hxx
+++ b/sal/inc/rtl/string.hxx
@@ -663,6 +663,32 @@ public:
}
/**
+ Check whether this string starts with a given substring.
+
+ @param str the substring to be compared
+
+ @return true if and only if the given str appears as a substring at the
+ start of this string
+
+ @since LibreOffice 3.7
+ */
+ bool startsWith(OString const & str) const {
+ return match(str, 0);
+ }
+
+ /**
+ @overload
+ This function accepts an ASCII string literal as its argument.
+ @since LibreOffice 3.7
+ */
+ template< typename T >
+ typename internal::ConstCharArrayDetector< T, bool >::Type startsWith( T& literal ) const
+ {
+ RTL_STRING_CONST_FUNCTION
+ return match(literal, 0);
+ }
+
+ /**
Check whether this string ends with a given substring.
@param str the substring to be compared
diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx
index 448f6201e773..3e4e5414d1bb 100644
--- a/sal/inc/rtl/ustring.hxx
+++ b/sal/inc/rtl/ustring.hxx
@@ -881,6 +881,65 @@ public:
#endif
/**
+ Check whether this string starts with a given substring.
+
+ @param str the substring to be compared
+
+ @return true if and only if the given str appears as a substring at the
+ start of this string
+
+ @since LibreOffice 3.7
+ */
+ bool startsWith(OUString const & str) const {
+ return match(str, 0);
+ }
+
+ /**
+ @overload
+ This function accepts an ASCII string literal as its argument.
+ @since LibreOffice 3.7
+ */
+ template< typename T >
+ typename internal::ConstCharArrayDetector< T, bool >::Type startsWith( T& literal ) const
+ {
+ return rtl_ustr_asciil_reverseEquals_WithLength( pData->buffer, literal,
+ internal::ConstCharArrayDetector< T, void >::size - 1);
+ }
+
+ /**
+ Check whether this string starts with a given string, ignoring the case of
+ ASCII letters.
+
+ 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 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
+ @since LibreOffice 3.7
+ */
+ sal_Bool startsWithIgnoreAsciiCase( const OUString & str ) const SAL_THROW(())
+ {
+ return matchIgnoreAsciiCase(str, 0);
+ }
+
+ /**
+ @overload
+ This function accepts an ASCII string literal as its argument.
+ @since LibreOffice 3.7
+ */
+ template< typename T >
+ typename internal::ConstCharArrayDetector< T, bool >::Type startsWithIgnoreAsciiCase( T& literal ) const SAL_THROW(())
+ {
+ return (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
+ pData->buffer,
+ internal::ConstCharArrayDetector< T, void >::size - 1, literal,
+ internal::ConstCharArrayDetector< T, void >::size - 1)
+ == 0);
+ }
+
+ /**
Check whether this string ends with a given substring.
@param str the substring to be compared