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;
67 for (std::size_t i = line; i < line+
num_lines; i++)
79 sys::file_stat fs (fname);
82 (*current_liboctave_error_handler) (
"no such file, '%s'", fname.c_str ());
84 std::size_t sz = fs.size ();
87 std::ios::in | std::ios::binary);
91 std::string buf (sz+1, 0);
93 file.read (&buf[0], sz+1);
96 (*current_liboctave_error_handler)
97 (
"error reading file %s", fname.c_str ());
108 std::deque<std::size_t> tmp_offsets;
110 tmp_offsets.push_back (0);
112 std::size_t
len = buf.length ();
114 for (std::size_t i = 0; i <
len; i++)
118 if (c ==
'\r' && ++i <
len)
123 tmp_offsets.push_back (i+1);
125 tmp_offsets.push_back (i);
128 tmp_offsets.push_back (i+1);
131 tmp_offsets.push_back (
len-1);
133 std::size_t
n = tmp_offsets.size ();
135 std::vector<std::size_t> retval (
n);
137 for (
auto& elt : tmp_offsets)
static OCTAVE_API std::vector< std::size_t > get_line_offsets(const std::string &buf)
std::size_t num_lines(void) const
static OCTAVE_API std::string snarf_file(const std::string &fname)
OCTAVE_API std::string get_line(std::size_t line) const
OCTAVE_API 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)
static std::string get_line(FILE *fp)