Files
textmate/Frameworks/text/tests/t_tokenize.cc
Allan Odgaard c2397484b8 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
2014-03-03 10:34:13 +07:00

18 lines
640 B
C++

#include <text/tokenize.h>
static std::string replace_token (std::string const& str, char token, std::string const& replacement)
{
std::vector<std::string> v;
for(auto const& component : text::tokenize(str.begin(), str.end(), token))
v.push_back(component);
return text::join(v, replacement);
}
void test_tokenize ()
{
OAK_ASSERT_EQ(replace_token( "foo/bar", '/', " » "), "foo » bar" );
OAK_ASSERT_EQ(replace_token("/foo/bar", '/', " » "), " » foo » bar" );
OAK_ASSERT_EQ(replace_token( "foo/bar/", '/', " » "), "foo » bar » ");
OAK_ASSERT_EQ(replace_token("/foo/bar/", '/', " » "), " » foo » bar » ");
}