26 #if defined (HAVE_CONFIG_H)
47 if (
line < m_offsets.size ())
49 std::size_t bol = m_offsets[
line-1];
50 std::size_t eol = m_offsets[
line];
52 while (eol > 0 && eol > bol
53 && (m_file_buf[eol-1] ==
'\n' || m_file_buf[eol-1] ==
'\r'))
56 retval = m_file_buf.substr (bol, eol - bol);
62 std::deque<std::string>
65 std::deque<std::string> retval;
76 file_info::snarf_file (
const std::string& fname)
80 sys::file_stat fs (fname);
83 (*current_liboctave_error_handler) (
"no such file, '%s'", fname.c_str ());
85 std::size_t sz = fs.size ();
88 std::ios::in | std::ios::binary);
92 std::string buf (sz+1, 0);
94 file.read (&buf[0], sz+1);
97 (*current_liboctave_error_handler)
98 (
"error reading file %s", fname.c_str ());
107 std::vector<std::size_t>
108 file_info::get_line_offsets (
const std::string& buf)
110 std::deque<std::size_t> tmp_offsets;
112 tmp_offsets.push_back (0);
114 std::size_t
len = buf.length ();
116 for (std::size_t i = 0; i <
len; i++)
120 if (c ==
'\r' && ++i <
len)
125 tmp_offsets.push_back (i+1);
127 tmp_offsets.push_back (i);
130 tmp_offsets.push_back (i+1);
133 tmp_offsets.push_back (
len-1);
135 std::size_t
n = tmp_offsets.size ();
137 std::vector<std::size_t> retval (
n);
139 for (
auto& elt : tmp_offsets)
145 OCTAVE_END_NAMESPACE(
octave)
std::size_t num_lines() const
std::string get_line(std::size_t line) const
std::deque< std::string > get_lines(std::size_t line, std::size_t num_lines) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
std::ifstream ifstream(const std::string &filename, const std::ios::openmode mode)