diff --git a/base/include/string_ex.h b/base/include/string_ex.h index bcb7d4b..41be2ad 100755 --- a/base/include/string_ex.h +++ b/base/include/string_ex.h @@ -118,13 +118,13 @@ bool IsAsciiString(const std::string& str); /** * The str16ToStr8 function convert string16 to string8. - * If covert failed, return an empty string. + * If convert failed, return an empty string. */ std::string Str16ToStr8(const std::u16string& str16); /** * The Str8ToStr16 function convert string8 to string16. - * If covert failed, return an empty u16string. + * If convert failed, return an empty u16string. */ std::u16string Str8ToStr16(const std::string& str); } // namespace OHOS diff --git a/base/src/string_ex.cpp b/base/src/string_ex.cpp index 6665223..65ce7d2 100755 --- a/base/src/string_ex.cpp +++ b/base/src/string_ex.cpp @@ -216,14 +216,12 @@ string::size_type GetFirstSubStrBetween(const string& str, const string& left, void GetSubStrBetween(const string& str, const string& left, const string& right, vector& sub) { string subString; - string::size_type pos = 0; string strTmp = str; + string::size_type pos = GetFirstSubStrBetween(strTmp, left, right, subString); while (pos != string::npos) { + sub.push_back(subString); + strTmp = strTmp.substr(pos); pos = GetFirstSubStrBetween(strTmp, left, right, subString); - if (pos != string::npos) { - sub.push_back(subString); - strTmp = strTmp.substr(pos); - } } }