Poco::StringTokenizer & String

// Library: Foundation
// Package: Core
// Module:  StringTokenizer

功能:String.h 文件中声明了几个静态函数,用于去除string 的开头和结尾的空白字符,大小写转换,字符串比较,字符映射,字符串替换,字符串连接。StringTokenizer 用于从一个字符串中解析出单词(如果以空白字符作分割符)。

方法:

  • template <class S> S trimLeft(const S& str)   // 都可以在后面加上InPlace,例如trimLeftInPlace,用于直接对传入的字符串进行操作
  • template <class S> S trimRight(const S& str)
  • template <class S> S trim(const S& str)
  • template <class S> S toUpper(const S& str)
  • template <class S> S toLower(const S& str)
  • template <class S> S trim(const S& str)
  • icompare
  • translate
  • replace
  • cat
  • inline const std::string& StringTokenizer::operator [] (std::size_t index) const

std::string s = " abc ";
assert (trimLeft(s) == "abc ");
s = " abc ";
trimLeftInPlace(s);
assert (s == "abc ");
s = "  ab c  ";
assert (trim(s) == "ab c");
std::string s1 = "AAA";
std::string s2 = "aaa";
std::string s3 = "bbb";
std::string s4 = "cCcCc";
std::string s5;
assert (icompare(s1, s2) == 0);
assert (icompare(s1, s3) < 0);
assert (icompare(s1, s4) < 0);
assert (icompare(s3, s1) > 0);

std::string ss1 = "xxAAAzz";
std::string ss2 = "YaaaX";
std::string ss3 = "YbbbX";
assert (icompare(ss1, 2, 3, ss2, 1, 3) == 0);
assert (icompare(ss1, 2, 3, ss3, 1, 3) < 0);

s = "aabbccdd";
assert (translate(s, "abc", "ABC") == "AABBCCdd");
assert (translate(s, "abc", "AB") == "AABBdd");
assert (translate(s, "abc", "") == "dd");
assert (translate(s, "cba", "CB") == "BBCCdd");
assert (translate(s, "", "CB") == "aabbccdd");

std::string s("aabbccdd");
assert (replace(s, std::string("bbcc"), std::string("xx")) == "aaxxdd");

StringTokenizer st("a/bc,def,,ghi // jk,  l ", ",/", StringTokenizer::TOK_TRIM | StringTokenizer::TOK_IGNORE_EMPTY);
StringTokenizer::Iterator it = st.begin();
assert (it != st.end());
assert (*it++ == "a");
assert (it != st.end());
assert (*it++ == "bc");
assert (it != st.end());
assert (*it++ == "def");
assert (it != st.end());
assert (*it++ == "ghi");
assert (it != st.end());
assert (*it++ == "jk");
assert (it != st.end());
assert (*it++ == "l");
assert (it == st.end());




你可能感兴趣的:(Poco::StringTokenizer & String)