本文整理汇总了C++中string_t::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ string_t::substr方法的具体用法?C++ string_t::substr怎么用?C++ string_t::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string_t
的用法示例。
在下文中一共展示了string_t::substr方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MatchTypeAndEpisodePattern
bool Parser::MatchTypeAndEpisodePattern(const string_t& word, Token& token) {
size_t number_begin = FindNumberInString(word);
auto prefix = word.substr(0, number_begin);
ElementCategory category = kElementAnimeType;
KeywordOptions options;
if (keyword_manager.Find(keyword_manager.Normalize(prefix),
category, options)) {
elements_.insert(kElementAnimeType, prefix);
auto number = word.substr(number_begin);
if (MatchEpisodePatterns(number, token) ||
SetEpisodeNumber(number, token, true)) {
auto it = std::find(tokens_.begin(), tokens_.end(), token);
if (it != tokens_.end()) {
// Split token (we do this last in order to avoid invalidating our
// token reference earlier)
token.content = number;
tokens_.insert(it, Token(options.identifiable ? kIdentifier : kUnknown,
prefix, token.enclosed));
}
return true;
}
}
return false;
}
示例2: split_string
void split_string(string_t& source, const string_t& delim, std::list<string_t>& ret)
{
ret.clear();
if (delim.empty() || source.empty())
{
ret.push_back(source);
return ;
}
size_t last = 0;
size_t index = source.find(delim, last);
while (index!=std::string::npos)
{
ret.push_back(source.substr(last, index - last));
last = index + delim.size();
index = source.find(delim, last);
}
if(index - last > 0)
{
ret.push_back(source.substr(last, index - last));
}
}
示例3: OnCompleteCommand
bool Desktop::OnCompleteCommand(const string_t &cmd, int &pos, string_t &result)
{
assert(pos >= 0);
lua_getglobal(g_env.L, "autocomplete");
if( lua_isnil(g_env.L, -1) )
{
lua_pop(g_env.L, 1);
GetConsole().WriteLine(1, "There was no autocomplete module loaded");
return false;
}
lua_pushlstring(g_env.L, cmd.substr(0, pos).c_str(), pos);
HRESULT hr = S_OK;
if( lua_pcall(g_env.L, 1, 1, 0) )
{
GetConsole().WriteLine(1, lua_tostring(g_env.L, -1));
}
else
{
const char *str = lua_tostring(g_env.L, -1);
string_t insert = str ? str : "";
result = cmd.substr(0, pos) + insert + cmd.substr(pos);
pos += insert.length();
if( g_client && !g_client->IsLocal() && !result.empty() && result[0] != '/' )
{
result = string_t("/") + result;
++pos;
}
}
lua_pop(g_env.L, 1); // pop result or error message
return true;
}
示例4: process
void cmdline_t::process(const int argc, const char* argv[]) const
{
string_t current_name_or_short_name;
for (int i = 1; i < argc; ++ i)
{
const string_t token = argv[i];
assert(!token.empty());
if (nano::starts_with(token, "--"))
{
const string_t name = token.substr(2);
if (name.empty())
{
log_critical(strcat("cmdline: invalid option name [", name, "/", token, "]"));
}
m_impl->store(name);
current_name_or_short_name = name;
}
else if (nano::starts_with(token, "-"))
{
const string_t short_name = token.substr(1);
if (short_name.size() != 1)
{
log_critical(strcat("cmdline: invalid short option name [", short_name, "/", token, "]"));
}
m_impl->store(short_name);
current_name_or_short_name = short_name;
}
else
{
const string_t& value = token;
if (current_name_or_short_name.empty())
{
log_critical(strcat("cmdline: missing option before value [", value, "]"));
}
m_impl->store(current_name_or_short_name, value);
current_name_or_short_name.clear();
}
}
if (has("help"))
{
usage();
}
}
示例5: RemoveExtensionFromFilename
bool Anitomy::RemoveExtensionFromFilename(string_t& filename,
string_t& extension) {
const size_t position = filename.find_last_of(L'.');
if (position == string_t::npos)
return false;
extension = filename.substr(position + 1);
const size_t max_length = 4;
if (extension.length() > max_length)
return false;
if (!IsAlphanumericString(extension))
return false;
// TODO: Add an option for this
auto keyword = StringToUpperCopy(extension);
if (!keyword_manager.Find(kElementFileExtension, keyword))
return false;
filename.resize(position);
return true;
}
示例6: dirname
string_t dirname(string_t source)
{
if (source.size() <= 1) //Make sure it's possible to check the last character.
{
return source;
}
if (*(source.rbegin() + 1) == '/') //Remove trailing slash if it exists.
{
source = source.substr(0, source.size() - 1);
}
source.erase(std::find(source.rbegin(), source.rend(), '/').base(), source.end());
return source;
}
示例7: OnCommand
void Desktop::OnCommand(const string_t &cmd)
{
if( cmd.empty() )
{
return;
}
string_t exec;
if( g_client && !g_client->IsLocal() )
{
if( cmd[0] == '/' )
{
exec = cmd.substr(1); // cut off the first symbol and execute cmd
}
else
{
dynamic_cast<TankClient*>(g_client)->SendTextMessage(cmd);
return;
}
}
else
{
exec = cmd;
}
if( luaL_loadstring(g_env.L, exec.c_str()) )
{
lua_pop(g_env.L, 1);
string_t tmp = "print(";
tmp += exec;
tmp += ")";
if( luaL_loadstring(g_env.L, tmp.c_str()) )
{
lua_pop(g_env.L, 1);
}
else
{
script_exec(g_env.L, tmp.c_str());
return;
}
}
script_exec(g_env.L, exec.c_str());
}
示例8: SetColor
void Square::SetColor(const string_t & hexcolor)
{
size_t len = hexcolor.size();
if (len > 0 && hexcolor[0] == puzT('#'))
{
SetColor(hexcolor.substr(1));
return;
}
try {
if (len == 3)
SetColor(ParseHex(hexcolor[0], hexcolor[0]),
ParseHex(hexcolor[1], hexcolor[1]),
ParseHex(hexcolor[2], hexcolor[2]));
else if (len == 6)
SetColor(ParseHex(hexcolor[0], hexcolor[1]),
ParseHex(hexcolor[2], hexcolor[3]),
ParseHex(hexcolor[4], hexcolor[5]));
}
catch (Exception &) {
// Don't set the color if we can't parse the hex value
}
}
示例9: strip_string
string_t strip_string(const string_t& escaped)
{
string_t::size_type first = 0;
string_t::size_type size = escaped.size();
if (escaped.empty())
{
return escaped;
}
if (escaped[0] == U('"'))
{
first += 1;
}
if (escaped[size - 1] == U('"'))
{
size -= 1;
}
return escaped.substr(first, size - first);
}
示例10: RemoveExtensionFromFilename
bool Anitomy::RemoveExtensionFromFilename(string_t& filename,
string_t& extension) const {
const size_t position = filename.find_last_of(L'.');
if (position == string_t::npos)
return false;
extension = filename.substr(position + 1);
const size_t max_length = 4;
if (extension.length() > max_length)
return false;
if (!IsAlphanumericString(extension))
return false;
string_t keyword = keyword_manager.Normalize(extension);
if (!keyword_manager.Find(kElementFileExtension, keyword))
return false;
filename.resize(position);
return true;
}
示例11: word_prefix
string_t word_prefix(const string_t &word)
{
return word.length() > DEPTH ? word.substr(0, DEPTH) : word;
}