summaryrefslogtreecommitdiff
path: root/boost/spirit/home/support/iterators/line_pos_iterator.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/spirit/home/support/iterators/line_pos_iterator.hpp')
-rw-r--r--boost/spirit/home/support/iterators/line_pos_iterator.hpp34
1 files changed, 22 insertions, 12 deletions
diff --git a/boost/spirit/home/support/iterators/line_pos_iterator.hpp b/boost/spirit/home/support/iterators/line_pos_iterator.hpp
index 0b2aec8ce9..558fdca5d5 100644
--- a/boost/spirit/home/support/iterators/line_pos_iterator.hpp
+++ b/boost/spirit/home/support/iterators/line_pos_iterator.hpp
@@ -1,6 +1,7 @@
/*==============================================================================
Copyright (c) 2001-2011 Joel de Guzman
Copyright (c) 2010 Bryce Lelbach
+ Copyright (c) 2014 Tomoki Imai
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -126,17 +127,30 @@ namespace boost { namespace spirit
inline Iterator get_line_start(Iterator lower_bound, Iterator current)
{
Iterator latest = lower_bound;
-
+ bool prev_was_newline = false;
for (Iterator i = lower_bound; i != current; ++i) {
- switch (*i) {
- case '\r':
- case '\n':
- latest = i;
- }
+ if (prev_was_newline) {
+ latest = i;
+ }
+ prev_was_newline = (*i == '\r') || (*i == '\n');
+ }
+ if (prev_was_newline) {
+ latest = current;
}
-
return latest;
}
+
+ template <class Iterator>
+ inline Iterator get_line_end(Iterator current, Iterator upper_bound)
+ {
+ for (Iterator i = current; i != upper_bound; ++i) {
+ if ((*i == '\n') || (*i == '\r')) {
+ return i;
+ }
+ }
+ return upper_bound;
+ }
+
template <class Iterator>
inline iterator_range<Iterator>
@@ -145,11 +159,7 @@ namespace boost { namespace spirit
Iterator upper_bound)
{
Iterator first = get_line_start(lower_bound, current);
- Iterator last = get_line_start(current, upper_bound);
-
- if (last == current)
- last = upper_bound;
-
+ Iterator last = get_line_end(current, upper_bound);
return iterator_range<Iterator>(first, last);
}