]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/boost/spirit/home/support/iterators/line_pos_iterator.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / boost / spirit / home / support / iterators / line_pos_iterator.hpp
index 0b2aec8ce9fdc6ab829d02b6f838153fa30b16a8..558fdca5d54d73a16793a81a7c67571212339f24 100644 (file)
@@ -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);
     }