本文整理汇总了C++中Dictionary::Find方法的典型用法代码示例。如果您正苦于以下问题:C++ Dictionary::Find方法的具体用法?C++ Dictionary::Find怎么用?C++ Dictionary::Find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dictionary
的用法示例。
在下文中一共展示了Dictionary::Find方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: f
// dictionary load/contains/find test
void Test::Test9()
{
const size_t dict_size = 10;
ofstream f("dict");
for (size_t i = 0; i < dict_size; ++i)
f << i << endl;
f.close();
Dictionary dict;
string msg;
bool res = dict.Load("dict", 1, msg);
for (size_t i = 0; res && i < dict_size; ++i)
{
string str = to_string(i);
res = dict.Contains(str);
Dictionary::DictionaryData::iterator di;
res = res && dict.Find(str, di);
res = res && di->first.compare(str) == 0;
res = res && di->second == false;
}
printf(res ? "Test9:\tpassed\r\n" : "Test9:\tfailed\r\n");
remove("dict");
}
示例2: Apply
std::string QueryMap::Apply(const VariableMap & vm, const Dictionary & dict
, SiteCharset charset)
{
using namespace std;
// split to vector
// find value in dict
stringstream ss;
UrlQueryEscape uqe;
vector<wstring> v;
boost::split(v, text_, boost::is_any_of(L"&"));
vector<pair<wstring, wstring> > w;
int i;
for (i=0; i<v.size(); ++i)
{
vector<wstring> eq;
boost::split(eq, v[i], boost::is_any_of(L"="));
if (eq.size() == 2)
w.push_back(make_pair(eq[0], eq[1]));
}
for (i=0; i<w.size(); ++i)
{
const wstring & key = w[i].first;
wstring domain = w[i].second, val;
// 1 find in vm, get value
// 2 find in dict, get value's value
if (boost::starts_with(domain, L"{")
&& boost::ends_with(domain, L"}") )
{
domain = domain.substr(1);
domain.resize(domain.size() - 1);
VariableMap::const_iterator i_vm = vm.find(domain);
ASSERT(i_vm != vm.end());
const VariableMap & vm_domain = dict.Find(domain);
if (!vm_domain.empty())
{
VariableMap::const_iterator j_vm = vm_domain.find(i_vm->second);
ASSERT(j_vm != vm_domain.end());
if (j_vm != vm_domain.end())
val = j_vm->second;
}
else
val = i_vm->second;
}
else
val = domain;
if (charset == SC_ANSI)
ss << w2string(key) << "=" << uqe(w2string(val)) << "&";
else
ss << string2utf8(key) << "=" << uqe(string2utf8(val)) << "&";
}
std::string ret = ss.str();
// remove last &
ret.resize(ret.size() - 1);
return ret;
}