1// Pingus - A free Lemmings clone
2// Copyright (C) 2007 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 "util/line_iterator.hpp"
18
19LineIterator::LineIterator(const std::string& str)
20 : first(str.begin()),
21 last(str.end()),
22 line_end(str.begin())
23{
24}
25
26LineIterator::LineIterator(std::string::const_iterator first_,
27 std::string::const_iterator last_)
28 : first(first_),
29 last(last_),
30 line_end(first_)
31{
32}
33
34bool
35LineIterator::next()
36{
37 if (line_end == last || (line_end+1 == last && *first == '\n'))
38 {
39 return false;
40 }
41 else
42 {
43 if (first != line_end)
44 first = line_end + 1;
45
46 do {
47 ++line_end;
48 } while(line_end != last && *line_end != '\n');
49
50 return true;
51 }
52}
53
54std::string
55LineIterator::get()
56{
57 return std::string(first, line_end);
58}
59
60/* EOF */
61