From 6df2755ba6b24d0cefd52ce175b0212dd46c9b10 Mon Sep 17 00:00:00 2001 From: Aaron Brashears Date: Mon, 18 May 2009 23:38:35 +0000 Subject: Result of svn merge -r119432:120464 svn+ssh://svn/svn/linden/branches/http_database/merge-03 into trunk. QAR-1462 --- indra/llcommon/llstring.h | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'indra/llcommon/llstring.h') diff --git a/indra/llcommon/llstring.h b/indra/llcommon/llstring.h index 99a9b9e269..6ba665b8d2 100644 --- a/indra/llcommon/llstring.h +++ b/indra/llcommon/llstring.h @@ -228,7 +228,25 @@ public: // True if this is the head of s. static BOOL isHead( const std::basic_string& string, const T* s ); - + + /** + * @brief Returns true if string starts with substr + * + * If etither string or substr are empty, this method returns false. + */ + static bool startsWith( + const std::basic_string& string, + const std::basic_string& substr); + + /** + * @brief Returns true if string ends in substr + * + * If etither string or substr are empty, this method returns false. + */ + static bool endsWith( + const std::basic_string& string, + const std::basic_string& substr); + static void addCRLF(std::basic_string& string); static void removeCRLF(std::basic_string& string); @@ -335,7 +353,7 @@ public: * This function works on bytes rather than glyphs, so this will * incorrectly truncate non-single byte strings. * Use utf8str_truncate() for utf8 strings - * @return a copy of in string minus the trailing count characters. + * @return a copy of in string minus the trailing count bytes. */ inline std::string chop_tail_copy( const std::string& in, @@ -1065,6 +1083,30 @@ BOOL LLStringUtilBase::isHead( const std::basic_string& string, const T* s } } +// static +template +bool LLStringUtilBase::startsWith( + const std::basic_string& string, + const std::basic_string& substr) +{ + if(string.empty() || (substr.empty())) return false; + if(0 == string.find(substr)) return true; + return false; +} + +// static +template +bool LLStringUtilBase::endsWith( + const std::basic_string& string, + const std::basic_string& substr) +{ + if(string.empty() || (substr.empty())) return false; + std::string::size_type idx = string.rfind(substr); + if(std::string::npos == idx) return false; + return (idx == (string.size() - substr.size())); +} + + template BOOL LLStringUtilBase::convertToBOOL(const std::basic_string& string, BOOL& value) { -- cgit v1.3