]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/source-file.cc
(get_counts): use multibyte variable.
[lilypond.git] / lily / source-file.cc
index cead386ae9166eddde96d50be24ce949baac4b0e..bb38ffdb0994879a5ad11ab1c9a9362445ec023d 100644 (file)
@@ -38,10 +38,11 @@ Source_file::load_stdin ()
   int c;
   while ((c = fgetc (stdin)) != EOF)
     characters_.push_back (c);
-
-  characters_.push_back (0);
 }
 
+/*
+  return contents of FILENAME. *Not 0-terminated!* 
+ */
 vector<char>
 gulp_file (string filename, int desired_size)
 {
@@ -101,9 +102,10 @@ Source_file::Source_file (string filename, string data)
   name_ = filename;
 
   characters_.resize (data.length ());
-
   copy (data.begin (), data.end (), characters_.begin ());
 
+  characters_.push_back (0);
+  
   init_port ();
 
   for (vsize i = 0; i < characters_.size (); i++)
@@ -122,9 +124,10 @@ Source_file::Source_file (string filename_string)
   else
     {
       characters_ = gulp_file (filename_string, -1);
-      characters_.push_back (0);
     }
 
+  characters_.push_back (0);
+
   init_port ();
 
   for (vsize i = 0; i < characters_.size (); i++)
@@ -198,7 +201,6 @@ Source_file::name_string () const
 Source_file::~Source_file ()
 {
   delete istream_;
-  istream_ = 0;
 }
 
 Slice
@@ -284,6 +286,7 @@ Source_file::get_counts (char const *pos_str0,
       size_t thislen = mbrtowc (multibyte, line_chars, left, &state);
 #else
       size_t thislen = 1;
+      (void) multibyte;
 #endif /* !HAVE_MBRTOWC */
 
       /* Stop converting at invalid character;
@@ -324,23 +327,13 @@ Source_file::get_line (char const *pos_str0) const
   if (!newline_locations_.size ())
     return 1;
 
-  vsize lo = 0;
-  vsize hi = newline_locations_.size ();
-
-  if (newline_locations_[lo] > pos_str0)
-    return 1;
-
-  if (newline_locations_[hi - 1] < pos_str0)
-    return hi;
-
-  binary_search_bounds (newline_locations_,
-                       (char const*&)pos_str0,
-                       default_compare,
-                       &lo, &hi);
+  /* this will find the '\n' character at the end of our line */
+  vsize lo = lower_bound (newline_locations_,
+                         pos_str0,
+                         less<char const*> ());
 
-  if (*pos_str0 == '\n')
-    lo--;
-  return lo + 2 + line_offset_;
+  /* the return value will be indexed from 1 */
+  return lo + 1 + line_offset_;
 }
 
 void