mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
update cppcommon for endswith in str_funst.h
This commit is contained in:
parent
8b3a192037
commit
2319fd9307
@ -228,11 +228,6 @@ namespace CPPCOMMON
|
||||
return res;
|
||||
}
|
||||
|
||||
bool strStartsWith(const string& str, const string& prefix)
|
||||
{
|
||||
return str.substr(0, prefix.size()) == prefix;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#ifdef TEST_STR_FUNCTS
|
||||
@ -302,15 +297,17 @@ int main()
|
||||
// s = utf8ToGbk(s);
|
||||
// cout<<s<<endl;
|
||||
//}
|
||||
//cout<<strStartsWith("--help","--")<<endl;
|
||||
//cout<<strStartsWith("--help","-")<<endl;
|
||||
//cout<<strStartsWith("--help","he")<<endl;
|
||||
//cout<<strStartsWith("help","help")<<endl;
|
||||
//cout<<strStartsWith("","help")<<endl;
|
||||
//cout<<strStartsWith("hel","")<<endl;
|
||||
string s(" helloword heh\t");
|
||||
string b;
|
||||
cout<<trim(b)<<"11"<<endl;
|
||||
cout<<strStartsWith("--help","--")<<endl;
|
||||
cout<<strStartsWith("--help","-")<<endl;
|
||||
cout<<strStartsWith("--help","he")<<endl;
|
||||
cout<<strStartsWith("help","help")<<endl;
|
||||
cout<<strStartsWith("","help")<<endl;
|
||||
cout<<strStartsWith("hel","")<<endl;
|
||||
cout<<strEndsWith("hel","")<<endl;
|
||||
cout<<strEndsWith("hel","el")<<endl;
|
||||
//string s(" helloword heh\t");
|
||||
//string b;
|
||||
//cout<<trim(b)<<"11"<<endl;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -63,7 +63,24 @@ namespace CPPCOMMON
|
||||
cout<<uniVecToStr(unicode)<<endl;
|
||||
}
|
||||
|
||||
bool strStartsWith(const string& str, const string& prefix);
|
||||
inline bool strStartsWith(const string& str, const string& prefix)
|
||||
{
|
||||
//return str.substr(0, prefix.size()) == prefix;
|
||||
if(prefix.length() > str.length())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return 0 == str.compare(0, prefix.length(), prefix);
|
||||
}
|
||||
|
||||
inline bool strEndsWith(const string& str, const string& suffix)
|
||||
{
|
||||
if(suffix.length() > str.length())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return 0 == str.compare(str.length() - suffix.length(), suffix.length(), suffix);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user