]> git.donarmstrong.com Git - lilypond.git/commitdiff
lily/source-file.cc (get_line): fix off-by-one error
authorJoe Neeman <joeneeman@gmail.com>
Fri, 29 Sep 2006 22:54:07 +0000 (22:54 +0000)
committerJoe Neeman <joeneeman@gmail.com>
Fri, 29 Sep 2006 22:54:07 +0000 (22:54 +0000)
and clean up some of the logic

ChangeLog
lily/source-file.cc

index 0497dd03c071deacdfbf9b6b0e4dd88368fba8fd..d12ce347788bee3fe83811f2afffe900244e2b2e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-09-30  Joe Neeman  <joeneeman@gmail.com>
+
+       * lily/source-file.cc (get_line): fix off-by-one error
+       and clean up some of the logic
+
 2006-09-29  Joe Neeman  <joeneeman@gmail.com>
 
        * lily/page-breaking.cc (make_pages): honour the first-page-number
index 56b2e57d72937d0a2501fa83c132b0e3ee5af16d..57d67b464b6e16b83d14ca454b841197ba2bcacc 100644 (file)
@@ -326,23 +326,13 @@ Source_file::get_line (char const *pos_str0) const
   if (!newline_locations_.size ())
     return 1;
 
-  vsize lo = 0;
-  vsize hi = newline_locations_.size ();
+  /* this will find the '\n' character at the end of our line */
+  vsize lo = lower_bound (newline_locations_,
+                         pos_str0,
+                         less<char const*> ());
 
-  if (newline_locations_[lo] > pos_str0)
-    return 1;
-
-  if (newline_locations_[hi - 1] < pos_str0)
-    return hi;
-
-  lo = lower_bound (newline_locations_,
-                   pos_str0,
-                   less<char const*> (),
-                   lo, hi);
-
-  if (*pos_str0 == '\n')
-    lo--;
-  return lo + 2 + line_offset_;
+  /* the return value will be indexed from 1 */
+  return lo + 1 + line_offset_;
 }
 
 void