本文整理汇总了C++中str::size方法的典型用法代码示例。如果您正苦于以下问题:C++ str::size方法的具体用法?C++ str::size怎么用?C++ str::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类str
的用法示例。
在下文中一共展示了str::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: extract_delimited_text
str::size_type extract_delimited_text(const str& in, const str& d1, const str& d2, str& out, size_t pos)
{
if(pos == str::npos)
return pos;
size_t end = pos;
if((pos = in.find(d1, pos)) != str::npos)
if((end = in.find(d2, (pos = pos + d1.size()))) != str::npos)
{
out = in.substr(pos, end - pos);
return end + d2.size();
}
return str::npos;
}
示例2: rcon
bool RConImpl::rcon(const str& host, siz port, const str& cmd, str& reply) const
{
str_vec packets;
if(!aocom(cmd, packets, host, port, TIMEOUT))
return false;
const str header = "\xFF\xFF\xFF\xFFprint\x0A";
if(packets.empty())
{
log("Empty response.");
return false;
}
reply.clear();
for(const str& packet: packets)
{
if(packet.find(header) != 0)
{
log("Unrecognised response.");
return false;
}
reply.append(packet.substr(header.size()));
}
return true;
}
示例3: strDecToStrBin
str strDecToStrBin(str dec){
str bin="";
int m=dec.size();
int i=0;
while(dec.size()){
//printf("DEC %s\n", dec.c_str());
char l=dec.at(dec.size()-1);
if(l=='0' || l=='2' || l=='4' || l=='6' || l=='8'){ //parzysta
bin='0'+bin;
}else{
bin='1'+bin;
}
dec=divideByTwo(dec);
if(dec.at(0)=='0'){dec.erase(0,1);}
}
return bin;
}
示例4: const
str operator+(str const &self, char const(&other)[N])
{
std::string s;
s.reserve(self.size() + N);
s += self.get_data();
s += other;
return {std::move(s)};
}
示例5: ch
uni ch(str in)
{
int a = 0, b = 0, c = 0, d = 0;
int uk = 0;
while (uk < in.size() && in[uk]!='.')
a = a * 10 +(int)(in[uk] - '0'), uk++;
uk++;
while (uk < in.size() && in[uk]!='.')
b = b * 10 +(int)(in[uk] - '0'), uk++;
uk++;
while (uk < in.size() && in[uk]!='.')
c = c * 10 +(int)(in[uk] - '0'), uk++;
uk++;
while (uk < in.size() && in[uk]!='.')
d = d * 10 +(int)(in[uk] - '0'), uk++;
unsigned int rrr = d + c * 256 + b * 256*256 + a * 256*256*256;
return rrr;
}
示例6: binaryNumberToCode
void binaryNumberToCode(str bin){
vec<str> v;
addCodeLine("ZERO");
//printf("ZMIANA\n");
while(bin!="0"){
//printf("BIN %s\n", bin.c_str());
char l=bin.at(bin.size()-1);
if(l=='1'){
v.push_back("INC");
bin.at(bin.size()-1)='0';
}else if(l=='0'){
v.push_back("SHL");
bin.erase(bin.size()-1, 1);
}
}
for(int i=v.size()-1; i>=0; i--){
addCodeLine(v.at(i));
}
}
示例7: get_filename_from_pathname
str get_filename_from_pathname(const str& pathname)
{
auto pos = pathname.find_last_of('/');
if(pos == pathname.size() - 1)
throw std::runtime_error("bad pathname: " + pathname);
else if(pos != str::npos)
return pathname.substr(pos + 1);
return pathname;
}
示例8: fwrite
uint fwrite(const str& s, const path& p, const bool append, const bool binary) {
FILE* fp;
uint size=s.size();
const char* buf=s.tocstr();
fp=fopen(p.tocstr(), append?(binary?"ab":"at"):(binary?"wb":"wt"));
assert(fp);//File error: Could not open file for write
size=fwrite(buf, 1, size, fp);
fclose(fp);
return size;
}
示例9: divideByTwo
str divideByTwo(str dec){
int rem=0;
int m=dec.size();
for(int i=0; i<m; i++){
int a=dec.at(i)-48; //cyfra
dec.at(i)=(rem+a)/2+48;
if(a%2){rem=10;}else{rem=0;}
}
//printf("DZIEL %s\n", dec.c_str());
return dec;
}
示例10: _addressBufferToString
void network_socket::_addressBufferToString(str& s) const
{
size_type i;
s.resize(20);
inet_ntop(AF_INET,&reinterpret_cast<const sockaddr_in*>(_addrbuf)->sin_addr,&s[0],s.size());
i = 0;
while (i < s.size()) {
if (s[i] == 0)
break;
++i;
}
s.resize(i);
}
示例11: rfind
/*************************************************
S.rfind(sub [,start [,end]]) -> int
Search from right to left.
Return the highest index in S where substring sub is found,
such that sub is contained within s[start:end]. Optional
arguments start and end are interpreted as in slice notation.
Return -1 on failure.
*************************************************/
int str::rfind(const str& sub, int start, int end) const {
uint l=size();
if (start<0) start+=l;
if (end<=0) end+=l;
start=l-start;
end=l-end;
assert(start>0);
assert(end>=0);
criterator a=s.rbegin()+end, b=s.rbegin()+start;
if (a>=b) return -1;
criterator c=std::search(a, b, sub.rbegin(), sub.rend());
return (c==b)?-1:(b-c)-sub.size();
}
示例12: SetText
void MenuItem::SetText(const str& s)
{
if (s.size()==0)
// we cannot have a string with no size
_text = "Item";
else
_text = s; // store text in our own buffer in anticipation that the item is going to be added to another item or bar
if (_parentItem!=0) // (I can use either _parentItem or _parentBar since they both refer to the same memory address)
{// the item has a parent, so we need to call an API routine to change the text
HMENU hTopLevel; // not the absolute top level, but a level above this menu
hTopLevel = (_parentState ? _parentItem->_hSubMenu : _parentBar->GetMenuHandle());
// modify text only
ModifyMenu(hTopLevel,*this,MF_BYCOMMAND | MF_STRING,*this,&_text[0]);
}
// if the item doesn't have a parent, then this item's text will be added when the item is added to
}
示例13: isNumeric
bool isNumeric(const str& token)
{
if(token == "")
return false;
for(uint i=0; i<token.length(); i++)
{
const char num = token.at(i);
if(i == 0 && Util::toString(num) == kSubtract() && token.size() > 1) //token.size > 1 because "-" is not a number
continue;
if(isdigit(num) == false && Util::toString(num) != kDot())
return false;
}
return true;
}
示例14: aocom
/**
* IPv4 IPv6 agnostic OOB (out Of Band) comms
* @param cmd
* @param packets Returned packets
* @param host Host to connect to
* @param port Port to connect on
* @param wait Timeout duration in milliseconds
* @return false if failed to connect/send or receive else true
*/
bool aocom(const str& cmd, str_vec& packets, const str& host, int port
, siz wait = TIMEOUT)
{
addrinfo hints;
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; // AF_INET or AF_INET6
hints.ai_socktype = SOCK_DGRAM;
addrinfo* res;
if(int status = getaddrinfo(host.c_str(), std::to_string(port).c_str(), &hints, &res) != 0)
{
log(gai_strerror(status));
return false;
}
st_time_point timeout = st_clk::now() + std::chrono::milliseconds(wait);
// try to connect to each
int cs;
addrinfo* p;
for(p = res; p; p = p->ai_next)
{
if((cs = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1)
continue;
if(!connect(cs, p->ai_addr, p->ai_addrlen))
break;
::close(cs);
}
freeaddrinfo(res);
if(!p)
{
log("aocom: failed to connect: " << host << ":" << port);
return false;
}
// cs good
const str msg = "\xFF\xFF\xFF\xFF" + cmd;
int n = 0;
if((n = send(cs, msg.c_str(), msg.size(), 0)) < 0 || n < (int)msg.size())
{
log("cs send: " << strerror(errno));
return false;
}
packets.clear();
char buf[2048];
n = sizeof(buf);
while(n == sizeof(buf))
{
while((n = recv(cs, buf, sizeof(buf), MSG_DONTWAIT)) == -1 && (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR))
{
if(st_clk::now() > timeout)
{
log("socket timed out connecting to: " << host << ":" << port);
return false;
}
// std::this_thread::yield();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
if(n < 0)
log("cs recv: " << strerror(errno));
if(n > 0)
packets.push_back(str(buf, n));
}
close(cs);
return true;
}
示例15:
bool operator!=(char c, str const &s)
{
return s.size() != 1 or s[0] != c;
}