本文整理汇总了C++中StringTokenizer::getTokens方法的典型用法代码示例。如果您正苦于以下问题:C++ StringTokenizer::getTokens方法的具体用法?C++ StringTokenizer::getTokens怎么用?C++ StringTokenizer::getTokens使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringTokenizer
的用法示例。
在下文中一共展示了StringTokenizer::getTokens方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getDisplayName
StringList UserCommand::getDisplayName() const
{
StringList l_displayName;
string name_ = name;
if (!isSet(UserCommand::FLAG_NOSAVE))
{
Util::replace("\\", "/", name_);
}
Util::replace("//", "\t", name_);
const StringTokenizer<string> t(name_, '/');
for (auto i = t.getTokens().cbegin(), iend = t.getTokens().cend(); i != iend; ++i)
{
l_displayName.push_back(*i);
Util::replace("\t", "/", l_displayName.back());
}
return l_displayName;
}
示例2: loadGraph
void loadGraph(std::string edgeFile)
{
// Open file for reading
freopen(edgeFile.c_str(), "rt", stdin);
edge_count = 0;
vecEdges.clear();
maxNode = -1;
// Read line by line edge info
while(gets(buff))
{
if(strlen(buff) == 0)
break;
edge_count++;
StringTokenizer token;
// tokenize using comma
token.parse(buff, ",");
std::vector<std::string> vecToken;
vecToken.clear();
token.getTokens(vecToken);
// There should be exactly 9 values: edge_id, start_node_id, end_node_id,
// start_node_longitude, start_node_latitude, end_node_longitude, end_node_latitude, cost, reverse_cost
if(vecToken.size() < 5)
fprintf(stderr, "Error in %d edge\n", edge_count);
// Populate Edge_t structure
edge_astar_t tempEdge;
tempEdge.id = atoi(vecToken[0].c_str());
tempEdge.source = atoi(vecToken[1].c_str());
tempEdge.target = atoi(vecToken[2].c_str());
tempEdge.cost = atof(vecToken[3].c_str());
tempEdge.reverse_cost = atof(vecToken[4].c_str());
tempEdge.s_x = atof(vecToken[5].c_str());
tempEdge.s_y = atof(vecToken[6].c_str());
tempEdge.t_x = atof(vecToken[7].c_str());
tempEdge.t_y = atof(vecToken[8].c_str());
// Update max_node_id
if(tempEdge.source > maxNode)
maxNode = tempEdge.source;
if(tempEdge.target > maxNode)
maxNode = tempEdge.target;
vecEdges.push_back(tempEdge);
}
edges = new edge_astar_t[edge_count];
int i;
for(i = 0; i < edge_count; i++)
{
edges[i] = vecEdges[i];
}
fclose(stdin);
}
示例3: calcISPCountryIconIndex
int PublicHubsFrame::calcISPCountryIconIndex(tstring& p_country)
{
// http://www.artlebedev.ru/tools/country-list/
static const TCHAR* g_country_map[] =
{
_T("Россия"), _T("RU"),
_T("Украина"), _T("UA"),
_T("Беларусь"), _T("BY"),
_T("USA"), _T("US"),
_T("Казахстан"), _T("KZ"),
_T("Узбекистан"), _T("UZ"),
_T("Азербайджан"), _T("AZ"),
_T("Молдова"), _T("MD"),
_T("Эстония"), _T("EE"),
_T("Bulgaria"), _T("BG"),
_T("Brazil"), _T("BR"),
_T("Australia"), _T("AS"),
_T("Poland"), _T("PL"),
_T("Korea"), _T("KP"),
_T("Romania"), _T("RO"),
_T("Spain"), _T("ES"),
_T("Niue"), _T("NU"),
_T("Italy"), _T("IT")
};
for (auto i = 0; i < _countof(g_country_map) / 2; ++i)
{
const StringTokenizer<tstring, TStringList> l_country(g_country_map[i * 2], _T(','));
for (auto j = l_country.getTokens().cbegin(); j != l_country.getTokens().cend() ; ++j)
{
if (*j == p_country)
{
p_country = l_country.getTokens()[0];
const auto l_id_country = Text::fromT(g_country_map[i * 2 + 1]);
return Util::getFlagIndexByCode(*reinterpret_cast<const uint16_t*>(l_id_country.c_str()));
}
}
}
return -1;
}
示例4: onInitDialog
LRESULT ToolbarPage::onInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
PropPage::translate((HWND)(*this), texts);
PropPage::read((HWND)*this, items);
m_ctrlCommands.Attach(GetDlgItem(IDC_TOOLBAR_POSSIBLE));
CRect rc;
m_ctrlCommands.GetClientRect(rc);
m_ctrlCommands.InsertColumn(0, _T("Dummy"), LVCFMT_LEFT, rc.Width(), 0);
m_ctrlCommands.SetImageList(MainFrame::getMainFrame()->largeImages, LVSIL_SMALL);
LVITEM lvi = {0};
lvi.mask = LVIF_TEXT | LVIF_IMAGE;
lvi.iSubItem = 0;
for (int i = -1; i < 0 || g_ToolbarButtons[i].id != 0; i++)
{
// [-] brain-ripper
// follow block commented,
// it can brake custom toolbar creation.
// don't do this!
/*
#ifndef IRAINMAN_ENABLE_HUB_LIST
if (!i)
continue;
#endif
*/
makeItem(&lvi, i);
lvi.iItem = i + 1;
m_ctrlCommands.InsertItem(&lvi);
m_ctrlCommands.SetItemData(lvi.iItem, i);
}
m_ctrlCommands.SetColumnWidth(0, LVSCW_AUTOSIZE);
m_ctrlToolbar.Attach(GetDlgItem(IDC_TOOLBAR_ACTUAL));
m_ctrlToolbar.GetClientRect(rc);
m_ctrlToolbar.InsertColumn(0, _T("Dummy"), LVCFMT_LEFT, rc.Width(), 0);
m_ctrlToolbar.SetImageList(MainFrame::getMainFrame()->largeImagesHot, LVSIL_SMALL);
const StringTokenizer<string> t(SETTING(TOOLBAR), ',');
const StringList& l = t.getTokens();
int n = 0;
for (auto k = l.cbegin(); k != l.cend(); ++k)
{
int i = Util::toInt(*k);
const int l_cnt = g_cout_of_ToolbarButtons;
if (i < l_cnt)
{
makeItem(&lvi, i);
lvi.iItem = n++;
m_ctrlToolbar.InsertItem(&lvi);
m_ctrlToolbar.SetItemData(lvi.iItem, i);
// disable items that are already in toolbar,
// to avoid duplicates
if (i != -1)
m_ctrlCommands.SetItemState(i + 1, LVIS_CUT, LVIS_CUT);
}
}
m_ctrlToolbar.SetColumnWidth(0, LVSCW_AUTOSIZE);
return TRUE;
}
示例5: parseISPHubsLine
void PublicHubsFrame::parseISPHubsLine(const string& p_line, CFlyLog& p_log)
{
if (!m_filter.empty() && Text::toLower(p_line).find(Text::toLower(m_filter)) == string::npos)
return;
string l_line = p_line;
const StringTokenizer<string> l_isp(l_line, ';');
dcassert(l_isp.getTokens().size() == 6);
if (l_isp.getTokens().size() != 6)
{
p_log.step("Error l_isp.getTokens().size()!= 6, Line = " + p_line);
}
else
{
const auto l_country_name = l_isp.getTokens()[1];
auto l_name = Text::toT(l_country_name);
const auto l_image_index = calcISPCountryIconIndex(l_name);
auto& l_country_item = m_country_map.m_country[l_country_name];
if (!l_country_item.m_tree_item)
{
l_country_item.m_tree_item = m_ctrlTree.InsertItem(TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_PARAM,
l_name.c_str(),
l_image_index, // nImage
l_image_index, // nSelectedImage
0, // nState
0, // nStateMask
e_ISPCountry, // lParam
m_ISPRootItem, // aParent,
0 // hInsertAfter
);
}
// Город
const auto l_city_name = l_isp.getTokens()[2];
auto& l_city_item = l_country_item.m_city[l_city_name];
if (!l_city_item.m_tree_item)
{
l_city_item.m_tree_item = m_ctrlTree.InsertItem(TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_PARAM,
Text::toT(l_city_name).c_str(),
g_ISPImage.m_flagImageCount + 7, // nImage
g_ISPImage.m_flagImageCount + 7, // nSelectedImage
0, // nState
0, // nStateMask
e_ISPCity, // lParam
l_country_item.m_tree_item, // aParent,
0 // hInsertAfter
);
}
// Провайдер
const auto l_isp_name = l_isp.getTokens()[3];
auto& l_isp_item = l_city_item.m_isp[l_isp_name];
if (!l_isp_item.m_tree_item)
{
l_isp_item.m_tree_item = m_ctrlTree.InsertItem(TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_PARAM,
Text::toT(l_isp_name).c_str(),
g_ISPImage.m_flagImageCount + 0, // nImage
g_ISPImage.m_flagImageCount + 0, // nSelectedImage
0, // nState
0, // nStateMask
e_ISPProvider, // lParam
l_city_item.m_tree_item, // aParent,
0 // hInsertAfter
);
}
// Сеть
const auto l_network_name = l_isp.getTokens()[4];
auto& l_network_item = l_isp_item.m_network[l_network_name];
if (!l_network_name.empty())
{
if (!l_network_item.m_tree_item)
{
l_network_item.m_tree_item = m_ctrlTree.InsertItem(TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_PARAM,
Text::toT(l_network_name).c_str(),
g_ISPImage.m_flagImageCount + 2, // nImage
g_ISPImage.m_flagImageCount + 2, // nSelectedImage
0, // nState
0, // nStateMask
e_ISPNetwork, // lParam
l_isp_item.m_tree_item, // aParent,
0 // hInsertAfter
);
}
}
// Хабы
const StringTokenizer<string> l_hubs(l_isp.getTokens()[5], ',');
for (auto j = l_hubs.getTokens().cbegin(); j != l_hubs.getTokens().cend() ; ++j)
{
if (!m_filter.empty() && Text::toLower(*j).find(Text::toLower(m_filter)) == string::npos)
continue;
auto& l_hub_item = l_network_item.m_hubs[*j];
if (!l_hub_item.m_tree_item)
{
l_hub_item.m_tree_item = m_ctrlTree.InsertItem(TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_PARAM,
Text::toT(*j).c_str(),
g_ISPImage.m_flagImageCount + 5, // nImage
g_ISPImage.m_flagImageCount + 5, // nSelectedImage
0, // nState
0, // nStateMask
e_ISPHub, // lParam
!l_network_name.empty() ? l_network_item.m_tree_item : l_isp_item.m_tree_item, // aParent,
0 // hInsertAfter
//.........这里部分代码省略.........
示例6: main
int main()
{
int i;
double cl;
kase = 1;
// The final output will be written in the outFile and the initial input will be read from inFile
std::string outFile = "output.txt";
std::string inFile = "input.txt";
// Create the output file
FILE *fpout = fopen(outFile.c_str(), "wt");
fclose(fpout);
// Open the input file
FILE *fpin = fopen(inFile.c_str(), "rt");
// Reading each of the cases, There may be two types of cases, with 4 parameters, with 5 parameters
// There may also be comments that starts with #
while(fgets(buff, 1000, fpin))
{
// No data
if(strlen(buff) == 0)
continue;
// Comment
if(buff[0] == '#')
continue;
StringTokenizer token;
// tokeniize using space
token.parse(buff, " \n\r");
std::vector<std::string> vecToken;
token.getTokens(vecToken);
int totParam = vecToken.size();
// Not enough parameters
if(totParam < 4)
continue;
// First token is the graph file name
std::string graphFile = vecToken[0];
// 2nd and 3rd tokens are start and end node id respectively
int startNode = atoi(vecToken[1].c_str());
int endNode = atoi(vecToken[2].c_str());
// 4th Token is the result file for this query
std::string pathFile = vecToken[3];
int ind = pathFile.length() - 1;
while(pathFile[ind] < 32)
{
pathFile[ind] = '\0';
ind--;
}
// Load edge information from graph file
loadGraph(graphFile);
// Use bidirectional AStar to get the route
BiDirAStar gdef;
cl = clock();
int res = gdef.bidir_astar(edges, edge_count, maxNode, startNode, endNode, &path, &path_count, &err_msg);
cl = clock() - cl;
// Write the route in the result file
write_result(pathFile, res);
// There is an answer file
if(totParam > 4)
{
std::string ansFile = vecToken[4];
ind = ansFile.length() - 1;
while(ansFile[ind] < 32)
{
ansFile[ind] = '\0';
ind--;
}
// Match and write result in the final output file
match(pathFile, ansFile, outFile, cl / CLOCKS_PER_SEC);
}
else
{
// Provide information that the route is generated in path file.
fpout = fopen(outFile.c_str(), "a+");
fprintf(fpout, "Case %d: Path Written to file %s", kase, pathFile.c_str());
fprintf(fpout, "Query Time: %lf sec\n\n", cl / CLOCKS_PER_SEC);
fclose(fpout);
}
kase++;
free(path);
delete [] edges;
}
return 0;
}