本文整理汇总了C++中xr_string::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ xr_string::substr方法的具体用法?C++ xr_string::substr怎么用?C++ xr_string::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xr_string
的用法示例。
在下文中一共展示了xr_string::substr方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetColorFromText
// %c[255,255,255,255]
u32 CUILines::GetColorFromText(const xr_string& str)const {
// typedef xr_string::size_type size;
StrSize begin, end, comma1_pos, comma2_pos, comma3_pos;
begin = str.find(BEGIN);
end = str.find(END, begin);
R_ASSERT2(npos != begin, "CUISubLine::GetColorFromText -- can't find beginning tag %c[");
R_ASSERT2(npos != end, "CUISubLine::GetColorFromText -- can't find ending tag ]");
// try default color
if (npos != str.find("%c[default]", begin, end - begin))
return m_dwTextColor;
// Try predefined in XML colors
// CUIXmlInit xml;
for (CUIXmlInit::ColorDefs::const_iterator it = CUIXmlInit::GetColorDefs()->begin(); it != CUIXmlInit::GetColorDefs()->end(); ++it)
{
int cmp = str.compare(begin+3, end-begin-3, *it->first);
if (cmp == 0)
return it->second;
}
// try parse values separated by commas
comma1_pos = str.find(",", begin);
comma2_pos = str.find(",", comma1_pos + 1);
comma3_pos = str.find(",", comma2_pos + 1);
R_ASSERT2(npos != comma1_pos, "CUISubLine::GetColorFromText -- can't find first comma");
R_ASSERT2(npos != comma2_pos, "CUISubLine::GetColorFromText -- can't find second comma");
R_ASSERT2(npos != comma3_pos, "CUISubLine::GetColorFromText -- can't find third comma");
u32 a, r, g, b;
xr_string single_color;
begin+=3;
single_color = str.substr(begin, comma1_pos - 1);
a = atoi(single_color.c_str());
single_color = str.substr(comma1_pos + 1, comma2_pos - 1);
r = atoi(single_color.c_str());
single_color = str.substr(comma2_pos + 1, comma3_pos - 1);
g = atoi(single_color.c_str());
single_color = str.substr(comma3_pos + 1, end - 1);
b = atoi(single_color.c_str());
return color_argb(a,r,g,b);
}
示例2: CutFirstColoredTextEntry
void CUILines::CutFirstColoredTextEntry(xr_string& entry, u32& color, xr_string& text) const {
entry.clear();
StrSize begin = text.find(BEGIN);
StrSize end = text.find(END, begin);
if (xr_string::npos == end)
begin = end;
StrSize begin2 = text.find(BEGIN, end);
StrSize end2 = text.find(END,begin2);
if (xr_string::npos == end2)
begin2 = end2;
// if we do not have any color entry or it is single with 0 position
if (xr_string::npos == begin)
{
entry = text;
color = m_dwTextColor;
text.clear();
}
else if (0 == begin && xr_string::npos == begin2)
{
entry = text;
color = GetColorFromText(entry);
entry.replace(begin, end - begin + 1, "");
text.clear();
}
// if we have color entry not at begin
else if (0 != begin)
{
entry = text.substr(0, begin );
color = m_dwTextColor;
text.replace(0, begin, "");
}
// if we have two color entries. and first has 0 position
else if (0 == begin && xr_string::npos != begin2)
{
entry = text.substr(0, begin2);
color = GetColorFromText(entry);
entry.replace(begin, end - begin + 1, "");
text.replace(0, begin2, "");
}
}
示例3: LoadMapInfo
void CMapListHelper::LoadMapInfo(LPCSTR map_cfg_fn, const xr_string& map_name, LPCSTR map_ver)
{
CInifile ini (map_cfg_fn);
shared_str _map_name = map_name.substr(0,map_name.find('\\')).c_str();
shared_str _map_ver = map_ver;
if(ini.section_exist("map_usage"))
{
if(ini.line_exist("map_usage","ver") && !map_ver)
_map_ver = ini.r_string("map_usage", "ver");
CInifile::Sect S = ini.r_section("map_usage");
CInifile::SectCIt si = S.Data.begin();
CInifile::SectCIt si_e = S.Data.end();
for( ;si!=si_e; ++si)
{
const shared_str& game_type = (*si).first;
if(game_type=="ver") continue;
SGameTypeMaps* M = GetMapListInt(game_type);
if(!M)
{
Msg ("--unknown game type-%s",game_type.c_str());
m_storage.resize (m_storage.size()+1);
SGameTypeMaps& Itm = m_storage.back();
Itm.m_game_type_name = game_type;
Itm.m_game_type_id = ParseStringToGameType(game_type.c_str());
M = &m_storage.back();
}
SGameTypeMaps::SMapItm Itm;
Itm.map_name = _map_name;
Itm.map_ver = _map_ver;
if(M->m_map_names.end()!=std::find(M->m_map_names.begin(),M->m_map_names.end(),Itm))
{
Msg("! duplicate map found [%s] [%s]", _map_name.c_str(), _map_ver.c_str());
}else
{
#ifndef MASTER_GOLD
Msg("added map [%s] [%s]", _map_name.c_str(), _map_ver.c_str());
#endif // #ifndef MASTER_GOLD
M->m_map_names.push_back (Itm);
}
}
}
}
示例4: while
void add_debug_info_restrictions (debug::text_tree& root_s, const xr_string& restr)
{
size_t cur_i = 0;
do
{
size_t pos = restr.find(',', cur_i);
if ( pos == xr_string::npos )
{
pos = restr.size()-1;
}
if ( cur_i > pos )
{
root_s.add_line(restr.substr(cur_i, pos-cur_i));
}
cur_i = pos + 1;
} while ( cur_i < restr.size() );
}