Use C++11 for loop

Majority of the edits done using the following ruby script:

    def update_loops(src)
      dst, cnt = '', 0

      block_indent, variable = nil, nil
      src.each_line do |line|
        if block_indent
          if line =~ /^#{block_indent}([{}\t])|^\t*$/
            block_indent = nil if $1 == '}'
            line = line.gsub(%r{ ([^a-z>]) \(\*#{variable}\) | \*#{variable}\b | \b#{variable}(->) }x) do
              $1.to_s + variable + ($2 == "->" ? "." : "")
            end
          else
            block_indent = nil
          end
        elsif line =~ /^(\t*)c?iterate\((\w+), (?!diacritics::make_range)(.*\))$/
          block_indent, variable = $1, $2
          line = "#$1for(auto const& #$2 : #$3\n"
          cnt += 1
        end
        dst << line
      end
      return dst, cnt
    end

    paths.each do |path|
      src = IO.read(path)

      cnt = 1
      while cnt != 0
        src, cnt = update_loops(src)
        STDERR << "#{path}: #{cnt}\n"
      end

      File.open(path, "w") { |io| io << src }
    end
This commit is contained in:
Allan Odgaard
2014-03-02 22:57:05 +07:00
parent 1781f4a605
commit c2397484b8
126 changed files with 1585 additions and 1585 deletions

View File

@@ -162,8 +162,8 @@ namespace ng
_hardlines.set(from + i, true);
}
iterate(hook, _meta_data)
(*hook)->replace(this, from, to, str);
for(auto const& hook : _meta_data)
hook->replace(this, from, to, str);
_callbacks(&callback_t::did_replace, from, to, str);
return from + str.size();

View File

@@ -149,8 +149,8 @@ namespace ng
private:
void did_parse (size_t first, size_t last)
{
iterate(hook, _meta_data)
(*hook)->did_parse(this, first, last);
for(auto const& hook : _meta_data)
hook->did_parse(this, first, last);
_callbacks(&callback_t::did_parse, first, last);
}

View File

@@ -5,13 +5,13 @@ namespace ng
{
void marks_t::replace (buffer_t* buffer, size_t from, size_t to, std::string const& str)
{
iterate(m, _marks)
for(auto& m : _marks)
{
tree_t::iterator it = m->second.upper_bound(to);
std::string preserveMark = it != m->second.begin() && from < (--it)->first && it->first <= to ? it->second : NULL_STR;
m->second.replace(from, to, str.size(), false);
tree_t::iterator it = m.second.upper_bound(to);
std::string preserveMark = it != m.second.begin() && from < (--it)->first && it->first <= to ? it->second : NULL_STR;
m.second.replace(from, to, str.size(), false);
if(preserveMark != NULL_STR)
m->second.set(from + str.size(), preserveMark);
m.second.set(from + str.size(), preserveMark);
}
}
@@ -74,9 +74,9 @@ namespace ng
if(markType == NULL_STR)
{
iterate(m, _marks)
for(auto const& m : _marks)
{
foreach(it, m->second.lower_bound(from), m->second.upper_bound(to))
foreach(it, m.second.lower_bound(from), m.second.upper_bound(to))
res[it->first - from] = it->second;
}
}

View File

@@ -24,14 +24,14 @@ namespace ng
if(!ranksToRemove.empty())
{
std::set<ssize_t> indicesToRemove;
iterate(it, _pairs)
for(auto const& it : _pairs)
{
if(ranksToRemove.find(it->second) != ranksToRemove.end())
indicesToRemove.insert(it->first);
if(ranksToRemove.find(it.second) != ranksToRemove.end())
indicesToRemove.insert(it.first);
}
iterate(index, indicesToRemove)
_pairs.remove(*index);
for(auto const& index : indicesToRemove)
_pairs.remove(index);
}
}
_pairs.replace(from, to, str.size());
@@ -72,11 +72,11 @@ namespace ng
ASSERT(_pairs.find(index) != _pairs.end());
size_t rank = _pairs.find(index)->second;
D(DBF_Buffer_Pairs, bug("%zu, rank %zu\n", index, rank););
iterate(it, _pairs)
for(auto const& it : _pairs)
{
D(DBF_Buffer_Pairs, bug("%zd, rank %zu → %s\n", it->first, it->second, BSTR((it->second & ~1) == (rank & ~1) && it->second != rank)););
if((it->second & ~1) == (rank & ~1) && it->second != rank)
return it->first;
D(DBF_Buffer_Pairs, bug("%zd, rank %zu → %s\n", it.first, it.second, BSTR((it.second & ~1) == (rank & ~1) && it.second != rank)););
if((it.second & ~1) == (rank & ~1) && it.second != rank)
return it.first;
}
ASSERT(false);
return index;

View File

@@ -105,10 +105,10 @@ namespace ng
D(DBF_Buffer_Parsing, bug("did parse %zu-%zu (revision %zu), at EOL %s\n", range.first, range.second, revision(), BSTR(atEOF)););
_scopes.remove(_scopes.lower_bound(range.first), atEOF ? _scopes.end() : _scopes.lower_bound(range.second));
iterate(pair, newScopes)
for(auto const& pair : newScopes)
{
if(range.first + pair->first < range.second || atEOF)
_scopes.set(range.first + pair->first, pair->second);
if(range.first + pair.first < range.second || atEOF)
_scopes.set(range.first + pair.first, pair.second);
}
_dirty.remove(_dirty.lower_bound(range.first), atEOF ? _dirty.end() : _dirty.lower_bound(range.second));

View File

@@ -73,15 +73,15 @@ namespace ng
if(fromIter != toIter && fromIter->first >= to && fromIter->second)
fromIter = toIter;
_misspellings.remove(fromIter, toIter);
iterate(r, ranges)
for(auto const& r : ranges)
{
std::string const& text = buffer->substr(r->first, r->second);
std::string const& text = buffer->substr(r.first, r.second);
D(DBF_Buffer_Spelling, bug("check: %s (%s)\n", text.c_str(), buffer->spelling_language().c_str()););
citerate(range, ns::spellcheck(text.data(), text.data() + text.size(), buffer->spelling_language(), buffer->spelling_tag()))
for(auto const& range : ns::spellcheck(text.data(), text.data() + text.size(), buffer->spelling_language(), buffer->spelling_tag()))
{
_misspellings.set(r->first + range->first, true);
_misspellings.set(r->first + range->last, false);
D(DBF_Buffer_Spelling, bug("bad: %s\n", text.substr(range->first, range->last - range->first).c_str()););
_misspellings.set(r.first + range.first, true);
_misspellings.set(r.first + range.last, false);
D(DBF_Buffer_Spelling, bug("bad: %s\n", text.substr(range.first, range.last - range.first).c_str()););
}
}
}

View File

@@ -69,8 +69,8 @@ namespace
{
static regexp::pattern_t newline("\n");
std::string res = replace(str, newline, format_string::format_string_t(" "));
iterate(it, records)
res = replace(res, it->regexp, it->format, it->repeat);
for(auto const& it : records)
res = replace(res, it.regexp, it.format, it.repeat);
res = replace(res, newline, format_string::format_string_t(""));
return res;
@@ -106,13 +106,13 @@ namespace ng
all_scopes.insert(all_scopes.end(), it->second);
std::map<scope::scope_t, transform_t> transforms;
iterate(it, all_scopes)
for(auto const& it : all_scopes)
{
if(plist::is_true(bundles::value_for_setting("showInSymbolList", *it)))
if(plist::is_true(bundles::value_for_setting("showInSymbolList", it)))
{
plist::any_t const& symbolTransformationValue = bundles::value_for_setting("symbolTransformation", *it);
plist::any_t const& symbolTransformationValue = bundles::value_for_setting("symbolTransformation", it);
std::string const* symbolTransformation = boost::get<std::string>(&symbolTransformationValue);
transforms.emplace(*it, transform_t(symbolTransformation ? *symbolTransformation : ""));
transforms.emplace(it, transform_t(symbolTransformation ? *symbolTransformation : ""));
}
}
@@ -143,8 +143,8 @@ namespace ng
std::map<size_t, std::string> symbols_t::symbols (buffer_t const* buffer) const
{
std::map<size_t, std::string> res;
iterate(it, _symbols)
res.insert(*it);
for(auto const& it : _symbols)
res.insert(it);
return res;
}