& Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/
+#include "config.h"
+
#include <stdio.h>
#include <assert.h>
#if HAVE_SSTREAM
pos_str0_ = to_str0 ();
init_port();
+
+ for (int i = 0; i < length_; i++)
+ if (contents_str0_[i] == '\n')
+ newline_locations_.push (contents_str0_ + i);
}
void
std::istream*
Source_file::get_istream ()
{
- /*
- if (!name_string_.length ())
- return &cin;
- */
-
if (!istream_)
{
if (length ()) // can-t this be done without such a hack?
{
delete istream_;
istream_ = 0;
- delete contents_str0_;
+ delete[] contents_str0_;
}
Slice
if (!in_b (pos_str0))
return 0;
- int i = 1;
- char const* scan_str0 = to_str0 ();
- if (!scan_str0)
- return 0;
-
- while (scan_str0 < pos_str0)
- if (*scan_str0++ == '\n')
- i++;
- return i;
+ int lo=0;
+ int hi = newline_locations_.size();
+
+ binary_search_bounds (newline_locations_,
+ pos_str0,
+ Link_array<char>::default_compare,
+ &lo, &hi);
+
+ return lo;
}
int