本文整理汇总了C++中StringT::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ StringT::substr方法的具体用法?C++ StringT::substr怎么用?C++ StringT::substr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringT
的用法示例。
在下文中一共展示了StringT::substr方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: trigraph
inline StringT
convert_trigraphs(StringT const &value)
{
StringT result;
typename StringT::size_type pos = 0;
typename StringT::size_type pos1 = value.find_first_of ("?", 0);
if (StringT::npos != pos1) {
do {
result += value.substr(pos, pos1-pos);
StringT trigraph (value.substr(pos1));
if (is_trigraph(trigraph)) {
result += convert_trigraph(trigraph);
pos1 = value.find_first_of ("?", pos = pos1+3);
}
else {
result += value[pos1];
pos1 = value.find_first_of ("?", pos = pos1+1);
}
} while (StringT::npos != pos1);
result += value.substr(pos);
}
else {
result = value;
}
return result;
}
示例2: while
inline StringT
unescape_lit(StringT const &value)
{
StringT result;
typename StringT::size_type pos = 0;
typename StringT::size_type pos1 = value.find_first_of ("\\", 0);
if (StringT::npos != pos1) {
do {
if ('\\' == value[pos1+1] || '\"' == value[pos1+1] ||
'?' == value[pos1+1])
{
result = result + value.substr(pos, pos1-pos);
pos1 = value.find_first_of ("\\", (pos = pos1+1)+1);
}
else {
result = result + value.substr(pos, pos1-pos+1);
pos1 = value.find_first_of ("\\", pos = pos1+1);
}
} while (pos1 != StringT::npos);
result = result + value.substr(pos);
}
else {
// the string doesn't contain any escaped character sequences
result = value;
}
return result;
}
示例3: StringT
inline StringT
escape_lit(StringT const &value)
{
StringT result;
typename StringT::size_type pos = 0;
typename StringT::size_type pos1 = value.find_first_of ("\"\\?", 0);
if (StringT::npos != pos1) {
do {
result += value.substr(pos, pos1-pos)
+ StringT("\\")
+ StringT(1, value[pos1]);
pos1 = value.find_first_of ("\"\\?", pos = pos1+1);
} while (StringT::npos != pos1);
result += value.substr(pos);
}
else {
result = value;
}
return result;
}
示例4: uchar_val
inline void
validate_identifier_name (StringT const &name, std::size_t line,
std::size_t column, StringT const &file_name)
{
using namespace std; // some systems have strtoul in namespace std::
typename StringT::size_type pos = name.find_first_of('\\');
while (StringT::npos != pos) {
// the identifier name contains a backslash (must be universal char)
BOOST_ASSERT('u' == name[pos+1] || 'U' == name[pos+1]);
StringT uchar_val(name.substr(pos+2, ('u' == name[pos+1]) ? 4 : 8));
universal_char_type type =
classify_universal_char(strtoul(uchar_val.c_str(), 0, 16));
if (universal_char_type_valid != type) {
// an invalid char was found, so throw an exception
StringT error_uchar(name.substr(pos, ('u' == name[pos+1]) ? 6 : 10));
if (universal_char_type_invalid == type) {
BOOST_WAVE_LEXER_THROW(lexing_exception, universal_char_invalid,
error_uchar, line, column, file_name.c_str());
}
else if (universal_char_type_base_charset == type) {
BOOST_WAVE_LEXER_THROW(lexing_exception, universal_char_base_charset,
error_uchar, line, column, file_name.c_str());
}
else {
BOOST_WAVE_LEXER_THROW(lexing_exception, universal_char_not_allowed,
error_uchar, line, column, file_name.c_str());
}
}
// find next universal char (if appropriate)
pos = name.find_first_of('\\', pos+2);
}
}
示例5: switch
inline StringT
unescape_lit(StringT const &value)
{
StringT result;
typename StringT::size_type pos = 0;
typename StringT::size_type pos1 = value.find_first_of ("\\", 0);
if (StringT::npos != pos1) {
do {
switch (value[pos1+1]) {
case '\\':
case '\"':
case '?':
result = result + value.substr(pos, pos1-pos);
pos1 = value.find_first_of ("\\", (pos = pos1+1)+1);
break;
case 'n':
result = result + value.substr(pos, pos1-pos) + "\n";
pos1 = value.find_first_of ("\\", pos = pos1+1);
++pos;
break;
default:
result = result + value.substr(pos, pos1-pos+1);
pos1 = value.find_first_of ("\\", pos = pos1+1);
}
} while (pos1 != StringT::npos);
result = result + value.substr(pos);
}
else {
// the string doesn't contain any escaped character sequences
result = value;
}
return result;
}
示例6:
inline bool
is_special_macroname (StringT const &name)
{
if (name.size() < 7)
return false;
if ("defined" == name)
return true;
if ('_' == name[0] && '_' == name[1]) {
StringT str = name.substr(2);
if (str == "cplusplus" || str == "STDC__" ||
str == "TIME__" || str == "DATE__" ||
str == "LINE__" || str == "FILE__" ||
str == "INCLUDE_LEVEL__")
{
return true;
}
}
return false;
}