$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r61333 - trunk/libs/spirit/example/scheme/support
From: joel_at_[hidden]
Date: 2010-04-17 04:44:20
Author: djowel
Date: 2010-04-17 04:44:20 EDT (Sat, 17 Apr 2010)
New Revision: 61333
URL: http://svn.boost.org/trac/boost/changeset/61333
Log:
line_pos_iterator: a lighweight line position iterator.
Text files modified: 
   trunk/libs/spirit/example/scheme/support/line_pos_iterator.hpp |    26 +++++++++++++++++++++++++-              
   1 files changed, 25 insertions(+), 1 deletions(-)
Modified: trunk/libs/spirit/example/scheme/support/line_pos_iterator.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/support/line_pos_iterator.hpp	(original)
+++ trunk/libs/spirit/example/scheme/support/line_pos_iterator.hpp	2010-04-17 04:44:20 EDT (Sat, 17 Apr 2010)
@@ -16,7 +16,9 @@
     // line_pos_iterator: a lighweight line position iterator. This iterator
     // adapter only stores the current line number, nothing else. Unlike
     // spirit classic's position_iterator, it does not store the column
-    // number and does not need an end iterator.
+    // number and does not need an end iterator. The current column can be
+    // computed, if needed. Some utilities line oriented are provided
+    // including computation of the current column.
     ///////////////////////////////////////////////////////////////////////////
     template <typename Iterator>
     class line_pos_iterator
@@ -104,6 +106,28 @@
             last = upper_bound;
         return iterator_range<Iterator>(first, last);
     }
+
+    // Get the current column. Applicable to any iterator.
+    template <typename Iterator>
+    inline std::size_t
+    get_column(
+        Iterator lower_bound, Iterator current, int tabs = 4)
+    {
+        std::size_t column = 1;
+        Iterator first = get_line_start(lower_bound, current);
+        for (Iterator i = first; i != current; ++i)
+        {
+            switch (*i)
+            {
+                case '\t':
+                    column += tabs - (column - 1) % tabs;
+                    break;
+                default:
+                    ++column;
+            }
+        }
+        return column;
+    }
 }
 
 #endif