Update CMake to 3.2.1 in .travis.yml
[supertux.git] / test / string_util_numeric_sort_test.cpp
1 //  SuperTux
2 //  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmail.com>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #include <algorithm>
18 #include <fstream>
19 #include <iostream>
20 #include <vector>
21
22 #include "util/string_util.hpp"
23
24 int main(int argc, char** argv)
25 {
26   std::vector<std::string> lines;
27   
28   // read files from stdin or files
29   std::string line;
30   if (argc > 1)
31   {
32     for(int i = 1; i < argc; ++i)
33     {
34       std::ifstream in(argv[i]);
35       while(std::getline(in, line))
36       {
37         lines.push_back(line);
38       }
39     }
40   }
41   else
42   {
43     while(std::getline(std::cin, line))
44     {
45       lines.push_back(line);
46     }
47   }
48   
49   // sort lines
50   std::sort(lines.begin(), lines.end(), StringUtil::numeric_less);
51
52   // output the sorted text
53   for(std::vector<std::string>::iterator i = lines.begin(); i != lines.end(); ++i)
54   {
55     std::cout << *i << std::endl;
56   }
57
58   return 0;
59 }
60
61 /* EOF */