本文整理汇总了C++中std::string::cbegin方法的典型用法代码示例。如果您正苦于以下问题:C++ string::cbegin方法的具体用法?C++ string::cbegin怎么用?C++ string::cbegin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::string
的用法示例。
在下文中一共展示了string::cbegin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Tokenize
std::vector<std::string> Tokenize(const std::string& source, const std::string& delimiters, bool removeDelim /*= true*/)
{
auto head = source.cbegin();
std::vector<std::string> tokens;
for (auto tail = source.cbegin(); tail != source.cend(); ++tail)
{
for (auto it = delimiters.cbegin(); it != delimiters.cend(); ++it)
{
const auto& delimiter = *it;
if ((*tail == delimiter))
{
if (head != tail)
tokens.push_back(std::string(head, tail));
if (removeDelim)
head = tail + 1;
else
head = tail;
}
}
}
if (head != source.cend())
tokens.push_back(std::string(head, source.cend()));
return tokens;
}
示例2: CompareLowerCase
bool CompareLowerCase(std::string const& l, std::string const& r)
{
return l.size() == r.size()
&& equal(l.cbegin(), l.cend(), r.cbegin(),
[](std::string::value_type l1, std::string::value_type r1)
{ return toupper(l1) == toupper(r1); });
}
示例3: getCodeTagAttributes
inline void Parser::getCodeTagAttributes( const std::string &text, std::string &data )
{
auto find_iter = std::find( text.cbegin(), text.cend(), ']' );
if( find_iter != text.cend() && find_iter != text.crend().base() ) {
data = std::string( text.cbegin(), find_iter + 1 );
}
}
示例4: Split
// split a string into multiple chunks
void ClientConsole::Split( const std::string &line, std::vector<std::string> &lines ) {
const uint16_t fontSize = static_cast<uint16_t>( con_fontSize->GetInt32() );
const real32_t lineWidth = view->width;
ptrdiff_t startOffset = 0u;
real32_t accumWidth = 0.0f;
const char *p = line.c_str();
for ( char c = *p; c != '\0'; c = *p++ ) {
if ( c == '\t' ) {
//FIXME: actually handle tab stops properly
accumWidth += font->GetGlyphWidth( ' ', fontSize );
}
else {
accumWidth += font->GetGlyphWidth( c, fontSize );
}
if ( accumWidth >= lineWidth ) {
// splice and reset counters
const ptrdiff_t endOffset = p - line.c_str();
lines.push_back( std::string( line.cbegin() + startOffset, line.cbegin() + endOffset ) );
startOffset = endOffset;
accumWidth = 0.0f;
}
}
// push the remainder of the line
lines.push_back( std::string( line.cbegin() + startOffset, line.cend() ) );
}
示例5: open
bool Module::open(const std::string &libPath)
{
if (is_open() )
{
close();
}
#ifdef WIN32
const size_t pos_slash = libPath.rfind('\\');
const size_t pos_slash_back = libPath.rfind('/');
size_t pos = std::string::npos;
if (pos_slash != std::string::npos && pos_slash > pos_slash_back)
{
pos = pos_slash;
}
else if (pos_slash_back != std::string::npos)
{
pos = pos_slash_back;
}
DLL_DIRECTORY_COOKIE cookie = nullptr;
if (std::string::npos != pos)
{
std::wstring directory(libPath.cbegin(), libPath.cbegin() + pos + 1);
cookie = ::AddDllDirectory(directory.data() );
}
#ifdef UNICODE
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
const std::wstring lib_path = converter.from_bytes(libPath);
#else
const std::string &lib_path = libPath;
#endif
lib_handle = ::LoadLibraryEx(lib_path.c_str(), 0, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
if (cookie)
{
::RemoveDllDirectory(cookie);
}
#elif POSIX
lib_handle = ::dlopen(libPath.c_str(), RTLD_NOW | RTLD_LOCAL);
#else
#error "Undefine platform"
#endif
if (nullptr == lib_handle)
{
#ifdef POSIX
std::cout << ::dlerror() << std::endl;
#endif
return false;
}
return true;
}
示例6: run
void run(const size_t messageCount){
const size_t stringSize = 25;
assert(stringSize <= TestClient::bufferSize);
for(size_t i = 0; i < messageCount; ++i){
const std::string currentString = TestClient::randomString(stringSize);
std::copy(currentString.cbegin(), currentString.cend(), this->buffer.get());
const ssize_t sendRes = send(this->serverSocketDescriptor, this->buffer.get(), stringSize, 0);
if(sendRes == -1){
throw std::runtime_error(std::string("send error: ") + strerror(errno));
}
std::cout << "Sent string: '" << currentString << "'" << std::endl;
const ssize_t recvRes = recv(this->serverSocketDescriptor, this->buffer.get(), TestClient::bufferSize, 0);
if(recvRes == -1){
throw std::runtime_error(std::string("recv error: ") + strerror(errno));
}
std::cout << "Recieved string: '";
for(ssize_t pos = 0; pos < recvRes; ++pos){
std::cout << this->buffer[pos];
}
std::cout << "'" << std::endl;
const bool isEqual = std::equal(currentString.cbegin(), currentString.cend(), this->buffer.get());
if(isEqual == false){
throw std::runtime_error("reply is not equal");
}
}
}
示例7:
/**! ctor from a line **/
Sam (const std::string& line)
{
std::string::const_iterator iter1 {line.cbegin ()}, iter2 {line.cbegin ()};
while (*++iter2 != '\t');
QNAME = std::string {iter1, iter2};
iter1 = ++iter2;
while (*++iter2 != '\t');
FLAG = std::bitset<SAM_FLAG::FLAG_SIZE> {std::stoul (std::string {iter1, iter2})};
iter1 = ++iter2;
while (*++iter2 != '\t');
RNAME = std::string {iter1, iter2};
iter1 = ++iter2;
while (*++iter2 != '\t');
POS = std::stoul (std::string {iter1, iter2});
iter1 = ++iter2;
while (*++iter2 != '\t');
MAPQ = std::stoi (std::string {iter1, iter2});
iter1 = ++iter2;
while (*++iter2 != '\t');
CIGAR = std::string {iter1, iter2};
iter1 = ++iter2;
while (*++iter2 != '\t');
RNEXT = std::string {iter1, iter2};
iter1 = ++iter2;
while (*++iter2 != '\t');
PNEXT = std::stoul (std::string {iter1, iter2});
iter1 = ++iter2;
while (*++iter2 != '\t');
TLEN = std::stol (std::string {iter1, iter2});
iter1 = ++iter2;
while (*++iter2 != '\t');
SEQ = std::string {iter1, iter2};
iter1 = ++iter2;
while (*++iter2 != '\t');
QUAL = std::string {iter1, iter2};
std::string Tag, Value;
while (iter2 != line.cend ())
{
iter1 = ++iter2;
iter2 += 2;
Tag = std::string {iter1, iter2};
iter1 += 5;
while ( (*iter2 != '\t') && (iter2 != line.cend()))
++iter2;
Value = std::string {iter1, iter2};
OPTIONAL_FIELDS.insert (std::make_pair (Tag, Value));
}
}
示例8: compute
size_t compute(const std::string& sequence_1, const std::string& sequence_2)
{
if (sequence_1.size() != sequence_2.size())
{
throw std::domain_error("Sequences are not of same length");
}
return std::inner_product(sequence_1.cbegin(), sequence_1.cend(), sequence_2.cbegin(), 0,
std::plus<size_t>(), std::not_equal_to<char>());
}
示例9: trim_start
std::string trim_start(const std::string& str, char trimChar)
{
if (str.length() == 0)
return str;
auto it = str.cbegin();
while(it++ != str.cbegin() && *it == trimChar) {}
return std::string(it - 1, str.cend());
}
示例10: trim_end
std::string trim_end(const std::string& str, char trimChar)
{
if (str.length() == 0)
return str;
auto it = str.cend();
while(--it != str.cbegin() && *it == trimChar) {}
return std::string(str.cbegin(), it + 1);
}
示例11: write_to
point string_stencil::write_to(frame& frame_, const std::string& str) const {
auto dim =frame_.get_dimension();
auto rows =required_y(dim.x, str.size());
if(rows <= dim.y) {
frame_.write({0, 0}, str);
return { dim.x, rows };
}
else {
frame_.write({0, 0}, str.cbegin(), str.cbegin()+dim.y*dim.x-1);
return dim;
}
}
示例12: matchre
boost::optional<std::string> matchre(std::string pattern)
{
boost::optional<std::string> maybe_token;
/* FIXME: Not thread-safe. */
static std::unordered_map<std::string, std::regex *>_lookup;
std::regex *rep;
if (_lookup.count(pattern) == 0)
{
rep = new std::regex(pattern);
_lookup[pattern] = rep;
}
else
rep = _lookup[pattern];
std::regex& re = *rep;
/* Multiline is the default. */
std::regex_constants::match_flag_type flags = std::regex_constants::match_continuous;
if (_pos > 0)
flags |= std::regex_constants::match_prev_avail;
#ifdef BOOST_REGEX
flags |= std::regex_constants::match_not_dot_newline;
#endif
std::smatch match;
int cnt = std::regex_search(_text.cbegin() + _pos, _text.cend(), match, re, flags);
if (cnt > 0)
{
maybe_token = match[0];
_pos += match[0].length();
}
return maybe_token;
}
示例13: match
bool match(const std::string& token)
{
int len = token.length();
if (len == 0)
return true;
bool eq = (_text.compare(_pos, len, token) == 0);
if (!eq)
return false;
if (_nameguard)
{
bool token_first_is_alpha = is_name_char(_pos);
bool follow_is_alpha = is_name_char(_pos + len);
if (token_first_is_alpha && follow_is_alpha)
{
/* Check if the token is alphanumeric. */
auto begin = _text.cbegin() + _pos;
auto end = begin + len;
bool token_is_alnum = find_if(begin, end,
[](char ch) { return !std::isalnum(ch); }) == end;
if (token_is_alnum)
return false;
}
}
move(len);
return true;
}
示例14: add
void add(const std::string& str)
{
auto strSize = (uint16_t)str.size();
buffer.reserve(2+strSize);
add(strSize);
buffer.insert(buffer.end(), str.cbegin(), str.cend());
}
示例15: _fillDigits
void HugeInteger::_fillDigits(const std::string &a_digits)
{
size_t digit = {0};
for (auto cit = a_digits.cbegin(); cit != a_digits.cend(); ++cit, ++digit)
m_integers.at(digit) = *cit - '0';
}