📄 ck_str.cpp
字号:
if(res!=100) { WY_THROW( WyRet() ); } } // _find_in(size_t*,size_t,const WyCSeg) { WyStr tmp; size_t res; res=100; if(tmp._find_in(&res,0,WyCSeg())!=false) { WY_THROW( WyRet() ); } if(res!=100) { WY_THROW( WyRet() ); } tmp+='x'; if(tmp._find_in(&res,0,WyCSeg("abc"))!=false) { WY_THROW( WyRet() ); } if(res!=100) { WY_THROW( WyRet() ); } tmp="\n\r123abccKOIU"; if(tmp._find_in(&res,0,WyCSeg("OKc"))!=true) { WY_THROW( WyRet() ); } if(res!=7) { WY_THROW( WyRet() ); } res=100; if(tmp._find_in(&res,7,WyCSeg("UcK"))!=true) { WY_THROW( WyRet() ); } if(res!=7) { WY_THROW( WyRet() ); } if(tmp._find_in(&res,0,WyCSeg("1"))!=true) { WY_THROW( WyRet() ); } if(res!=2) { WY_THROW( WyRet() ); } res=100; if(tmp._find_in(&res,0,tmp.cseg())!=true) { WY_THROW( WyRet() ); } if(res!=0) { WY_THROW( WyRet() ); } } // _rfind_in(size_t*,size_t,const WyCSeg) { WyStr tmp; size_t res; res=100; if(tmp._rfind_in(&res,1,WyCSeg())!=false) { WY_THROW( WyRet() ); } if(res!=100) { WY_THROW( WyRet() ); } if(tmp._rfind_in(&res,0,WyCSeg("axc"))!=false) { WY_THROW( WyRet() ); } if(res!=100) { WY_THROW( WyRet() ); } tmp+='x'; if(tmp._rfind_in(&res,9,WyCSeg("axc"))!=true) { WY_THROW( WyRet() ); } if(res!=0) { WY_THROW( WyRet() ); } tmp="\n\r123abccKOIU"; if(tmp._rfind_in(&res,99,WyCSeg("OKc"))!=true) { WY_THROW( WyRet() ); } if(res!=10) { WY_THROW( WyRet() ); } res=100; if(tmp._rfind_in(&res,99,WyCSeg("1c2"))!=true) { WY_THROW( WyRet() ); } if(res!=8) { WY_THROW( WyRet() ); } if(tmp._rfind_in(&res,10,WyCSeg("1"))!=true) { WY_THROW( WyRet() ); } if(res!=2) { WY_THROW( WyRet() ); } res=100; if(tmp._rfind_in(&res,99,tmp.cseg())!=true) { WY_THROW( WyRet() ); } if(res!=tmp.size()-1) { WY_THROW( WyRet() ); } } // substr() modified to cseg() { WyStr tmp_str("xy564"); const WyCSeg cseg(tmp_str.cseg()); if(cseg.begin()!=tmp_str.data()) { WY_THROW(WyRet() ); } if(cseg.size()!=tmp_str.size()) { WY_THROW(WyRet() ); } } // substr(..) modified to cseg(..) { WyStr tmp; CHK_DEFAULT(tmp.cseg(0)); CHK_DEFAULT(tmp.cseg(0,0)); CHK_DEFAULT(tmp.cseg(0,2)); WyStr tmp1("abcd"); if( WyStr(tmp1.cseg(2))!="cd") { WY_THROW(WyRet() ); } if( WyStr(tmp1.cseg(2,5))!="cd") { WY_THROW(WyRet() ); } if( WyStr(tmp1.cseg(0))!="abcd") { WY_THROW(WyRet() ); } if( WyStr(tmp1.cseg(0,5))!="abcd") { WY_THROW(WyRet() ); } } // cseg { WyStr tmp; WyCSeg cseg( tmp.cseg(0) ); if(cseg.size()!=0) { WY_THROW(WyRet() ); } if(cseg.begin()!=tmp.data()) { WY_THROW(WyRet() ); } const WyStr tmp1("bcd"); cseg.reset(tmp1.cseg(1)); if(cseg.size()!=tmp1.size()-1) { WY_THROW(WyRet() ); } if(cseg.begin()!=tmp1.data()+1) { WY_THROW(WyRet() ); } cseg.reset(tmp1.cseg()); if(cseg.size()!=tmp1.size()) { WY_THROW(WyRet() ); } if(cseg.begin()!=tmp1.data()) { WY_THROW(WyRet() ); } cseg.reset(tmp1.cseg(1,1)); if(cseg.size()!=1) { WY_THROW(WyRet() ); } if(cseg.begin()!=tmp1.data()+1) { WY_THROW(WyRet() ); } cseg.reset(tmp1.cseg(1,100)); if(cseg.size()!=tmp1.size()-1) { WY_THROW(WyRet() ); } if(cseg.begin()!=tmp1.data()+1) { WY_THROW(WyRet() ); } } // _strcmp and == { const WyStr tmp0; const WyStr tmp1a("qwert"); const WyStr tmp1b("qweru"); const WyStr tmp2a("qwerty"); const WyStr tmp2b("qwertu"); if(tmp0!="") { WY_THROW(WyRet() ); } if(tmp0._strcmp(tmp0)!=0) { WY_THROW(WyRet() ); } if(tmp0._strcmp(tmp1a)>=0) { WY_THROW(WyRet() ); } if(tmp1a._strcmp(tmp0)<=0) { WY_THROW(WyRet() ); } if(tmp1a._strcmp(tmp1a)!=0) { WY_THROW(WyRet() ); } if(tmp1a._strcmp(tmp1b)>=0) { WY_THROW(WyRet() ); } if(tmp1a._strcmp(tmp2a)>=0) { WY_THROW(WyRet() ); } if(tmp1a._strcmp(tmp0.c_str())<=0) { WY_THROW(WyRet() ); } if(tmp1a._strcmp(tmp1a.c_str())!=0) { WY_THROW(WyRet() ); } if(tmp1a._strcmp(tmp1b.c_str())>=0) { WY_THROW(WyRet() ); } if(tmp1a._strcmp(tmp2a.c_str())>=0) { WY_THROW(WyRet() ); } if(tmp2a._strcmp(tmp0)<=0) { WY_THROW(WyRet() ); } if(tmp2a._strcmp(tmp2b)==0) { WY_THROW(WyRet() ); } if(tmp2a._strcmp(tmp1b)>-0) { WY_THROW(WyRet() ); } if(tmp2a._strcmp(tmp2a)!=0) { WY_THROW(WyRet() ); } // Wy::_strcmp if(Wy::_strcmp(tmp1a,tmp0)<=0) { WY_THROW(WyRet() ); } if(Wy::_strcmp(tmp1a,tmp1a)!=0) { WY_THROW(WyRet() ); } if(Wy::_strcmp(tmp1a.cseg(1,2),tmp0)<=0) { WY_THROW(WyRet() ); } if(Wy::_strcmp(tmp1a.cseg(1,2),tmp1a)<=0) { WY_THROW(WyRet() ); } if(Wy::_strcmp(tmp1a.cseg(1,2),tmp0.c_str())<=0) { WY_THROW(WyRet() ); } if(Wy::_strcmp(tmp1a.cseg(1,2),tmp1a.c_str())<=0) { WY_THROW(WyRet() ); } if(Wy::_strcmp(tmp1a.cseg(1,2),tmp0)<=0) { WY_THROW(WyRet() ); } if(Wy::_strcmp(tmp1a.cseg(1,2).begin(),tmp1a)<=0) { WY_THROW(WyRet() ); } if(Wy::_strcmp(tmp1a.cseg(1,2),WyCSeg(tmp0.c_str(),1))<=0) { WY_THROW(WyRet() ); } if(Wy::_strcmp(tmp1a.cseg(1,2),WyCSeg(tmp1a.c_str()+1,3))>=0) { WY_THROW(WyRet() ); } if(Wy::_strcmp(tmp1a.cseg(1,2),WyCSeg(tmp1a.c_str()+1,2))!=0) { WY_THROW(WyRet() ); } if(tmp1a==(const char*)tmp1a.c_str()) { } else { WY_THROW(WyRet() ); } if(tmp1a!=(const char*)tmp1a.c_str()) { WY_THROW(WyRet() ); } } // _reserve(size_t) { const char* STR="aaa"; WyStr str(STR); if(str!=STR) { WY_THROW( WyRet() ); } if(str.size()!=std::strlen(STR)) { WY_THROW( WyRet() ); } if(str._capacity()<WyStr::min_capacity()) { WY_THROW( WyRet() ); } if(str._reserve(1)!=Ok) { WY_THROW( WyRet() ); } if(str!=STR) { WY_THROW( WyRet() ); } if(str.size()!=std::strlen(STR)) { WY_THROW( WyRet() ); } if(str._capacity()<WyStr::min_capacity()) { WY_THROW( WyRet() ); } if(str._reserve(10)!=Ok) { WY_THROW( WyRet() ); } if(str!=STR) { WY_THROW( WyRet() ); } if(str.size()!=std::strlen(STR)) { WY_THROW( WyRet() ); } if(str._capacity()<WyStr::min_capacity()) { WY_THROW( WyRet() ); } if(str._reserve(100000)!=Ok) { WY_THROW( WyRet() ); } if(str!=STR) { WY_THROW( WyRet() ); } if(str.size()!=std::strlen(STR)) { WY_THROW( WyRet() ); } if(str._capacity()<100000) { WY_THROW( WyRet() ); } // just chk is_ok //if(str._reserve(100000).is_ok()) { // WY_THROW( WyRet() ); //} } // operator + { const char* cstr="bt"; const char ch('x'); const WyStr str("gfh"); if((str+str)!=WyStr("gfhgfh")) { WY_THROW(WyRet() ); } if((str+str.cseg())!=WyStr("gfhgfh")) { WY_THROW(WyRet() ); } if((str+cstr)!=WyStr("gfhbt")) { WY_THROW(WyRet() ); } if((WyCSeg(cstr)+str)!=WyStr("btgfh")) { WY_THROW(WyRet() ); } if((cstr+str)!=WyStr("btgfh")) { WY_THROW(WyRet() ); } if((cstr+str.cseg())!=WyStr("btgfh")) { WY_THROW(WyRet() ); } if((str+ch)!=WyStr("gfhx")) { WY_THROW(WyRet() ); } if((ch+str)!=WyStr("xgfh")) { WY_THROW(WyRet() ); } } // aux: ==(const WyCSeg&,const WyStr&) { const WyCSeg str1("bt"),str2("u"); if((const WyCSeg&)str1==WyStr(str1)) { } else { WY_THROW( WyRet() ); } if((const WyCSeg&)str1!=WyStr(str1)) { WY_THROW( WyRet() ); } if((const WyCSeg&)str1==WyStr(str2)) { WY_THROW( WyRet() ); } if((const WyCSeg&)str1!=WyStr(str2)) { } else { WY_THROW( WyRet() ); } } // aux: ==(const char*,const WyStr&) { const char *str1="bt",*str2="u"; if(str1==WyStr(str1)) { } else { WY_THROW( WyRet() ); } if(str1!=WyStr(str1)) { WY_THROW( WyRet() ); } if(str1==WyStr(str2)) { WY_THROW( WyRet() ); } if(str1!=WyStr(str2)) { } else { WY_THROW( WyRet() ); } } // chk _setsize(size_t) { WyStr tmp; tmp._setsize(0); CHK_DEFAULT(tmp); const char* TStr="abc"; tmp=TStr; if(tmp!=TStr) { WY_THROW( WyRet() ); } tmp._setsize(0); CHK_DEFAULT(tmp); tmp._setsize(1); if(tmp!=WyCSeg("\0",1)) { WY_THROW( WyRet() ); } tmp._setsize(3); if(tmp!=WyCSeg("\0\0c",3)) { WY_THROW( WyRet() ); } { WyStr tmp; if((r=tmp._setsize(WyStr::max_capacity()+1))!=Wym_EFBIG) { WY_THROW(r); } } } // chk move ctor { char buf[2*sizeof(WyStr)]; ::memset(buf,0,sizeof(buf)); WyStr*p=reinterpret_cast<WyStr*>(buf); new(p) WyStr(WyCSeg("pm",2)); new(p+1) WyStr(*p,Wy::ByMove); if((p+1)->_strcmp("pm")!=0) { (p+1)->~WyStr(); WY_THROW( WyRet() ); } (p+1)->~WyStr(); }};static void t1_error(void){ WyRet r; // chk error WyStr(const WyStr&,size_t) try { WyStr tmp("123"); WyStr tmp1(tmp.cseg(4)); WY_THROW( WyRet() ); } catch(const WyStr::Reply& e) { if(e!=Wym_EINVAL) { throw; } // FALLTHOUGH }; // chk error WyStr(const WyStr&,size_t,size_t) try { WyStr tmp("123"); WyStr tmp1(tmp.cseg(4,1)); WY_THROW( WyRet() ); } catch(const WyStr::Reply& e) { if(e!=Wym_EINVAL) { throw; } // FALLTHOUGH }; // chk error WyStr(const WyCSeg&) try { WyStr tmp( WyCSeg(0,1) ); WY_THROW( WyRet() ); } catch(const WyCSeg::Reply& e) { if(e!=Wym_EFAULT) { throw; } // FALLTHOUGH }; // chk error at(size_t) try { WyStr tmp; tmp.at(tmp.size()+1); WY_THROW( WyRet() ); } catch(const WyStr::Reply& e) { if(e!=Wym_EINVAL) { throw; } // FALLTHOUGH }; const WyStr NZSTR("x"); // non zero string for test. as operation may say // ok if argument str is zero size WyStr tmp("khio"); // chk error reset(const WyStr&,size_t) if((r=tmp.reset(tmp))!=Wym_ELOOP) { WY_THROW(r); } try { tmp.reset(tmp.cseg(tmp.size()+1)); WY_THROW( WyRet() ); } catch(const WyStr::Reply& e) { if(e!=Wym_EINVAL) { throw; } // FALL_THROUGH }; try { tmp.reset(tmp.cseg(tmp.size()+1,1)); WY_THROW(r); } catch(const WyStr::Reply& e) { if(e!=Wym_EINVAL) { throw; } // FALL_THROUGH }; if((r=tmp.reset(tmp.cseg(1,2)))!=Wym_ELOOP) { WY_THROW(r); } if((r=tmp.reset(tmp.cseg(2,1)))!=Ok) { // This is imp. feature, src/des on the same buffer though WY_THROW(r); } if((r=tmp.reset(tmp.cseg(tmp.size()-1,1)))!=Wym_ELOOP) { WY_THROW(r); } try { tmp.append(tmp.cseg(tmp.size()+1)); WY_THROW(r); } catch(const WyStr::Reply& e) { if(e!=Wym_EINVAL) { throw; } // FALL_THROUGH }; // check error operator = { try { tmp=tmp.cseg(); } catch(const WyStr::Reply& e) { if(e!=Wym_ELOOP) { throw; } // FALL_THROUGH }; try { tmp=tmp; } catch(const WyStr::Reply& e) { if(e!=Wym_ELOOP) { throw; } // FALL_THROUGH }; } // check error append(..) try { tmp.append(tmp.cseg(tmp.size()+1,1)); WY_THROW(r); } catch(const WyStr::Reply& e) { if(e!=Wym_EINVAL) { throw; } // FALL_THROUGH }; // check error insert(..) if((r=tmp.insert(tmp.size()+1,NZSTR))!=Wym_EINVAL) { WY_THROW(r); } if((r=tmp.insert(tmp.size()+1,1,'a'))!=Wym_EINVAL) { WY_THROW(r); } { WyStr tmp4("abcd"); if((r=tmp4.insert(0,tmp4))!=Wym_ELOOP) { WY_THROW(r); } if((r=tmp4.insert(tmp4.size()-1,tmp4))!=Wym_ELOOP) { WY_THROW(r); } if((r=tmp4.insert(tmp4.size(),tmp4))!=Ok) { WY_THROW(r); } if(tmp4!="abcdabcd") { WY_THROW( WyRet() ); } } // check error erase(..) if((r=tmp.erase(tmp.size()+1))!=Wym_EINVAL) { WY_THROW(r); } if((r=tmp.erase(tmp.size()+1,1))!=Wym_EINVAL) { WY_THROW( WyRet() ); } // chk error replace(..) if((r=tmp.replace(tmp.size()+1,1,NZSTR))!=Wym_EINVAL) { WY_THROW( WyRet() ); } if((r=tmp.replace(tmp.size()+1,1,NZSTR.cseg(0)))!=Wym_EINVAL) { WY_THROW( WyRet() ); } if((r=tmp.replace(tmp.size()+1,1,NZSTR.cseg(0,1)))!=Wym_EINVAL) { WY_THROW( WyRet() ); } if((r=tmp.replace(tmp.size()+1,1,WyCSeg("",1)))!=Wym_EINVAL) { WY_THROW(r); } if((r=tmp.replace(tmp.size()+1,1,1,'x'))!=Wym_EINVAL) { WY_THROW(r); } { // chk error WyStr tmp4("13579"); WyStr TMP4; if((r=tmp4.replace(0,1,tmp4))!=Wym_ELOOP) { WY_THROW(r); } if((r=tmp4.replace(tmp4.size()-1,1,tmp4))!=Wym_ELOOP) { WY_THROW(r); } if((r=tmp4.replace(1,3,tmp4))!=Wym_ELOOP) { WY_THROW(r); } TMP4=tmp4; if((r=tmp4.replace(tmp4.size(),0,tmp4))!=Ok) { if(tmp4!=TMP4) { WY_THROW( WyRet() ); // failure postcondition } if(r!=Wym_ELOOP) { WY_THROW(r); // protocol violated } } else { if(tmp4!=TMP4+TMP4) { WY_THROW( WyRet() ); } } if((r=tmp4.replace(0,1,tmp4.cseg()))!=Wym_ELOOP) { WY_THROW(r); } if((r=tmp4.replace(tmp4.size()-1,1,tmp4.cseg()))!=Wym_ELOOP) { WY_THROW(r); } if((r=tmp4.replace(1,3,tmp4.cseg()))!=Wym_ELOOP) { WY_THROW(r); } TMP4=tmp4; if((r=tmp4.replace(tmp4.size(),0,tmp4.cseg()))!=Ok) { if(tmp4!=TMP4) { WY_THROW( WyRet() ); // failure postcondition } if(r!=Wym_ELOOP) { WY_THROW(r); // protocol violated } } else { if(tmp4!=TMP4+TMP4) { WY_THROW( WyRet() ); } } TMP4=tmp4; if((r=tmp4.replace(tmp4.size()-1,1,WyCSeg(tmp4.data()+1,3)))!=Ok) { // protocol not violated, though if(tmp4!=TMP4) { WY_THROW( WyRet() ); // failure postcondition } if(r!=Wym_ELOOP) { WY_THROW(r); // protocol violated } } else { TMP4.resize(TMP4.size()-1); TMP4+=tmp4.cseg(1,3); if(tmp4!=TMP4) { WY_THROW( WyRet() ); } } }; // chk error cseg try { WyStr tt( tmp.cseg(tmp.size()+1) ); WY_THROW( WyRet() ); } catch(const WyStr::Reply& e) { if(e!=Wym_EINVAL) { throw; } // FALLTHOUGH }; try { WyStr tt( tmp.cseg(tmp.size()+1,1) ); WY_THROW(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -