本文整理汇总了C++中std::string::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ string::begin方法的具体用法?C++ string::begin怎么用?C++ string::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::string
的用法示例。
在下文中一共展示了string::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: StringToBool
bool StringToBool(std::string const& str)
{
std::string lowerStr = str;
std::transform(str.begin(), str.end(), lowerStr.begin(), [](char c) { return char(::tolower(c)); });
return lowerStr == "1" || lowerStr == "true" || lowerStr == "yes";
}
示例2: regex_grep
inline unsigned int regex_grep(bool (*foo)(const match_results<std::string::const_iterator>&), const std::string& s,
const regex& e,
match_flag_type flags = match_default)
{
return regex_grep(foo, s.begin(), s.end(), e, flags);
}
示例3: remove
std::string remove(std::string expression, const std::string& toRemove) {
for (std::string::const_iterator str = toRemove.begin(); str != toRemove.end(); str++) {
expression.erase(std::remove(expression.begin(), expression.end(), *str), expression.end());
}
return expression;
}
示例4: runtime_error
Time::Time(const std::string& str, const std::string& fmt)
: _msecs(0)
{
unsigned hours = 0;
unsigned minutes = 0;
unsigned seconds = 0;
unsigned mseconds = 0;
bool am = true;
enum {
state_0,
state_fmt
} state = state_0;
std::string::const_iterator dit = str.begin();
std::string::const_iterator it;
for (it = fmt.begin(); it != fmt.end(); ++it)
{
char ch = *it;
switch (state)
{
case state_0:
if (ch == '%')
state = state_fmt;
else
{
if (dit == str.end() || *dit != ch)
throw std::runtime_error("string <" + str + "> does not match time format <" + fmt + '>');
++dit;
}
break;
case state_fmt:
switch (ch)
{
case 'H':
case 'I':
hours = getUnsigned(dit, str.end(), 2);
break;
case 'M':
minutes = getUnsigned(dit, str.end(), 2);
break;
case 'S':
seconds = getUnsigned(dit, str.end(), 2);
break;
case 'j':
if (dit != str.end() && *dit == '.')
++dit;
mseconds = getMilliseconds(dit, str.end());
break;
case 'J':
case 'K':
if (dit != str.end() && *dit == '.')
{
++dit;
mseconds = getMilliseconds(dit, str.end());
}
break;
case 'k':
mseconds = getMilliseconds(dit, str.end());
break;
case 'p':
if (dit == str.end()
|| dit + 1 == str.end()
|| ((*dit != 'A'
&& *dit != 'a'
&& *dit != 'P'
&& *dit != 'p')
|| (*(dit + 1) != 'M'
&& *(dit + 1) != 'm')))
{
throw std::runtime_error("string <" + str + "> does not match time format <" + fmt + '>');
}
am = (*dit == 'A' || *dit == 'a');
dit += 2;
break;
default:
throw std::runtime_error("invalid time format <" + fmt + '>');
}
state = state_0;
break;
}
}
if (it != fmt.end() || dit != str.end())
throw std::runtime_error("string <" + str + "> does not match time format <" + fmt + '>');
set(am ? hours : hours + 12, minutes, seconds, mseconds);
}
示例5: is_number
bool is_number(const std::string& s)
{
std::string::const_iterator it = s.begin();
while (it != s.end() && (isdigit(*it))) ++it;
return !s.empty() && it == s.end();
}
示例6: ToLowerCase
void Toolbox::ToLowerCase(std::string& s)
{
std::transform(s.begin(), s.end(), s.begin(), tolower);
}
示例7: decode
entry decode(std::string const& str)
{
return bdecode(str.begin(), str.end());
}
示例8: make_tuple
// returns protocol, auth, hostname, port, path
boost::tuple<std::string, std::string, std::string, int, std::string>
parse_url_components(std::string url, error_code& ec)
{
std::string hostname; // hostname only
std::string auth; // user:pass
std::string protocol; // http or https for instance
int port = -1;
std::string::iterator at;
std::string::iterator colon;
std::string::iterator port_pos;
// PARSE URL
std::string::iterator start = url.begin();
// remove white spaces in front of the url
while (start != url.end() && is_space(*start))
++start;
std::string::iterator end
= std::find(url.begin(), url.end(), ':');
protocol.assign(start, end);
if (end == url.end())
{
ec = errors::unsupported_url_protocol;
goto exit;
}
++end;
if (end == url.end() || *end != '/')
{
ec = errors::unsupported_url_protocol;
goto exit;
}
++end;
if (end == url.end() || *end != '/')
{
ec = errors::unsupported_url_protocol;
goto exit;
}
++end;
start = end;
at = std::find(start, url.end(), '@');
colon = std::find(start, url.end(), ':');
end = std::find(start, url.end(), '/');
if (at != url.end()
&& colon != url.end()
&& colon < at
&& at < end)
{
auth.assign(start, at);
start = at;
++start;
}
// this is for IPv6 addresses
if (start != url.end() && *start == '[')
{
port_pos = std::find(start, url.end(), ']');
if (port_pos == url.end())
{
ec = errors::expected_close_bracket_in_address;
goto exit;
}
port_pos = std::find(port_pos, url.end(), ':');
}
else
{
port_pos = std::find(start, url.end(), ':');
}
if (port_pos < end)
{
hostname.assign(start, port_pos);
++port_pos;
for (std::string::iterator i = port_pos; i < end; ++i)
{
if (is_digit(*i)) continue;
ec = errors::invalid_port;
goto exit;
}
port = std::atoi(std::string(port_pos, end).c_str());
}
else
{
hostname.assign(start, end);
}
start = end;
exit:
return boost::make_tuple(protocol, auth, hostname, port
, std::string(start, url.end()));
}
示例9: replaceSymbols
/**
* We don't want to pronounce punctuation
*/
void ALSpeech::replaceSymbols(std::string& text)
{
replace(text.begin(), text.end(), '_', ' ');
replace(text.begin(), text.end(), ':', ' ');
replace(text.begin(), text.end(), '-', ' ');
}
示例10:
/// c'tor
Parser(std::string input_data) :
data_(input_data),
state_(data_.begin()),
error_state_(data_.begin())
{}
示例11: Lux_OGL_DrawText
void Lux_OGL_DrawText( std::string text, LuxRect dest_rect, Effects image_effects, bool allow_custom )
{
//glPushMatrix();
int32_t z = dest_rect.z/1000;
glColor4ub(image_effects.colour.r, image_effects.colour.g, image_effects.colour.b, image_effects.colour.a);
uint16_t x = dest_rect.x;
std::string::iterator object;
for ( object = text.begin(); object != text.end(); object++ )
{
uint32_t cchar = *object;
/*
194-223 2 bytes
224-239 3 bytes
240-244 4 bytes
*/
if (cchar == '\n' || cchar == '\r')
{
dest_rect.y += ( oglGraphics_customtext && allow_custom ? oglGraphics_customtext_height + 2 : 10);
x = dest_rect.x;
}
else if ( cchar <= 32 )
{
x += 7;
}
else if ( cchar <= 128 )
{
if ( oglGraphics_customtext && allow_custom )
{
x += Lux_OGL_DrawChar((int32_t)cchar, x, dest_rect.y, z, image_effects);
}
else
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, font[cchar-32]);
glBegin(GL_QUADS);
glTexCoord2f( 0.0, 0.0 );
Lux_OGL_ColouredVertex3(image_effects.colour, image_effects.colour2, image_effects.style, 1, x, dest_rect.y, z);
glTexCoord2f( 1.0, 0.0 );
Lux_OGL_ColouredVertex3(image_effects.colour, image_effects.colour2, image_effects.style, 2, x + 8, dest_rect.y, z);
glTexCoord2f( 1.0, 1.0 );
Lux_OGL_ColouredVertex3(image_effects.colour, image_effects.colour2, image_effects.style, 3, x + 8, dest_rect.y + 8, z);
glTexCoord2f( 0.0, 1.0 );
Lux_OGL_ColouredVertex3(image_effects.colour, image_effects.colour2, image_effects.style, 4, x, dest_rect.y + 8, z );
glEnd();
glDisable(GL_TEXTURE_2D);
x += 7;
}
}
else
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, font['?'-32]);
glBegin(GL_QUADS);
glTexCoord2f( 0.0, 0.0 );
Lux_OGL_ColouredVertex3(image_effects.colour, image_effects.colour2, image_effects.style, 1, x, dest_rect.y, z);
glTexCoord2f( 1.0, 0.0 );
Lux_OGL_ColouredVertex3(image_effects.colour, image_effects.colour2, image_effects.style, 2, x + 8, dest_rect.y, z);
glTexCoord2f( 1.0, 1.0 );
Lux_OGL_ColouredVertex3(image_effects.colour, image_effects.colour2, image_effects.style, 3, x + 8, dest_rect.y + 8, z);
glTexCoord2f( 0.0, 1.0 );
Lux_OGL_ColouredVertex3(image_effects.colour, image_effects.colour2, image_effects.style, 4, x, dest_rect.y + 8, z );
glEnd();
glDisable(GL_TEXTURE_2D);
x += 7;
if ( cchar < 224 )
object++;
else if ( cchar < 240 )
object +=2;
else if ( cchar < 245 )
object +=3;
}
}
glColor4f(1.0,1.0,1.0,1.0);
//glPopMatrix();
}
示例12: append
void DateTimeFormatter::append(std::string& str, const DateTime& dateTime, const std::string& fmt, int timeZoneDifferential)
{
std::string::const_iterator it = fmt.begin();
std::string::const_iterator end = fmt.end();
while (it != end)
{
if (*it == '%')
{
if (++it != end)
{
switch (*it)
{
case 'w':
str.append(DateTimeFormat::WEEKDAY_NAMES[dateTime.dayOfWeek()], 0, 3);
break;
case 'W':
str.append(DateTimeFormat::WEEKDAY_NAMES[dateTime.dayOfWeek()]);
break;
case 'b':
str.append(DateTimeFormat::MONTH_NAMES[dateTime.month() - 1], 0, 3);
break;
case 'B':
str.append(DateTimeFormat::MONTH_NAMES[dateTime.month() - 1]);
break;
case 'd':
NumberFormatter::append0(str, dateTime.day(), 2);
break;
case 'e':
NumberFormatter::append(str, dateTime.day());
break;
case 'f':
NumberFormatter::append(str, dateTime.day(), 2);
break;
case 'm':
NumberFormatter::append0(str, dateTime.month(), 2);
break;
case 'n':
NumberFormatter::append(str, dateTime.month());
break;
case 'o':
NumberFormatter::append(str, dateTime.month(), 2);
break;
case 'y':
NumberFormatter::append0(str, dateTime.year() % 100, 2);
break;
case 'Y':
NumberFormatter::append0(str, dateTime.year(), 4);
break;
case 'H':
NumberFormatter::append0(str, dateTime.hour(), 2);
break;
case 'h':
NumberFormatter::append0(str, dateTime.hourAMPM(), 2);
break;
case 'a':
str.append(dateTime.isAM() ? "am" : "pm");
break;
case 'A':
str.append(dateTime.isAM() ? "AM" : "PM");
break;
case 'M':
NumberFormatter::append0(str, dateTime.minute(), 2);
break;
case 'S':
NumberFormatter::append0(str, dateTime.second(), 2);
break;
case 's':
NumberFormatter::append0(str, dateTime.second(), 2);
str += '.';
NumberFormatter::append0(str, dateTime.millisecond()*1000 + dateTime.microsecond(), 6);
break;
case 'i':
NumberFormatter::append0(str, dateTime.millisecond(), 3);
break;
case 'c':
NumberFormatter::append(str, dateTime.millisecond()/100);
break;
case 'F':
NumberFormatter::append0(str, dateTime.millisecond()*1000 + dateTime.microsecond(), 6);
break;
case 'z':
tzdISO(str, timeZoneDifferential);
break;
case 'Z':
tzdRFC(str, timeZoneDifferential);
break;
default:
str += *it;
}
++it;
}
}
else str += *it++;
}
}
示例13: binary
explicit binary(const std::string& s) : std::vector<value_type>(s.begin(), s.end()) {}
示例14: format
std::string RegexSMatch::format(const std::string& s) const
{
enum state_type
{
state_0,
state_esc,
state_var0,
state_var1,
state_1
} state;
state = state_0;
std::string ret;
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it)
{
char ch = *it;
switch (state)
{
case state_0:
if (ch == '$')
state = state_var0;
else if (ch == '\\')
state = state_esc;
break;
case state_esc:
ret += ch;
state = state_1;
break;
case state_var0:
if (std::isdigit(ch))
{
ret = std::string(s.begin(), it - 1);
regoff_t s = matchbuf[ch - '0'].rm_so;
regoff_t e = matchbuf[ch - '0'].rm_eo;
if (s >= 0 && e >= 0)
ret.append(str, s, e-s);
state = state_1;
}
else
state = state_0;
break;
case state_1:
if (ch == '$')
state = state_var1;
else if (state == '\\')
state = state_esc;
else
ret += ch;
break;
case state_var1:
if (std::isdigit(ch))
{
regoff_t s = matchbuf[ch - '0'].rm_so;
regoff_t e = matchbuf[ch - '0'].rm_eo;
if (s >= 0 && e >= 0)
ret.append(str, s, e-s);
state = state_1;
}
else if (ch == '$')
ret += '$';
else
{
ret += '$';
ret += ch;
}
break;
}
}
switch (state)
{
case state_0:
case state_var0:
return s;
case state_esc:
return ret + '\\';
case state_var1:
return ret + '$';
case state_1:
return ret;
}
return ret;
}
示例15: writeBytes
std::size_t ByteBuffer::writeBytes(const std::string& buffer)
{
_buffer.reserve(_buffer.size() + buffer.size());
_buffer.insert(_buffer.end(), buffer.begin(), buffer.end());
return buffer.size();
}