当前位置: 首页>>代码示例>>C++>>正文


C++ string_t::substr方法代码示例

本文整理汇总了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;
}
开发者ID:KasaiDot,项目名称:anitomy,代码行数:27,代码来源:parser_number.cpp

示例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));
	}
}
开发者ID:OData,项目名称:odatacpp-server,代码行数:25,代码来源:utility.cpp

示例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;
}
开发者ID:ACefalu,项目名称:tzod,代码行数:33,代码来源:gui_desktop.cpp

示例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();
        }
}
开发者ID:accosmin,项目名称:nano,代码行数:52,代码来源:cmdline.cpp

示例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;
}
开发者ID:vevix,项目名称:anitomy,代码行数:25,代码来源:anitomy.cpp

示例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;
}
开发者ID:tyrel,项目名称:DCPUToolchain,代码行数:13,代码来源:Main.cpp

示例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());
}
开发者ID:ACefalu,项目名称:tzod,代码行数:48,代码来源:gui_desktop.cpp

示例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
    }
}
开发者ID:mattprintz,项目名称:wx-xword,代码行数:22,代码来源:Square.cpp

示例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);
}
开发者ID:OData,项目名称:odatacpp-server,代码行数:22,代码来源:utility.cpp

示例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;
}
开发者ID:gamedeff,项目名称:anitomy,代码行数:24,代码来源:anitomy.cpp

示例11: word_prefix

string_t word_prefix(const string_t &word)
{
	return word.length() > DEPTH ? word.substr(0, DEPTH) : word;
}
开发者ID:aababilov,项目名称:dictutils,代码行数:4,代码来源:wordform.cpp


注:本文中的string_t::substr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。