diff --git a/xpcom/string/nsReadableUtils.cpp b/xpcom/string/nsReadableUtils.cpp index 879b4ef5cdb5..d8904fe95c59 100644 --- a/xpcom/string/nsReadableUtils.cpp +++ b/xpcom/string/nsReadableUtils.cpp @@ -1026,6 +1026,17 @@ CountCharInReadable(const nsACString& aStr, char aChar) return count; } +bool +StringBeginsWith(const nsAString& aSource, const nsAString& aSubstring) +{ + nsAString::size_type src_len = aSource.Length(), + sub_len = aSubstring.Length(); + if (sub_len > src_len) { + return false; + } + return Substring(aSource, 0, sub_len).Equals(aSubstring); +} + bool StringBeginsWith(const nsAString& aSource, const nsAString& aSubstring, const nsStringComparator& aComparator) @@ -1038,6 +1049,17 @@ StringBeginsWith(const nsAString& aSource, const nsAString& aSubstring, return Substring(aSource, 0, sub_len).Equals(aSubstring, aComparator); } +bool +StringBeginsWith(const nsACString& aSource, const nsACString& aSubstring) +{ + nsACString::size_type src_len = aSource.Length(), + sub_len = aSubstring.Length(); + if (sub_len > src_len) { + return false; + } + return Substring(aSource, 0, sub_len).Equals(aSubstring); +} + bool StringBeginsWith(const nsACString& aSource, const nsACString& aSubstring, const nsCStringComparator& aComparator) @@ -1050,6 +1072,17 @@ StringBeginsWith(const nsACString& aSource, const nsACString& aSubstring, return Substring(aSource, 0, sub_len).Equals(aSubstring, aComparator); } +bool +StringEndsWith(const nsAString& aSource, const nsAString& aSubstring) +{ + nsAString::size_type src_len = aSource.Length(), + sub_len = aSubstring.Length(); + if (sub_len > src_len) { + return false; + } + return Substring(aSource, src_len - sub_len, sub_len).Equals(aSubstring); +} + bool StringEndsWith(const nsAString& aSource, const nsAString& aSubstring, const nsStringComparator& aComparator) @@ -1063,6 +1096,17 @@ StringEndsWith(const nsAString& aSource, const nsAString& aSubstring, aComparator); } +bool +StringEndsWith(const nsACString& aSource, const nsACString& aSubstring) +{ + nsACString::size_type src_len = aSource.Length(), + sub_len = aSubstring.Length(); + if (sub_len > src_len) { + return false; + } + return Substring(aSource, src_len - sub_len, sub_len).Equals(aSubstring); +} + bool StringEndsWith(const nsACString& aSource, const nsACString& aSubstring, const nsCStringComparator& aComparator) diff --git a/xpcom/string/nsReadableUtils.h b/xpcom/string/nsReadableUtils.h index 6a697d5eaedc..12b2e67465bf 100644 --- a/xpcom/string/nsReadableUtils.h +++ b/xpcom/string/nsReadableUtils.h @@ -386,18 +386,18 @@ uint32_t CountCharInReadable(const nsAString& aStr, uint32_t CountCharInReadable(const nsACString& aStr, char aChar); +bool StringBeginsWith(const nsAString& aSource, const nsAString& aSubstring); bool StringBeginsWith(const nsAString& aSource, const nsAString& aSubstring, - const nsStringComparator& aComparator = - nsDefaultStringComparator()); + const nsStringComparator& aComparator); +bool StringBeginsWith(const nsACString& aSource, const nsACString& aSubstring); bool StringBeginsWith(const nsACString& aSource, const nsACString& aSubstring, - const nsCStringComparator& aComparator = - nsDefaultCStringComparator()); + const nsCStringComparator& aComparator); +bool StringEndsWith(const nsAString& aSource, const nsAString& aSubstring); bool StringEndsWith(const nsAString& aSource, const nsAString& aSubstring, - const nsStringComparator& aComparator = - nsDefaultStringComparator()); + const nsStringComparator& aComparator); +bool StringEndsWith(const nsACString& aSource, const nsACString& aSubstring); bool StringEndsWith(const nsACString& aSource, const nsACString& aSubstring, - const nsCStringComparator& aComparator = - nsDefaultCStringComparator()); + const nsCStringComparator& aComparator); const nsAFlatString& EmptyString(); const nsAFlatCString& EmptyCString();