From: Joe Neeman Date: Fri, 29 Sep 2006 22:54:07 +0000 (+0000) Subject: lily/source-file.cc (get_line): fix off-by-one error X-Git-Tag: cvs/HEAD~52 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=af78c7fc26abecd26f40fc08ef1b8019a6d82e5a;p=lilypond.git lily/source-file.cc (get_line): fix off-by-one error and clean up some of the logic --- diff --git a/ChangeLog b/ChangeLog index 0497dd03c0..d12ce34778 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-09-30 Joe Neeman + + * lily/source-file.cc (get_line): fix off-by-one error + and clean up some of the logic + 2006-09-29 Joe Neeman * lily/page-breaking.cc (make_pages): honour the first-page-number diff --git a/lily/source-file.cc b/lily/source-file.cc index 56b2e57d72..57d67b464b 100644 --- a/lily/source-file.cc +++ b/lily/source-file.cc @@ -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 ()); - 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 (), - 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