📄 wystr.cpp
字号:
/* Copyright is licensed by GNU LGPL. by I.J.Wang 2004*/#define WYLIB_SOURCE#include "wystr.h"#include "wy__hstr.h"#include <limits>const char WyStr::class_name[]="WyStr";WyStr::size_type WyStr::max_capacity(void) WY__TSPC(){ return Wy__HStr::max_capacity(); };WyStr::size_type WyStr::min_capacity(void) WY__TSPC(){ return Wy__HStr::min_capacity();};class WyStr::_Assertion { public: _Assertion() { if(WyStr::max_capacity()>static_cast<WyStr::size_type>( (std::numeric_limits<ssize_t>::max()/2-1))) { WY_TERMINATE(""); }; if(NULL!=(void*)0) { WY_TERMINATE(""); }; };} static const wy__do_not_use_me__;WyStr::WyStr() WY__TSPC(Reply)try : _imp(Wy__HStr::alloc()){}catch(const Wy__HStr::Reply& e) { WY_THROW(Reply(e));};WyStr::WyStr(const WyStr& str) WY__TSPC(Reply)try : _imp(Wy__HStr::alloc(*str._imp)){}catch(const Wy__HStr::Reply& e) { WY_THROW(Reply(e));};WyStr::WyStr(WyStr& str, Wy::ByMove_t) WY__TSPC() : _imp(str._imp){ str._imp=NULL;};WyStr::WyStr(const WyCSeg& cs) WY__TSPC(Reply)try : _imp(Wy__HStr::alloc(cs)){}catch(const Wy__HStr::Reply& e) { WY_THROW(Reply(e));};WyStr::WyStr(size_type num, WyStr::value_type ch) WY__TSPC(Reply)try : _imp(Wy__HStr::alloc(num,ch)){}catch(const Wy__HStr::Reply& e) { WY_THROW(Reply(e));};WyStr::WyStr(Wy__HStr* hstr) WY__TSPC() : _imp(hstr) {};//------------------------WyStr::~WyStr() WY__TSPC(){ Wy__HStr::free(_imp); _imp=NULL;};bool WyStr::is_default(void) const WY__TSPC(){ return(_imp->size()==0);};void WyStr::reset(void) WY__TSPC(){ _imp->set_string();};WyRet WyStr::reset(const WyStr& str) WY__TSPC(){ const WyRet r(_imp->set_string(*str._imp)); if(r==Ok) { return(Ok); } if(r!=Wym_EFBIG) { WY_RETURN(r); } Wy__HStr* hptr(NULL); try { hptr= Wy__HStr::alloc(*str._imp); } catch(const Wy__HStr::Reply& e) { WY_RETURN( WyRet(e) ); }; Wy__HStr::free(_imp); _imp=hptr; return(Ok);};WyRet WyStr::reset(const WyCSeg& cs) WY__TSPC(){ const WyRet r(_imp->set_string(cs)); if(r==Ok) { return(Ok); } if(r!=Wym_EFBIG) { WY_RETURN(r); } Wy__HStr* hptr(NULL); try { hptr= Wy__HStr::alloc(cs); } catch(const Wy__HStr::Reply& e) { WY_RETURN( WyRet(e) ); }; Wy__HStr::free(_imp); _imp=hptr; return(Ok);};WyRet WyStr::reset(size_type cnum, WyStr::value_type ch) WY__TSPC(){ const WyRet r(_imp->set_string(cnum,ch)); if(r==Ok) { return(Ok); } if(r!=Wym_EFBIG) { WY_RETURN(r); } Wy__HStr* hptr(NULL); try { hptr= Wy__HStr::alloc(cnum,ch); } catch(const Wy__HStr::Reply& e) { WY_RETURN( WyRet(e) ); }; Wy__HStr::free(_imp); _imp=hptr; return(Ok);};//WyStr::size_type WyStr::size(void) const WY__TSPC(){ return _imp->size();};const WyStr::value_type* WyStr::begin(void) const WY__TSPC(){ return _imp->_begin();};const WyStr::value_type* WyStr::end(void) const WY__TSPC(){ return _imp->_end();};const WyStr::value_type& WyStr::operator [](size_type pos) const WY__TSPC(){ return _imp->_at(pos);};WyStr::value_type& WyStr::operator [](size_type pos) WY__TSPC(){ return _imp->_at(pos);};const WyStr::value_type& WyStr::at(size_type pos) const WY__TSPC(Reply){ if(pos>=_imp->size()) { WY_THROW( Reply(Wym_EINVAL) ); } return _imp->_at(pos);};WyStr::value_type& WyStr::at(size_type pos) WY__TSPC(Reply){ if(pos>=_imp->size()) { WY_THROW( Reply(Wym_EINVAL) ); } return _imp->_at(pos);};const WyStr::value_type* WyStr::data(void) const WY__TSPC(){ return _imp->data();};const WyStr::value_type* WyStr::c_str(void) const WY__TSPC(){ return _imp->c_str();};bool WyStr::operator ==(const WyStr& rhs) const WY__TSPC(){ return this->cseg()==rhs.cseg();};bool WyStr::operator !=(const WyStr& rhs) const WY__TSPC(){ return this->cseg()!=rhs.cseg();};bool WyStr::operator ==(const WyCSeg& rhs) const WY__TSPC(){ return this->cseg()==rhs;};bool WyStr::operator !=(const WyCSeg& rhs) const WY__TSPC(){ return this->cseg()!=rhs;};bool WyStr::operator ==(const char* rhs) const WY__TSPC(WyCSeg::Reply){ return this->cseg()==rhs;};bool WyStr::operator !=(const char* rhs) const WY__TSPC(WyCSeg::Reply){ return this->cseg()!=rhs;};WyRet WyStr::append(const WyStr& str) WY__TSPC(){ const WyRet r(_imp->append(*str._imp)); if(r==Ok) { return(Ok); } if(r!=Wym_EFBIG) { WY_RETURN(r); } // realloc only for EFBIG Wy__HStr* hptr(NULL); try { hptr= Wy__HStr::alloc(_imp->cseg(),str._imp->cseg()); } catch(const Wy__HStr::Reply& e) { WY_RETURN( WyRet(e) ); }; Wy__HStr::free(_imp); _imp=hptr; return(Ok);};WyRet WyStr::append(value_type ch) WY__TSPC(){ const WyRet r(_imp->append(ch)); if(r==Ok) { return(Ok); } if(r!=Wym_EFBIG) { WY_RETURN(r); } Wy__HStr* hptr(NULL); try { hptr= Wy__HStr::alloc(_imp->cseg(),ch); } catch(const Wy__HStr::Reply& e) { WY_RETURN( WyRet(e) ); }; Wy__HStr::free(_imp); _imp=hptr; return(Ok);};WyRet WyStr::append(WyStr::size_type cnum,WyStr::value_type ch) WY__TSPC(){ const WyRet r(_imp->append(cnum,ch)); if(r==Ok) { return(Ok); } if(r!=Wym_EFBIG) { WY_RETURN(r); } Wy__HStr* hptr(NULL); try { hptr= Wy__HStr::alloc(_imp->cseg(),cnum,ch); } catch(const Wy__HStr::Reply& e) { WY_RETURN( WyRet(e) ); }; Wy__HStr::free(_imp); _imp=hptr; return(Ok);};WyRet WyStr::append(const WyCSeg& cs) WY__TSPC(){ const WyRet r(_imp->append(cs)); if(r==Ok) { return(Ok); } if(r!=Wym_EFBIG) { WY_RETURN(r); } Wy__HStr* hptr(NULL); try { hptr= Wy__HStr::alloc(_imp->cseg(),cs); } catch(const Wy__HStr::Reply& e) { WY_RETURN( WyRet(e) ); }; Wy__HStr::free(_imp); _imp=hptr; return(Ok);};const WyStr& WyStr::operator +=(const WyStr& str) WY__TSPC(Reply){ const WyRet r(_imp->append(str.cseg())); if(r==Ok) { return(*this); } if(r!=Wym_EFBIG) { WY_THROW( Reply(r) ); } Wy__HStr* hptr(NULL); try { hptr= Wy__HStr::alloc(_imp->cseg(),str.cseg()); } catch(const Wy__HStr::Reply& e) { WY_THROW( Reply(e) ); }; Wy__HStr::free(_imp); _imp=hptr; return(*this);};const WyStr& WyStr::operator +=(const WyCSeg& cs) WY__TSPC(Reply){ const WyRet r(_imp->append(cs)); if(r==Ok) { return(*this); } if(r!=Wym_EFBIG) { WY_THROW( Reply(r) ); } Wy__HStr* hptr(NULL); try { hptr= Wy__HStr::alloc(_imp->cseg(),cs); } catch(const Wy__HStr::Reply& e) { WY_THROW( Reply(e) ); }; Wy__HStr::free(_imp); _imp=hptr; return(*this);};const WyStr& WyStr::operator +=(value_type ch) WY__TSPC(Reply){ const WyRet r(_imp->append(ch)); if(r==Ok) { return(*this); } if(r!=Wym_EFBIG) { WY_THROW( Reply(r) ); } Wy__HStr* hptr(NULL); try { hptr= Wy__HStr::alloc(_imp->cseg(),ch); } catch(const Wy__HStr::Reply& e) { WY_THROW( Reply(e) ); }; Wy__HStr::free(_imp); _imp=hptr; return(*this);};WyCSeg WyStr::cseg(void) const WY__TSPC(){ return _imp->cseg();};WyCSeg WyStr::cseg(size_type idx) const WY__TSPC(Reply)try { return _imp->cseg(idx);}catch(const Wy__HStr::Reply& e) { WY_THROW( Reply(e) );};WyCSeg WyStr::cseg(size_type idx, size_type num) const WY__TSPC(Reply)try { return _imp->cseg(idx,num);}catch(const Wy__HStr::Reply& e) { WY_THROW( Reply(e) );};bool WyStr::find(size_type* res,value_type ch) const WY__TSPC(){ return _imp->find(res,ch);};bool WyStr::find(size_type* res,const WyCSeg& cseg) const WY__TSPC(){ return _imp->find(res,0,cseg);};bool WyStr::find(size_type* res,size_type idx,value_type ch) const WY__TSPC(){ return _imp->find(res,idx,ch);};bool WyStr::find(size_type* res,size_type idx,const WyCSeg& cseg) const WY__TSPC(){ return _imp->find(res,idx,cseg);};bool WyStr::rfind(size_type* res,value_type ch) const WY__TSPC(){ return _imp->rfind(res,ch);};bool WyStr::rfind(size_type* res,const WyCSeg& cseg) const WY__TSPC(){ return _imp->rfind(res,cseg);};bool WyStr::rfind(size_type* res,size_type idx,value_type ch) const WY__TSPC(){ return _imp->rfind(res,idx,ch);};bool WyStr::rfind(size_type* res,size_type idx,const WyCSeg& cseg) const WY__TSPC(){ return _imp->rfind(res,idx,cseg);};bool WyStr::_find_in(size_type* res,size_type idx,const WyCSeg& cs) const WY__TSPC(){ return _imp->_find_in(res,idx,cs);};bool WyStr::find_not(size_type* res,size_type idx,value_type ch) const WY__TSPC(){ return _imp->_find_not(res,idx,ch);};bool WyStr::_find_not(size_type* res,size_type idx,const WyCSeg& cs) const WY__TSPC(){ return _imp->_find_not(res,idx,cs);};bool WyStr::_rfind_in(size_type* res,size_type idx,const WyCSeg& cs) const WY__TSPC(){ return _imp->_rfind_in(res,idx,cs);};bool WyStr::rfind_not(size_type* res,size_type idx,value_type ch) const WY__TSPC(){ return _imp->_rfind_not(res,idx,ch);};bool WyStr::_rfind_not(size_type* res,size_type idx,const WyCSeg& cs) const WY__TSPC(){ return _imp->_rfind_not(res,idx,cs);};const WyStr& WyStr::operator =(const WyStr& rhs) WY__TSPC(Reply){ const WyRet r(_imp->set_string(*rhs._imp)); if(r==Ok) { return(*this); } if(r!=Wym_EFBIG) { WY_THROW( Reply(r) ); } Wy__HStr* hptr(NULL); try { hptr= Wy__HStr::alloc(*rhs._imp); } catch(const Wy__HStr::Reply& e) { WY_THROW( Reply(e) ); }; Wy__HStr::free(_imp); _imp=hptr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -