Rename token_iterator_foreach to token_iterator::foreach

This commit is contained in:
Ilari Liusvaara 2014-11-10 16:54:18 +02:00
parent b0c08d3a9f
commit e2589db8b7
9 changed files with 41 additions and 37 deletions

View file

@ -148,6 +148,33 @@ public:
*/
static void pull_fn();
private:
/**
* Foreach helper.
*/
template<typename U> class _foreach
{
public:
/**
* Create helper.
*/
_foreach(const std::basic_string<U>& _s,
std::initializer_list<const U*> sep, bool whole_sequence = false)
: s(_s, sep, whole_sequence)
{
}
/**
* Starting iterator.
*/
token_iterator<U> begin() throw() { return s; }
/**
* Ending iterator.
*/
token_iterator<U> end() throw() { return e; }
private:
token_iterator<U> s;
token_iterator<U> e;
};
void ctor_eos();
void ctor_itr(std::initializer_list<const T*> sep, bool whole_sequence = false) throw(std::bad_alloc);
token_iterator<T> postincrement() throw(std::bad_alloc);
@ -163,40 +190,17 @@ private:
std::set<std::basic_string<T>> spliton;
bool is_end_iterator;
bool whole_seq;
};
/**
* Foreach helper.
*/
template<typename U> class _token_iterator_foreach
{
public:
/**
* Create helper.
* Return an container referencing tokens of string.
*/
_token_iterator_foreach(const std::basic_string<U>& _s,
std::initializer_list<const U*> sep, bool whole_sequence = false)
: s(_s, sep, whole_sequence)
static _foreach<T> foreach(const std::basic_string<T>& _s,
std::initializer_list<const T*> sep, bool whole_sequence = false)
{
return _foreach<T>(_s, sep, whole_sequence);
}
/**
* Starting iterator.
*/
token_iterator<U> begin() throw() { return s; }
/**
* Ending iterator.
*/
token_iterator<U> end() throw() { return e; }
private:
token_iterator<U> s;
token_iterator<U> e;
};
template<typename T> _token_iterator_foreach<T> token_iterator_foreach(const std::basic_string<T>& _s,
std::initializer_list<const T*> sep, bool whole_sequence = false)
{
return _token_iterator_foreach<T>(_s, sep, whole_sequence);
}
class regex_results

View file

@ -331,7 +331,7 @@ namespace
auto& core = CORE();
std::list<std::string> _args;
std::string args2 = args;
for(auto& sym : token_iterator_foreach(args, {" ", "\t"}))
for(auto& sym : token_iterator<char>::foreach(args, {" ", "\t"}))
_args.push_back(sym);
core.lua2->callback_do_latch(_args);
});

View file

@ -320,7 +320,7 @@ messagebuffer platform::msgbuf(MAXMESSAGES, INIT_WIN_SIZE);
void platform::message(const std::string& msg) throw(std::bad_alloc)
{
threads::alock h(msgbuf_lock());
for(auto& forlog : token_iterator_foreach(msg, {"\n"})) {
for(auto& forlog : token_iterator<char>::foreach(msg, {"\n"})) {
msgbuf.add_message(forlog);
if(system_log)
system_log << forlog << std::endl;

View file

@ -432,7 +432,7 @@ namespace sky
stransitions[lsid].end_pts = parse_value<uint64_t>(r[3]) + ctx.pregap;
if(r[1] == "NEXT") {
std::string next = r[3];
for(auto& token : token_iterator_foreach(next, {","})) {
for(auto& token : token_iterator<char>::foreach(next, {","})) {
uint32_t lsid2 = register_lsid(token);
stransitions[lsid].next_subsongs.insert(lsid2);
}

View file

@ -133,7 +133,7 @@ core_romimage_info::core_romimage_info(const core_romimage_info_params& params)
headersize = params.headersize;
if(params.extensions) {
std::string tmp = params.extensions;
for(auto& ext : token_iterator_foreach(tmp, {";"}))
for(auto& ext : token_iterator<char>::foreach(tmp, {";"}))
extensions.insert(ext);
}
}

View file

@ -206,7 +206,7 @@ font2::font2(const std::string& file)
if(tname == "bad") {
//Special, no key.
} else if(regex_match("[0-9]+(-[0-9]+)*", tname))
for(auto& tmp : token_iterator_foreach(tname, {"-"}))
for(auto& tmp : token_iterator<char>::foreach(tname, {"-"}))
key.append(1, parse_value<uint32_t>(tmp));
else {
delete toclose;

View file

@ -868,7 +868,7 @@ color::color(const std::string& clr) throw(std::bad_alloc, std::runtime_error)
int64_t col = -1;
bool first = true;
auto& cspecs = colornames();
for(auto& t : token_iterator_foreach(clr, {" ","\t"}, true)) {
for(auto& t : token_iterator<char>::foreach(clr, {" ","\t"}, true)) {
if(t.length() > 0 && t[0] == '#') {
if(!first)
throw std::runtime_error("Base color (" + t + ") can't be used as modifier");

View file

@ -378,9 +378,9 @@ std::string clean_keystring(const std::string& in)
std::string key = tmp[3];
std::set<std::string> _mods, _mask;
std::string tmp2;
for(auto& tmp2 : token_iterator_foreach(mods, {","}))
for(auto& tmp2 : token_iterator<char>::foreach(mods, {","}))
_mods.insert(tmp2);
for(auto& tmp2 : token_iterator_foreach(mask, {","}))
for(auto& tmp2 : token_iterator<char>::foreach(mask, {","}))
_mask.insert(tmp2);
for(auto i : _mods)
if(!_mask.count(i))

View file

@ -60,8 +60,8 @@ bool search_match(const std::string& term, const std::string& name)
{
std::set<std::string> searched;
std::vector<std::string> name_words;
for(auto i : token_iterator_foreach<char>(name, {" "})) if(i != "") name_words.push_back(str_tolower(i));
for(auto i : token_iterator_foreach<char>(term, {" "})) {
for(auto i : token_iterator<char>::foreach(name, {" "})) if(i != "") name_words.push_back(str_tolower(i));
for(auto i : token_iterator<char>::foreach(term, {" "})) {
if(i == "")
continue;
std::string st = str_tolower(i);