annotate libinterp/corefcn/textscan.h @ 21490:243b04c97b56

textscan: Use references rather than pointers to stream objects * textscan.cc, textscan.h (textscan::scan, textscan::do_scan): Accept a reference to a std::istream rather than a pointer. (Ftextscan): Pass streams by reference.
author Mike Miller <mtmiller@octave.org>
date Fri, 18 Mar 2016 16:36:40 -0700
parents 9dbc8f8bc2d7
children ab0a19882615
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
1 /*
21467
3aa83b8ce94b * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21465
diff changeset
2
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
3 Copyright (C) 2015-2016 Lachlan Andrew, Monash University
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
4
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
5 This file is part of Octave.
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
6
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
10 option) any later version.
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
11
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
15 for more details.
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
16
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
20
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
21 */
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
22
21465
bca9aaef907a * textscan.h, textscan.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 21462
diff changeset
23 // @file
bca9aaef907a * textscan.h, textscan.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 21462
diff changeset
24 // Implementation of textscan, a versatile text parser.
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
25
21465
bca9aaef907a * textscan.h, textscan.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 21462
diff changeset
26 #if ! defined (octave_textscan_h)
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
27 #define octave_textscan_h 1
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
28
21474
deeb9b4b2846 * textscan.h: Add required #includes for types used in header
Mike Miller <mtmiller@octave.org>
parents: 21473
diff changeset
29 #include "octave-config.h"
deeb9b4b2846 * textscan.h: Add required #includes for types used in header
Mike Miller <mtmiller@octave.org>
parents: 21473
diff changeset
30
deeb9b4b2846 * textscan.h: Add required #includes for types used in header
Mike Miller <mtmiller@octave.org>
parents: 21473
diff changeset
31 #include <iosfwd>
deeb9b4b2846 * textscan.h: Add required #includes for types used in header
Mike Miller <mtmiller@octave.org>
parents: 21473
diff changeset
32 #include <list>
deeb9b4b2846 * textscan.h: Add required #includes for types used in header
Mike Miller <mtmiller@octave.org>
parents: 21473
diff changeset
33 #include <string>
deeb9b4b2846 * textscan.h: Add required #includes for types used in header
Mike Miller <mtmiller@octave.org>
parents: 21473
diff changeset
34
21484
a6717373a0cd make delimited_stream, textscan_format_elt, and textscan_format_list private
John W. Eaton <jwe@octave.org>
parents: 21474
diff changeset
35 // These are only needed as arguments to private functions, so they
a6717373a0cd make delimited_stream, textscan_format_elt, and textscan_format_list private
John W. Eaton <jwe@octave.org>
parents: 21474
diff changeset
36 // are also treated as private.
a6717373a0cd make delimited_stream, textscan_format_elt, and textscan_format_list private
John W. Eaton <jwe@octave.org>
parents: 21474
diff changeset
37
a6717373a0cd make delimited_stream, textscan_format_elt, and textscan_format_list private
John W. Eaton <jwe@octave.org>
parents: 21474
diff changeset
38 class delimited_stream;
a6717373a0cd make delimited_stream, textscan_format_elt, and textscan_format_list private
John W. Eaton <jwe@octave.org>
parents: 21474
diff changeset
39 class textscan_format_elt;
a6717373a0cd make delimited_stream, textscan_format_elt, and textscan_format_list private
John W. Eaton <jwe@octave.org>
parents: 21474
diff changeset
40 class textscan_format_list;
a6717373a0cd make delimited_stream, textscan_format_elt, and textscan_format_list private
John W. Eaton <jwe@octave.org>
parents: 21474
diff changeset
41
21474
deeb9b4b2846 * textscan.h: Add required #includes for types used in header
Mike Miller <mtmiller@octave.org>
parents: 21473
diff changeset
42 #include "Cell.h"
deeb9b4b2846 * textscan.h: Add required #includes for types used in header
Mike Miller <mtmiller@octave.org>
parents: 21473
diff changeset
43 #include "ov.h"
21484
a6717373a0cd make delimited_stream, textscan_format_elt, and textscan_format_list private
John W. Eaton <jwe@octave.org>
parents: 21474
diff changeset
44 #include "ovl.h"
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
45
21484
a6717373a0cd make delimited_stream, textscan_format_elt, and textscan_format_list private
John W. Eaton <jwe@octave.org>
parents: 21474
diff changeset
46 // Main class to implement textscan. Read data and parse it
a6717373a0cd make delimited_stream, textscan_format_elt, and textscan_format_list private
John W. Eaton <jwe@octave.org>
parents: 21474
diff changeset
47 // according to a format.
a6717373a0cd make delimited_stream, textscan_format_elt, and textscan_format_list private
John W. Eaton <jwe@octave.org>
parents: 21474
diff changeset
48 //
a6717373a0cd make delimited_stream, textscan_format_elt, and textscan_format_list private
John W. Eaton <jwe@octave.org>
parents: 21474
diff changeset
49 // The calling sequence is
a6717373a0cd make delimited_stream, textscan_format_elt, and textscan_format_list private
John W. Eaton <jwe@octave.org>
parents: 21474
diff changeset
50 //
a6717373a0cd make delimited_stream, textscan_format_elt, and textscan_format_list private
John W. Eaton <jwe@octave.org>
parents: 21474
diff changeset
51 // textscan scanner ();
a6717373a0cd make delimited_stream, textscan_format_elt, and textscan_format_list private
John W. Eaton <jwe@octave.org>
parents: 21474
diff changeset
52 // scanner.scan (...);
21467
3aa83b8ce94b * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21465
diff changeset
53
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
54 class
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
55 OCTINTERP_API
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
56 textscan
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
57 {
21467
3aa83b8ce94b * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21465
diff changeset
58 public:
3aa83b8ce94b * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21465
diff changeset
59
21488
9dbc8f8bc2d7 move textscan constructor out of header file
John W. Eaton <jwe@octave.org>
parents: 21484
diff changeset
60 textscan (void);
21467
3aa83b8ce94b * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21465
diff changeset
61
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
62 ~textscan (void) { }
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
63
21490
243b04c97b56 textscan: Use references rather than pointers to stream objects
Mike Miller <mtmiller@octave.org>
parents: 21488
diff changeset
64 octave_value scan (std::istream& isp, const octave_value_list& args);
21467
3aa83b8ce94b * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21465
diff changeset
65
3aa83b8ce94b * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21465
diff changeset
66 private:
3aa83b8ce94b * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21465
diff changeset
67
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
68 friend class textscan_format_list;
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
69
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
70 std::string buf;
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
71
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
72 // Three cases for delim_table and delim_list
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
73 // 1. delim_table empty, delim_list empty: whitespace delimiters
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
74 // 2. delim_table = look-up table of delim chars, delim_list empty.
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
75 // 3. delim_table non-empty, delim_list = Cell array of delim strings
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
76
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
77 std::string whitespace_table;
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
78
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
79 // delim_table[i] == '\0' if i is not a delimiter.
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
80 std::string delim_table;
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
81
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
82 // String of delimiter characters.
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
83 std::string delims;
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
84
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
85 Cell comment_style;
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
86
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
87 // How far ahead to look to detect an open comment.
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
88 int comment_len;
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
89
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
90 // First character of open comment.
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
91 int comment_char;
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
92
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
93 octave_idx_type buffer_size;
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
94
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
95 std::string date_locale;
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
96
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
97 // 'inf' and 'nan' for formatted_double.
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
98 Cell inf_nan;
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
99
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
100 // Array of strings of delimiters.
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
101 Cell delim_list;
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
102
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
103 // Longest delimiter.
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
104 int delim_len;
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
105
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
106 octave_value empty_value;
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
107 std::string exp_chars;
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
108 int header_lines;
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
109 Cell treat_as_empty;
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
110
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
111 // Longest string to treat as "N/A".
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
112 int treat_as_empty_len;
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
113
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
114 std::string whitespace;
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
115
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
116 short eol1;
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
117 short eol2;
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
118 short return_on_error;
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
119
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
120 bool collect_output;
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
121 bool multiple_delims_as_one;
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
122 bool default_exp;
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
123 bool numeric_delim;
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
124
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
125 octave_idx_type lines;
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
126
21490
243b04c97b56 textscan: Use references rather than pointers to stream objects
Mike Miller <mtmiller@octave.org>
parents: 21488
diff changeset
127 octave_value do_scan (std::istream& isp, textscan_format_list& fmt_list,
21484
a6717373a0cd make delimited_stream, textscan_format_elt, and textscan_format_list private
John W. Eaton <jwe@octave.org>
parents: 21474
diff changeset
128 octave_idx_type ntimes);
a6717373a0cd make delimited_stream, textscan_format_elt, and textscan_format_list private
John W. Eaton <jwe@octave.org>
parents: 21474
diff changeset
129
a6717373a0cd make delimited_stream, textscan_format_elt, and textscan_format_list private
John W. Eaton <jwe@octave.org>
parents: 21474
diff changeset
130 void parse_options (const octave_value_list& args,
a6717373a0cd make delimited_stream, textscan_format_elt, and textscan_format_list private
John W. Eaton <jwe@octave.org>
parents: 21474
diff changeset
131 textscan_format_list& fmt_list);
a6717373a0cd make delimited_stream, textscan_format_elt, and textscan_format_list private
John W. Eaton <jwe@octave.org>
parents: 21474
diff changeset
132
21473
e9978387898a * textscan.h, textscan.cc: Rename dstr class to delimited_stream.
John W. Eaton <jwe@octave.org>
parents: 21468
diff changeset
133 int read_format_once (delimited_stream &isp, textscan_format_list& fmt_list,
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
134 std::list<octave_value> & retval,
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
135 Array<octave_idx_type> row, int& done_after);
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
136
21473
e9978387898a * textscan.h, textscan.cc: Rename dstr class to delimited_stream.
John W. Eaton <jwe@octave.org>
parents: 21468
diff changeset
137 void scan_one (delimited_stream& is, const textscan_format_elt& fmt,
e9978387898a * textscan.h, textscan.cc: Rename dstr class to delimited_stream.
John W. Eaton <jwe@octave.org>
parents: 21468
diff changeset
138 octave_value& ov, Array<octave_idx_type> row);
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
139
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
140 // Methods to process a particular conversion specifier.
21473
e9978387898a * textscan.h, textscan.cc: Rename dstr class to delimited_stream.
John W. Eaton <jwe@octave.org>
parents: 21468
diff changeset
141 double read_double (delimited_stream& is,
e9978387898a * textscan.h, textscan.cc: Rename dstr class to delimited_stream.
John W. Eaton <jwe@octave.org>
parents: 21468
diff changeset
142 const textscan_format_elt& fmt) const;
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
143
21473
e9978387898a * textscan.h, textscan.cc: Rename dstr class to delimited_stream.
John W. Eaton <jwe@octave.org>
parents: 21468
diff changeset
144 void scan_complex (delimited_stream& is, const textscan_format_elt& fmt,
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
145 Complex& val) const;
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
146
21473
e9978387898a * textscan.h, textscan.cc: Rename dstr class to delimited_stream.
John W. Eaton <jwe@octave.org>
parents: 21468
diff changeset
147 int scan_bracket (delimited_stream& is, const char *pattern,
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
148 std::string& val) const;
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
149
21473
e9978387898a * textscan.h, textscan.cc: Rename dstr class to delimited_stream.
John W. Eaton <jwe@octave.org>
parents: 21468
diff changeset
150 int scan_caret (delimited_stream& is, const char *, std::string& val) const;
e9978387898a * textscan.h, textscan.cc: Rename dstr class to delimited_stream.
John W. Eaton <jwe@octave.org>
parents: 21468
diff changeset
151
e9978387898a * textscan.h, textscan.cc: Rename dstr class to delimited_stream.
John W. Eaton <jwe@octave.org>
parents: 21468
diff changeset
152 void scan_string (delimited_stream& is, const textscan_format_elt& fmt,
e9978387898a * textscan.h, textscan.cc: Rename dstr class to delimited_stream.
John W. Eaton <jwe@octave.org>
parents: 21468
diff changeset
153 std::string& val) const;
e9978387898a * textscan.h, textscan.cc: Rename dstr class to delimited_stream.
John W. Eaton <jwe@octave.org>
parents: 21468
diff changeset
154
e9978387898a * textscan.h, textscan.cc: Rename dstr class to delimited_stream.
John W. Eaton <jwe@octave.org>
parents: 21468
diff changeset
155 void scan_cstring (delimited_stream& is, const textscan_format_elt& fmt,
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
156 std::string& val) const;
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
157
21473
e9978387898a * textscan.h, textscan.cc: Rename dstr class to delimited_stream.
John W. Eaton <jwe@octave.org>
parents: 21468
diff changeset
158 void scan_qstring (delimited_stream& is, const textscan_format_elt& fmt,
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
159 std::string& val);
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
160
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
161 // Helper methods.
21473
e9978387898a * textscan.h, textscan.cc: Rename dstr class to delimited_stream.
John W. Eaton <jwe@octave.org>
parents: 21468
diff changeset
162 std::string read_until (delimited_stream& is, const Cell& delimiters,
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
163 const std::string& ends) const;
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
164
21473
e9978387898a * textscan.h, textscan.cc: Rename dstr class to delimited_stream.
John W. Eaton <jwe@octave.org>
parents: 21468
diff changeset
165 int lookahead (delimited_stream& is, const Cell& targets, int max_len,
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
166 bool case_sensitive = true) const;
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
167
21473
e9978387898a * textscan.h, textscan.cc: Rename dstr class to delimited_stream.
John W. Eaton <jwe@octave.org>
parents: 21468
diff changeset
168 char *get_field (delimited_stream& isp, unsigned int width) const;
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
169
21473
e9978387898a * textscan.h, textscan.cc: Rename dstr class to delimited_stream.
John W. Eaton <jwe@octave.org>
parents: 21468
diff changeset
170 bool match_literal (delimited_stream& isp, const textscan_format_elt& elem);
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
171
21473
e9978387898a * textscan.h, textscan.cc: Rename dstr class to delimited_stream.
John W. Eaton <jwe@octave.org>
parents: 21468
diff changeset
172 int skip_whitespace (delimited_stream& is, bool EOLstop = false);
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
173
21473
e9978387898a * textscan.h, textscan.cc: Rename dstr class to delimited_stream.
John W. Eaton <jwe@octave.org>
parents: 21468
diff changeset
174 int skip_delim (delimited_stream& is);
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
175
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
176 bool is_delim (unsigned char ch) const
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
177 {
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
178 return ((delim_table.length () == 0
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
179 && (isspace (ch) || ch == eol1 || ch == eol2))
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
180 || delim_table[ch] != '\0');
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
181 }
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
182
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
183 bool isspace (unsigned int ch) const { return whitespace_table[ch & 0xff]; }
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
184
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
185 // True if the only delimiter is whitespace.
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
186 bool whitespace_delim (void) const { return delim_table.length () == 0; }
21468
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
187
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
188 // No copying!
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
189
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
190 textscan (const textscan&);
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
191
7d06afd924be * textscan.h, textscan.cc: More style fixes.
John W. Eaton <jwe@octave.org>
parents: 21467
diff changeset
192 textscan& operator = (const textscan&);
21462
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
193 };
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
194
b7d1e93c0702 initial implementation of textscan in C++
Lachlan Andrew <lachlanbis@gmail.com>
parents:
diff changeset
195 #endif