26 #if defined (HAVE_CONFIG_H)
90 convert_to_valid_int (
const octave_value& tc,
int& conv_err)
130 get_size (
double d,
const std::string& who)
135 ::error (
"%s: NaN invalid as size specification", who.c_str ());
142 ::error (
"%s: negative value invalid as size specification",
145 static const double out_of_range_top
148 if (
d >= out_of_range_top)
149 ::error (
"%s: dimension too large for Octave's index type",
161 bool& one_elt_size_spec,
const std::string& who)
166 one_elt_size_spec =
false;
175 one_elt_size_spec =
true;
179 dnc = (dnr == 0.0) ? 0.0 : 1.0;
181 else if (sz_len == 2)
186 ::error (
"%s: infinite value invalid as size specification",
192 ::error (
"%s: invalid size specification (must be 2-D)", who.c_str ());
194 nr = get_size (dnr, who);
198 nc = get_size (dnc, who);
203 ::error (
"%s: size too large for Octave's index type", who.c_str ());
208 expand_char_class (
const std::string& s)
212 std::size_t
len = s.length ();
218 unsigned char c = s[i++];
220 if (c ==
'-' && i > 1 && i <
len
221 && (
static_cast<unsigned char> (s[i-2])
222 <=
static_cast<unsigned char> (s[i])))
227 for (c = s[i-2]+1; c < s[i]; c++)
235 if (c !=
'-' || i ==
len)
248 enum special_conversion
250 whitespace_conversion = 1,
251 literal_conversion = 2,
255 scanf_format_elt (
const std::string& txt =
"",
int w = 0,
bool d =
false,
256 char typ =
'\0',
char mod =
'\0',
257 const std::string& ch_class =
"")
258 :
text (txt), width (
w), discard (
d), type (typ),
259 modifier (
mod), char_class (ch_class)
262 scanf_format_elt (
const scanf_format_elt&) =
default;
264 scanf_format_elt& operator = (
const scanf_format_elt&) =
default;
266 ~scanf_format_elt () =
default;
285 std::string char_class;
293 scanf_format_list (
const std::string& fmt =
"");
295 OCTAVE_DISABLE_COPY_MOVE (scanf_format_list)
297 ~scanf_format_list ();
306 std::size_t length ()
const {
return m_fmt_elts.size (); }
308 const scanf_format_elt * first ()
314 const scanf_format_elt * current ()
const
316 return length () > 0 ? m_fmt_elts[m_curr_idx] :
nullptr;
319 const scanf_format_elt * next (
bool cycle =
true)
321 static scanf_format_elt dummy
322 (
"", 0,
false, scanf_format_elt::null,
'\0',
"");
326 if (m_curr_idx >= length ())
337 void printme ()
const;
339 bool ok ()
const {
return (m_nconv >= 0); }
341 operator bool ()
const {
return ok (); }
343 bool all_character_conversions ();
345 bool all_numeric_conversions ();
349 void add_elt_to_list (
int width,
bool discard,
char type,
char modifier,
350 const std::string& char_class =
"");
352 void process_conversion (
const std::string& s, std::size_t& i,
353 std::size_t
n,
int& width,
bool& discard,
354 char& type,
char& modifier);
356 int finish_conversion (
const std::string& s, std::size_t& i, std::size_t
n,
357 int width,
bool discard,
char& type,
367 std::size_t m_curr_idx;
370 std::deque<scanf_format_elt *> m_fmt_elts;
373 std::ostringstream m_buf;
377 scanf_format_list::scanf_format_list (
const std::string& s)
378 : m_nconv (0), m_curr_idx (0), m_fmt_elts (), m_buf ()
380 std::size_t
n = s.length ();
385 bool discard =
false;
386 char modifier =
'\0';
389 bool have_more =
true;
399 process_conversion (s, i,
n, width, discard, type, modifier);
401 have_more = (m_buf.tellp () != 0);
403 else if (isspace (s[i]))
405 type = scanf_format_elt::whitespace_conversion;
412 while (++i <
n && isspace (s[i]))
415 add_elt_to_list (width, discard, type, modifier);
421 type = scanf_format_elt::literal_conversion;
427 while (i <
n && ! isspace (s[i]) && s[i] !=
'%')
430 add_elt_to_list (width, discard, type, modifier);
443 add_elt_to_list (width, discard, type, modifier);
449 scanf_format_list::~scanf_format_list ()
451 std::size_t
n = m_fmt_elts.size ();
453 for (std::size_t i = 0; i <
n; i++)
455 scanf_format_elt *elt = m_fmt_elts[i];
461 scanf_format_list::add_elt_to_list (
int width,
bool discard,
char type,
463 const std::string& char_class)
465 std::string
text = m_buf.str ();
469 scanf_format_elt *elt
470 =
new scanf_format_elt (
text, width, discard, type,
471 modifier, char_class);
473 m_fmt_elts.push_back (elt);
481 scanf_format_list::process_conversion (
const std::string& s, std::size_t& i,
482 std::size_t
n,
int& width,
483 bool& discard,
char& type,
493 bool have_width =
false;
509 case '0':
case '1':
case '2':
case '3':
case '4':
510 case '5':
case '6':
case '7':
case '8':
case '9':
516 width = 10 * width + c -
'0';
519 while (i <
n && isdigit (s[i]))
522 width = 10 * width + c -
'0';
528 case 'h':
case 'l':
case 'L':
529 if (modifier !=
'\0')
536 case 'd':
case 'i':
case 'o':
case 'u':
case 'x':
547 case 'e':
case 'f':
case 'g':
560 case 'c':
case 's':
case 'p':
case '%':
case '[':
561 if (modifier !=
'\0')
570 if (finish_conversion (s, i,
n, width, discard,
571 type, modifier) == 0)
589 scanf_format_list::finish_conversion (
const std::string& s, std::size_t& i,
590 std::size_t
n,
int width,
bool discard,
591 char& type,
char modifier)
595 std::string char_class;
597 std::size_t beg_idx = std::string::npos;
598 std::size_t end_idx = std::string::npos;
630 else if (s[i] ==
']')
634 while (i <
n && s[i] !=
']')
637 if (i <
n && s[i] ==
']')
644 retval = m_nconv = -1;
654 if (beg_idx != std::string::npos && end_idx != std::string::npos)
655 char_class = expand_char_class (s.substr (beg_idx,
656 end_idx - beg_idx + 1));
658 add_elt_to_list (width, discard, type, modifier, char_class);
665 scanf_format_list::printme ()
const
667 std::size_t
n = m_fmt_elts.size ();
669 for (std::size_t i = 0; i <
n; i++)
671 scanf_format_elt *elt = m_fmt_elts[i];
674 <<
"width: " << elt->width <<
"\n"
675 <<
"discard: " << elt->discard <<
"\n"
678 if (elt->type == scanf_format_elt::literal_conversion)
679 std::cerr <<
"literal text\n";
680 else if (elt->type == scanf_format_elt::whitespace_conversion)
681 std::cerr <<
"whitespace\n";
683 std::cerr << elt->type <<
"\n";
686 <<
"modifier: " << elt->modifier <<
"\n"
693 scanf_format_list::all_character_conversions ()
695 std::size_t
n = m_fmt_elts.size ();
699 for (std::size_t i = 0; i <
n; i++)
701 scanf_format_elt *elt = m_fmt_elts[i];
705 case 'c':
case 's':
case '%':
case '[':
case '^':
706 case scanf_format_elt::literal_conversion:
707 case scanf_format_elt::whitespace_conversion:
723 scanf_format_list::all_numeric_conversions ()
725 std::size_t
n = m_fmt_elts.size ();
729 for (std::size_t i = 0; i <
n; i++)
731 scanf_format_elt *elt = m_fmt_elts[i];
735 case 'd':
case 'i':
case 'o':
case 'u':
case 'x':
case 'X':
736 case 'e':
case 'f':
case 'g':
case 'E':
case 'G':
756 printf_format_elt (
const std::string& txt =
"",
int n = 0,
int w = -1,
757 int p = -1,
const std::string&
f =
"",
758 char typ =
'\0',
char mod =
'\0')
759 :
text (txt), args (
n), fw (
w), prec (p), flags (
f),
760 type (typ), modifier (
mod)
763 printf_format_elt (
const printf_format_elt&) =
default;
765 printf_format_elt& operator = (
const printf_format_elt&) =
default;
767 ~printf_format_elt () =
default;
797 printf_format_list (
const std::string& fmt =
"");
799 OCTAVE_DISABLE_COPY_MOVE (printf_format_list)
801 ~printf_format_list ();
805 const printf_format_elt * first ()
811 const printf_format_elt * current ()
const
813 return length () > 0 ? m_fmt_elts[m_curr_idx] :
nullptr;
816 std::size_t length ()
const {
return m_fmt_elts.size (); }
818 const printf_format_elt * next (
bool cycle =
true)
822 if (m_curr_idx >= length ())
833 bool last_elt_p () {
return (m_curr_idx + 1 == length ()); }
835 void printme ()
const;
837 bool ok ()
const {
return (m_nconv >= 0); }
839 operator bool ()
const {
return ok (); }
843 void add_elt_to_list (
int args,
const std::string& flags,
int fw,
844 int prec,
char type,
char modifier);
846 void process_conversion (
const std::string& s, std::size_t& i,
848 int& args, std::string& flags,
int& fw,
849 int& prec,
char& modifier,
char& type);
851 void finish_conversion (
const std::string& s, std::size_t& i,
int args,
852 const std::string& flags,
int fw,
int prec,
853 char modifier,
char& type);
862 std::size_t m_curr_idx;
865 std::deque<printf_format_elt *> m_fmt_elts;
868 std::ostringstream m_buf;
872 printf_format_list::printf_format_list (
const std::string& s)
873 : m_nconv (0), m_curr_idx (0), m_fmt_elts (), m_buf ()
875 std::size_t
n = s.length ();
883 char modifier =
'\0';
886 bool have_more =
true;
887 bool empty_buf =
true;
891 printf_format_elt *elt
892 =
new printf_format_elt (
"", args, fw, prec, flags, type, modifier);
894 m_fmt_elts.push_back (elt);
902 empty_buf = (m_buf.tellp () == 0);
910 process_conversion (s, i,
n, args, flags, fw, prec,
919 have_more = (m_buf.tellp () != 0);
922 add_elt_to_list (args, flags, fw, prec, type, modifier);
947 add_elt_to_list (args, flags, fw, prec, type, modifier);
954 printf_format_list::~printf_format_list ()
956 std::size_t
n = m_fmt_elts.size ();
958 for (std::size_t i = 0; i <
n; i++)
960 printf_format_elt *elt = m_fmt_elts[i];
966 printf_format_list::add_elt_to_list (
int args,
const std::string& flags,
967 int fw,
int prec,
char type,
970 std::string
text = m_buf.str ();
974 printf_format_elt *elt
975 =
new printf_format_elt (
text, args, fw, prec, flags,
978 m_fmt_elts.push_back (elt);
986 printf_format_list::process_conversion (
const std::string& s, std::size_t& i,
987 std::size_t
n,
int& args,
988 std::string& flags,
int& fw,
989 int& prec,
char& modifier,
1007 case '-':
case '+':
case ' ':
case '0':
case '#':
1034 std::string tmp = s.substr (i);
1035 sscanf (tmp.c_str (),
"%d%n", &fw, &nn);
1038 while (i <
n && isdigit (s[i]))
1043 if (i <
n && s[i] ==
'.')
1067 std::string tmp = s.substr (i);
1068 sscanf (tmp.c_str (),
"%d%n", &prec, &nn);
1071 while (i <
n && isdigit (s[i]))
1085 case 'h':
case 'l':
case 'L':
1095 finish_conversion (s, i, args, flags, fw, prec, modifier, type);
1101 printf_format_list::finish_conversion (
const std::string& s, std::size_t& i,
1102 int args,
const std::string& flags,
1103 int fw,
int prec,
char modifier,
1108 case 'd':
case 'i':
case 'o':
case 'x':
case 'X':
1110 if (modifier ==
'L')
1117 case 'f':
case 'e':
case 'E':
case 'g':
case 'G':
1118 if (modifier ==
'h' || modifier ==
'l')
1125 case 's':
case 'p':
case '%':
1126 if (modifier !=
'\0')
1139 if (type !=
'%' || args != 0)
1145 add_elt_to_list (args, flags, fw, prec, type, modifier);
1156 printf_format_list::printme ()
const
1158 std::size_t
n = m_fmt_elts.size ();
1160 for (std::size_t i = 0; i <
n; i++)
1162 printf_format_elt *elt = m_fmt_elts[i];
1165 <<
"args: " << elt->args <<
"\n"
1166 <<
"flags: '" << elt->flags <<
"'\n"
1167 <<
"width: " << elt->fw <<
"\n"
1168 <<
"prec: " << elt->prec <<
"\n"
1169 <<
"type: '" << elt->type <<
"'\n"
1170 <<
"modifier: '" << elt->modifier <<
"'\n"
1179 pown (
double x,
unsigned int n)
1183 for (
unsigned int d =
n;
d;
d >>= 1)
1222 delimited_stream (std::istream& is,
const std::string& delimiters,
1225 delimited_stream (std::istream& is,
const delimited_stream& ds);
1227 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (delimited_stream)
1229 ~delimited_stream ();
1235 if (m_idx >= m_last)
1241 int refresh_buf (
bool initialize =
false);
1248 return eof () ? std::istream::traits_type::eof () : *m_idx++;
1250 return get_undelim ();
1261 {
return eof () ? std::istream::traits_type::eof () : *m_idx; }
1264 int peek_undelim ();
1270 void putback (
char = 0) {
if (! eof ()) --m_idx; }
1272 int getline (std::string& dest,
char delim);
1276 char * read (
char *buffer,
int size,
char *&new_start);
1280 char * tellg () {
return m_idx; }
1282 void seekg (
char *old_idx) { m_idx = old_idx; }
1286 return (m_eob == m_buf + m_overlap && m_i_stream.eof ())
1287 || (m_flags & std::ios_base::eofbit);
1290 operator const void *()
1291 {
return (! eof () && ! m_flags) ?
this :
nullptr; }
1293 bool fail () {
return m_flags & std::ios_base::failbit; }
1295 std::ios_base::iostate rdstate () {
return m_flags; }
1297 void setstate (std::ios_base::iostate
m) { m_flags = m_flags |
m; }
1299 void clear (std::ios_base::iostate
m
1300 = (std::ios_base::eofbit & ~std::ios_base::eofbit))
1302 m_flags = m_flags &
m;
1308 void progress_benchmark () { m_progress_marker = m_idx; }
1310 bool no_progress () {
return m_progress_marker == m_idx; }
1315 std::ptrdiff_t remaining ()
1317 if (m_eob < m_buf + m_bufsize)
1318 return m_eob - m_idx;
1329 std::istream& m_i_stream;
1345 std::ptrdiff_t m_overlap;
1354 const std::string m_delims;
1357 std::streampos m_buf_in_file;
1360 char *m_progress_marker;
1362 std::ios_base::iostate m_flags;
1369 delimited_stream::delimited_stream (std::istream& is,
1370 const std::string& delimiters,
1371 int longest_lookahead,
1373 : m_bufsize (bsize), m_i_stream (is), m_longest (longest_lookahead),
1374 m_delims (delimiters),
1375 m_flags (std::ios::failbit & ~std::ios::failbit)
1377 m_buf =
new char[m_bufsize];
1378 m_eob = m_buf + m_bufsize;
1380 m_progress_marker = m_idx;
1385 delimited_stream::delimited_stream (std::istream& is,
1386 const delimited_stream& ds)
1387 : delimited_stream (is, ds.m_delims, ds.m_longest, ds.m_bufsize)
1390 delimited_stream::~delimited_stream ()
1395 m_i_stream.clear ();
1396 m_i_stream.seekg (m_buf_in_file);
1397 m_i_stream.read (m_buf, m_idx - m_buf - m_overlap);
1407 delimited_stream::get_undelim ()
1412 setstate (std::ios_base::failbit);
1413 return std::istream::traits_type::eof ();
1424 setstate (std::ios_base::eofbit);
1425 retval = std::istream::traits_type::eof ();
1431 if (m_idx >= m_last)
1432 m_delimited =
false;
1441 delimited_stream::peek_undelim ()
1443 int retval = get_undelim ();
1455 delimited_stream::refresh_buf (
bool initialize)
1458 return std::istream::traits_type::eof ();
1465 std::size_t old_remaining = m_eob - m_idx;
1466 std::size_t old_overlap = 0;
1468 if (initialize || (m_idx - m_buf <= 0))
1472 old_overlap = m_overlap;
1479 m_overlap =
std::min (m_overlap, m_idx - m_buf - 1);
1484 if (old_remaining + m_overlap > 0)
1486 m_buf_in_file += (m_idx - old_overlap - m_buf);
1487 std::memmove (m_buf, m_idx - m_overlap, m_overlap + old_remaining);
1490 m_buf_in_file = m_i_stream.tellg ();
1493 m_progress_marker -= m_idx - m_overlap - m_buf;
1494 m_idx = m_buf + m_overlap;
1497 if (! m_i_stream.eof ())
1499 m_i_stream.read (m_buf + m_overlap + old_remaining,
1500 m_bufsize - m_overlap - old_remaining);
1501 gcount = m_i_stream.gcount ();
1506 m_eob = m_buf + m_overlap + old_remaining + gcount;
1510 m_delimited =
false;
1512 if (m_eob != m_buf + m_overlap)
1517 retval = std::istream::traits_type::eof ();
1523 for (m_last = m_eob - m_longest; m_last - m_buf - m_overlap >= 0;
1526 if (m_delims.find (*m_last) != std::string::npos)
1530 if (m_last < m_buf + m_overlap)
1531 m_delimited =
false;
1537 if (retval == std::istream::traits_type::eof ())
1550 delimited_stream::read (
char *buffer,
int size,
char *&prior_tell)
1554 if (m_eob - m_idx >= size)
1559 m_delimited =
false;
1568 if (m_eob - prior_tell + size < m_bufsize)
1582 if (m_eob - m_idx > size)
1587 m_delimited =
false;
1591 if (size <= m_bufsize)
1594 memset (m_eob, 0, size + (m_idx - m_buf));
1602 for (i = 0; i < size && ! eof (); i++)
1603 *buffer++ = get_undelim ();
1605 memset (buffer, 0, size - i);
1617 delimited_stream::getline (std::string& out,
char delim)
1619 int len = out.length ();
1622 while ((ch = get_undelim ()) != delim
1623 && ch != std::istream::traits_type::eof ())
1645 enum special_conversion
1647 whitespace_conversion = 1,
1648 literal_conversion = 2
1651 textscan_format_elt () =
delete;
1653 textscan_format_elt (
const std::string& txt,
int w = 0,
int p = -1,
1654 int bw = 0,
bool dis =
false,
char typ =
'\0',
1655 const std::string& ch_class = std::string ())
1656 :
text (txt), width (
w), prec (p), bitwidth (bw),
1657 char_class (ch_class), type (typ), discard (dis),
1658 numeric (typ ==
'd' || typ ==
'u' || type ==
'f' || type ==
'n')
1661 OCTAVE_DEFAULT_COPY_MOVE_DELETE (textscan_format_elt)
1678 std::string char_class;
1696 textscan_format_list
1700 textscan_format_list (
const std::string& fmt = std::string (),
1701 const std::string& who =
"textscan");
1702 OCTAVE_DISABLE_COPY_MOVE (textscan_format_list)
1704 ~textscan_format_list ();
1713 std::size_t
numel ()
const {
return m_fmt_elts.size (); }
1715 const textscan_format_elt * first ()
1721 const textscan_format_elt * current ()
const
1723 return numel () > 0 ? m_fmt_elts[m_curr_idx] :
nullptr;
1726 const textscan_format_elt * next (
bool cycle =
true)
1730 if (m_curr_idx >=
numel ())
1741 void printme ()
const;
1743 bool ok ()
const {
return (m_nconv >= 0); }
1745 operator const void *()
const {
return ok () ? this :
nullptr; }
1751 bool set_from_first;
1756 int read_first_row (delimited_stream& is, textscan& ts);
1758 std::list<octave_value> out_buf ()
const
1759 {
return (m_output_container); }
1763 void add_elt_to_list (
unsigned int width,
int prec,
int bitwidth,
1766 const std::string& char_class = std::string ());
1768 void process_conversion (
const std::string& s, std::size_t& i,
1771 std::string parse_char_class (
const std::string& pattern)
const;
1773 int finish_conversion (
const std::string& s, std::size_t& i, std::size_t
n,
1774 unsigned int width,
int prec,
int bitwidth,
1776 bool discard,
char& type);
1785 std::size_t m_curr_idx;
1788 std::deque<textscan_format_elt *> m_fmt_elts;
1791 std::list<octave_value> m_output_container;
1794 std::ostringstream m_buf;
1812 textscan (
const std::string& who_arg =
"textscan",
1813 const std::string& encoding =
"utf-8");
1815 OCTAVE_DISABLE_COPY_MOVE (textscan)
1817 ~textscan () =
default;
1819 octave_value scan (std::istream& isp,
const std::string& fmt,
1826 friend class textscan_format_list;
1828 octave_value do_scan (std::istream& isp, textscan_format_list& fmt_list,
1832 textscan_format_list& fmt_list);
1834 int read_format_once (delimited_stream& isp, textscan_format_list& fmt_list,
1835 std::list<octave_value>& retval,
1838 void scan_one (delimited_stream& is,
const textscan_format_elt& fmt,
1842 double read_double (delimited_stream& is,
1843 const textscan_format_elt& fmt)
const;
1845 void scan_complex (delimited_stream& is,
const textscan_format_elt& fmt,
1848 int scan_bracket (delimited_stream& is,
const std::string& pattern,
1849 std::string& val)
const;
1851 int scan_caret (delimited_stream& is,
const std::string& pattern,
1852 std::string& val)
const;
1854 void scan_string (delimited_stream& is,
const textscan_format_elt& fmt,
1855 std::string& val)
const;
1857 void scan_cstring (delimited_stream& is,
const textscan_format_elt& fmt,
1858 std::string& val)
const;
1860 void scan_qstring (delimited_stream& is,
const textscan_format_elt& fmt,
1864 std::string read_until (delimited_stream& is,
const Cell& delimiters,
1865 const std::string& ends)
const;
1867 int lookahead (delimited_stream& is,
const Cell& targets,
int max_len,
1868 bool case_sensitive =
true)
const;
1870 bool match_literal (delimited_stream& isp,
const textscan_format_elt& elem);
1872 int skip_whitespace (delimited_stream& is,
bool EOLstop =
true);
1874 int skip_delim (delimited_stream& is);
1876 bool is_delim (
unsigned char ch)
const
1878 return ((m_delim_table.empty ()
1879 && (isspace (ch) || ch == m_eol1 || ch == m_eol2))
1880 || m_delim_table[ch] !=
'\0');
1883 bool isspace (
unsigned int ch)
const
1884 {
return m_whitespace_table[ch & 0xff]; }
1887 bool whitespace_delim ()
const {
return m_delim_table.empty (); }
1894 std::string m_encoding;
1903 std::string m_whitespace_table;
1906 std::string m_delim_table;
1909 std::string m_delims;
1911 Cell m_comment_style;
1921 std::string m_date_locale;
1933 std::string m_exp_chars;
1935 Cell m_treat_as_empty;
1938 int m_treat_as_empty_len;
1940 std::string m_whitespace;
1944 short m_return_on_error;
1946 bool m_collect_output;
1947 bool m_multiple_delims_as_one;
1953 textscan_format_list::textscan_format_list (
const std::string& s,
1954 const std::string& who_arg)
1955 : who (who_arg), set_from_first (false), has_string (false),
1956 m_nconv (0), m_curr_idx (0), m_fmt_elts (), m_buf ()
1958 std::size_t
n = s.length ();
1962 unsigned int width = -1;
1965 bool discard =
false;
1968 bool have_more =
true;
1982 set_from_first =
true;
1987 set_from_first =
false;
1993 if (s[i] ==
'%' && (i+1 ==
n || s[i+1] !=
'%'))
1997 process_conversion (s, i,
n);
2005 have_more = (m_buf.tellp () != 0);
2007 else if (isspace (s[i]))
2009 while (++i <
n && isspace (s[i]))
2016 type = textscan_format_elt::literal_conversion;
2023 while (i <
n && ! isspace (s[i])
2024 && (s[i] !=
'%' || (i+1 <
n && s[i+1] ==
'%')))
2032 add_elt_to_list (width, prec, bitwidth,
octave_value (),
2047 add_elt_to_list (width, prec, bitwidth,
octave_value (), discard, type);
2053 textscan_format_list::~textscan_format_list ()
2055 std::size_t
n =
numel ();
2057 for (std::size_t i = 0; i <
n; i++)
2059 textscan_format_elt *elt = m_fmt_elts[i];
2065 textscan_format_list::add_elt_to_list (
unsigned int width,
int prec,
2067 bool discard,
char type,
2068 const std::string& char_class)
2070 std::string
text = m_buf.str ();
2072 if (!
text.empty ())
2074 textscan_format_elt *elt
2075 =
new textscan_format_elt (
text, width, prec, bitwidth, discard,
2079 m_output_container.push_back (val_type);
2081 m_fmt_elts.push_back (elt);
2089 textscan_format_list::process_conversion (
const std::string& s,
2090 std::size_t& i, std::size_t
n)
2095 bool discard =
false;
2101 bool have_width =
false;
2117 case '0':
case '1':
case '2':
case '3':
case '4':
2118 case '5':
case '6':
case '7':
case '8':
case '9':
2124 width = width * 10 + c -
'0';
2127 while (i <
n && isdigit (s[i]))
2130 width = width * 10 + c -
'0';
2134 if (i <
n && s[i] ==
'.')
2138 while (i <
n && isdigit (s[i]))
2141 prec = prec * 10 + c -
'0';
2151 m_buf << (type = s[i++]);
2163 else if (s[i] ==
'1' && i+1 <
n && s[i+1] ==
'6')
2173 else if (s[i] ==
'3' && i+1 <
n && s[i+1] ==
'2')
2179 else if (s[i] ==
'6' && i+1 <
n && s[i+1] ==
'4')
2207 m_buf << (type = s[i++]);
2211 if (s[i] ==
'3' && i+1 <
n && s[i+1] ==
'2')
2218 else if (s[i] ==
'6' && i+1 <
n && s[i+1] ==
'4')
2232 m_buf << (type = s[i++]);
2237 case 's':
case 'q':
case '[':
case 'c':
2240 m_buf << (type = s[i++]);
2251 width =
static_cast<unsigned int> (-1);
2254 if (finish_conversion (s, i,
n, width, prec, bitwidth, val_type,
2255 discard, type) == 0)
2261 error (
"%s: '%%%c' is not a valid format specifier",
2262 who.c_str (), s[i]);
2285 textscan_format_list::parse_char_class (
const std::string& pattern)
const
2287 int len = pattern.length ();
2291 std::string retval (256,
'\0');
2292 std::string mask (256,
'\0');
2294 int in = 0, out = 0;
2295 unsigned char ch, prev = 0;
2304 mask[pattern[in]] =
'\1';
2305 retval[out++] = pattern[in++];
2307 bool prev_was_range =
false;
2308 bool prev_prev_was_range =
false;
2309 for (; in <
len; in++)
2311 bool was_range =
false;
2316 if (prev ==
'-' && in > 1 && isalnum (ch) && ! prev_prev_was_range)
2318 unsigned char start_of_range = pattern[in-2];
2319 if (start_of_range < ch
2320 && ((isupper (ch) && isupper (start_of_range))
2321 || (islower (ch) && islower (start_of_range))
2322 || (isdigit (ch) && isdigit (start_of_range))
2328 for (
int i = start_of_range; i <= ch; i++)
2330 if (mask[i] ==
'\0')
2340 if (mask[ch]++ == 0)
2344 "%s: [...] contains two '%c's",
2347 if (prev ==
'-' && mask[
'-'] >= 2)
2349 (
"Octave:textscan-pattern",
2350 "%s: [...] contains two '-'s outside range expressions",
2354 prev_prev_was_range = prev_was_range;
2355 prev_was_range = was_range;
2361 for (
int i = 0; i < 256; i++)
2366 retval.resize (out);
2372 textscan_format_list::finish_conversion (
const std::string& s, std::size_t& i,
2373 std::size_t
n,
unsigned int width,
2374 int prec,
int bitwidth,
2380 std::string char_class;
2382 std::size_t beg_idx = std::string::npos;
2383 std::size_t end_idx = std::string::npos;
2407 else if (s[i] ==
']')
2411 while (i <
n && s[i] !=
']')
2414 if (i <
n && s[i] ==
']')
2421 retval = m_nconv = -1;
2427 if (beg_idx != std::string::npos && end_idx != std::string::npos)
2428 char_class = parse_char_class (s.substr (beg_idx,
2429 end_idx - beg_idx + 1));
2431 add_elt_to_list (width, prec, bitwidth, val_type, discard, type,
2439 textscan_format_list::printme ()
const
2441 std::size_t
n =
numel ();
2443 for (std::size_t i = 0; i <
n; i++)
2445 textscan_format_elt *elt = m_fmt_elts[i];
2448 <<
"width: " << elt->width <<
"\n"
2449 <<
"digits " << elt->prec <<
"\n"
2450 <<
"bitwidth: " << elt->bitwidth <<
"\n"
2451 <<
"discard: " << elt->discard <<
"\n"
2454 if (elt->type == textscan_format_elt::literal_conversion)
2455 std::cerr <<
"literal text\n";
2456 else if (elt->type == textscan_format_elt::whitespace_conversion)
2457 std::cerr <<
"whitespace\n";
2459 std::cerr << elt->type <<
"\n";
2471 textscan_format_list::read_first_row (delimited_stream& is, textscan& ts)
2474 std::string first_line (20,
' ');
2476 is.getline (first_line,
static_cast<char> (ts.m_eol2));
2478 if (! first_line.empty () && first_line.back () == ts.m_eol1)
2479 first_line.pop_back ();
2481 std::istringstream strstr (first_line);
2482 delimited_stream ds (strstr, is);
2488 int max_empty = 1000;
2494 bool already_skipped_delim =
false;
2495 ts.skip_whitespace (ds,
false);
2496 ds.progress_benchmark ();
2497 ts.scan_complex (ds, *m_fmt_elts[0], val);
2500 ds.clear (ds.rdstate () & ~std::ios::failbit);
2508 if (ds.no_progress ())
2513 already_skipped_delim =
true;
2521 if (val.imag () == 0)
2526 m_output_container.push_back (val_type);
2528 if (! already_skipped_delim)
2531 if (ds.no_progress ())
2537 m_output_container.pop_front ();
2541 m_fmt_elts.push_back (
new textscan_format_elt (*m_fmt_elts[0]));
2546 textscan::textscan (
const std::string& who_arg,
const std::string& encoding)
2547 : m_who (who_arg), m_encoding (encoding), m_buf (), m_whitespace_table (),
2548 m_delim_table (), m_delims (), m_comment_style (), m_comment_len (0),
2549 m_comment_char (-2), m_buffer_size (0), m_date_locale (),
2550 m_inf_nan (init_inf_nan ()),
2551 m_empty_value (numeric_limits<double>::
NaN ()),
2552 m_exp_chars (
"edED"), m_header_lines (0), m_treat_as_empty (),
2553 m_treat_as_empty_len (0), m_whitespace (
" \b\t"), m_eol1 (
'\r'),
2554 m_eol2 (
'\n'), m_return_on_error (1), m_collect_output (false),
2555 m_multiple_delims_as_one (false), m_default_exp (true), m_lines (0)
2559 textscan::scan (std::istream& isp,
const std::string& fmt,
2563 textscan_format_list fmt_list (fmt);
2565 parse_options (options, fmt_list);
2573 std::ios::iostate state = isp.rdstate ();
2576 isp.setstate (state);
2582 textscan::do_scan (std::istream& isp, textscan_format_list& fmt_list,
2587 if (fmt_list.num_conversions () == -1)
2588 error (
"%s: invalid format specified", m_who.c_str ());
2590 if (fmt_list.num_conversions () == 0)
2591 error (
"%s: no valid format conversion specifiers", m_who.c_str ());
2595 for (
int i = 0; i < m_header_lines && isp; i++)
2596 getline (isp, dummy,
static_cast<char> (m_eol2));
2601 int max_lookahead =
std::max ({m_comment_len, m_treat_as_empty_len,
2607 buf_size = m_buffer_size;
2608 else if (ntimes > 0)
2612 buf_size =
std::max (buf_size, ntimes);
2615 delimited_stream is (isp,
2616 (m_delims.empty () ? m_whitespace +
"\r\n"
2618 max_lookahead, buf_size);
2629 if (m_multiple_delims_as_one)
2635 if (fmt_list.set_from_first)
2637 err = fmt_list.read_first_row (is, *
this);
2640 done_after = fmt_list.numel () + 1;
2645 done_after = fmt_list.out_buf ().size () + 1;
2647 std::list<octave_value> out = fmt_list.out_buf ();
2655 std::vector<bool> merge_with_prev (fmt_list.numel ());
2657 if (m_collect_output)
2660 for (
const auto& col : out)
2662 if (col.type_id () == prev_type
2663 || (fmt_list.set_from_first && prev_type != -1))
2664 merge_with_prev[conv++] =
true;
2666 merge_with_prev[conv++] =
false;
2668 prev_type = col.type_id ();
2674 if (fmt_list.num_conversions () == 0)
2675 error (
"%s: No conversions specified", m_who.c_str ());
2681 row < ntimes || ntimes == -1;
2684 if (row == 0 || row >= size)
2687 for (
auto& col : out)
2692 err = read_format_once (is, fmt_list, out, row_idx, done_after);
2694 if ((err & ~1) > 0 || ! is || (m_lines >= ntimes && ntimes > -1))
2699 if ((err & 4) && ! m_return_on_error)
2700 error (
"%s: Read error in field %d of row %" OCTAVE_IDX_TYPE_FORMAT,
2701 m_who.c_str (), done_after + 1, row + 1);
2704 bool uneven_columns =
false;
2706 uneven_columns =
true;
2707 else if (isp.eof ())
2710 isp.seekg (-1, std::ios_base::end);
2711 int last_char = isp.get ();
2712 isp.setstate (isp.eofbit);
2713 uneven_columns = (last_char != m_eol1 && last_char != m_eol2);
2722 done_after = out.size () + 1;
2724 int valid_rows = (row == ntimes
2726 : ((err & 1) && (err & 8)) ? row : row+1);
2731 if (! m_collect_output)
2734 for (
auto& col : out)
2737 if (i == done_after && uneven_columns)
2754 for (
auto& col : out)
2756 if (! merge_with_prev[conv++])
2758 if (prev_type != -1)
2765 prev_type = col.type_id ();
2769 ra_idx(1) = group_size++;
2784 textscan::read_double (delimited_stream& is,
2785 const textscan_format_elt& fmt)
const
2788 unsigned int width_left = fmt.width;
2792 int ch = is.peek_undelim ();
2797 ch = is.peek_undelim ();
2805 ch = is.peek_undelim ();
2813 if (ch >=
'0' && ch <=
'9')
2815 while (width_left-- && is && (ch = is.get ()) >=
'0' && ch <=
'9')
2816 retval = retval * 10 + (ch -
'0');
2821 if (ch ==
'.' && width_left)
2823 double multiplier = 1;
2824 int precision = fmt.prec;
2829 if (precision == -1)
2835 for (i = 0; i < precision; i++)
2837 if (width_left-- && is && (ch = is.get ()) >=
'0' && ch <=
'9')
2838 retval += (ch -
'0') * (multiplier *= 0.1);
2847 if ((i == precision || ! width_left) && (ch = is.get ()) >=
'5'
2849 retval += multiplier;
2861 while (width_left-- && is && (ch = is.get ()) >=
'0' && ch <=
'9')
2868 bool used_exp =
false;
2869 if (valid && width_left > 1 && m_exp_chars.find (ch) != std::string::npos)
2871 int ch1 = is.peek_undelim ();
2872 if (ch1 ==
'-' || ch1 ==
'+' || (ch1 >=
'0' && ch1 <=
'9'))
2883 else if (ch1 ==
'-')
2890 while (width_left-- && is && (ch = is.get_undelim ()) >=
'0' && ch <=
'9')
2892 exp = exp*10 + ch -
'0';
2896 if (ch != std::istream::traits_type::eof () && width_left)
2899 double multiplier = pown (10, exp);
2901 retval *= multiplier;
2903 retval /= multiplier;
2909 if (! used_exp && ch != std::istream::traits_type::eof () && width_left)
2913 if (! valid && width_left >= 3 && is.remaining () >= 3)
2915 int i = lookahead (is, m_inf_nan, 3,
false);
2929 is.setstate (std::ios::failbit);
2931 is.setstate (is.rdstate () & ~std::ios::failbit);
2933 return retval * sign;
2941 textscan::scan_complex (delimited_stream& is,
const textscan_format_elt& fmt,
2946 bool as_empty =
false;
2949 int ch = is.peek_undelim ();
2950 if (ch ==
'+' || ch ==
'-')
2953 int ch2 = is.peek_undelim ();
2954 if (ch2 ==
'i' || ch2 ==
'j')
2959 if (is.peek_undelim () ==
'n')
2961 char *pos = is.tellg ();
2962 std::ios::iostate state = is.rdstate ();
2965 ch2 = is.get_undelim ();
2970 : -numeric_limits<double>::
Inf ());
2982 im = (ch ==
'+') ? value : -value;
2990 char *pos = is.tellg ();
2991 std::ios::iostate state = is.rdstate ();
2994 re = read_double (is, fmt);
2997 if (m_treat_as_empty.numel ()
3002 for (
int i = 0; i < m_treat_as_empty.numel (); i++)
3004 if (ch == m_treat_as_empty (i).string_value ()[0])
3020 std::string look_buf (m_treat_as_empty_len,
'\0');
3021 char *look = is.read (&look_buf[0], look_buf.size (), pos);
3027 for (
int i = 0; i < m_treat_as_empty.numel (); i++)
3029 std::string s = m_treat_as_empty (i).string_value ();
3030 if (!
strncmp (s.c_str (), look, s.size ()))
3034 is.read (&look_buf[0], s.size (), pos);
3041 if (! is.eof () && ! as_empty)
3043 state = is.rdstate ();
3045 ch = is.peek_undelim ();
3047 if (ch ==
'i' || ch ==
'j')
3053 else if (ch ==
'+' || ch ==
'-')
3057 state = is.rdstate ();
3062 im = read_double (is, fmt);
3066 if (is.peek_undelim () ==
'i' || is.peek_undelim () ==
'j')
3080 val = m_empty_value.scalar_value ();
3088 textscan::scan_caret (delimited_stream& is,
const std::string& pattern,
3089 std::string& val)
const
3091 int c1 = std::istream::traits_type::eof ();
3092 std::ostringstream obuf;
3094 while (is && ((c1 = (is && ! is.eof ())
3096 : std::istream::traits_type::eof ())
3097 != std::istream::traits_type::eof ())
3098 && pattern.find (c1) == std::string::npos)
3099 obuf << static_cast<char> (c1);
3103 if (c1 != std::istream::traits_type::eof ())
3113 textscan::read_until (delimited_stream& is,
const Cell& delimiters,
3114 const std::string& ends)
const
3116 std::string retval (
"");
3122 scan_caret (is, ends.c_str (), next);
3123 retval = retval + next;
3125 int last = (! is.eof ()
3126 ? is.get_undelim () : std::istream::traits_type::eof ());
3128 if (last != std::istream::traits_type::eof ())
3130 if (last == m_eol1 || last == m_eol2)
3133 retval = retval +
static_cast<char> (last);
3134 for (
int i = 0; i < delimiters.
numel (); i++)
3136 std::string delim = delimiters(i).string_value ();
3137 std::size_t start = (retval.length () > delim.length ()
3138 ? retval.length () - delim.length ()
3140 std::string may_match = retval.substr (start);
3141 if (may_match == delim)
3144 retval = retval.substr (0, start);
3152 while (! done && is && ! is.eof ());
3162 textscan::scan_string (delimited_stream& is,
const textscan_format_elt& fmt,
3163 std::string& val)
const
3165 if (m_delim_list.isempty ())
3168 unsigned int width = fmt.width;
3170 for (i = 0; i < width; i++)
3173 if (i >= val.length ())
3174 val.append (
std::max (val.length (),
3175 static_cast<std::size_t
> (16)),
'\0');
3177 int ch = is.get_undelim ();
3178 if (is_delim (ch) || ch == std::istream::traits_type::eof ())
3186 val = val.substr (0, i);
3190 std::string ends (m_delim_list.numel () + 2,
'\0');
3192 for (i = 0; i < m_delim_list.numel (); i++)
3194 std::string tmp = m_delim_list(i).string_value ();
3195 ends[i] = tmp.back ();
3199 val = textscan::read_until (is, m_delim_list, ends);
3203 if (m_encoding.compare (
"utf-8"))
3210 textscan::scan_bracket (delimited_stream& is,
const std::string& pattern,
3211 std::string& val)
const
3213 int c1 = std::istream::traits_type::eof ();
3214 std::ostringstream obuf;
3216 while (is && pattern.find (c1 = is.get_undelim ()) != std::string::npos)
3217 obuf << static_cast<char> (c1);
3220 if (c1 != std::istream::traits_type::eof ())
3230 textscan::scan_qstring (delimited_stream& is,
const textscan_format_elt& fmt,
3233 skip_whitespace (is);
3235 if (is.peek_undelim () !=
'"')
3236 scan_string (is, fmt, val);
3240 scan_caret (is, R
"(")", val);
3243 while (is && is.peek_undelim () ==
'"')
3248 scan_caret (is, R
"(")", val1);
3249 val = val + '"' + val1;
3255 if (m_encoding.compare (
"utf-8"))
3263 textscan::scan_cstring (delimited_stream& is,
const textscan_format_elt& fmt,
3264 std::string& val)
const
3266 val.resize (fmt.width);
3268 for (
unsigned int i = 0; is && i < fmt.width; i++)
3270 int ch = is.get_undelim ();
3271 if (ch != std::istream::traits_type::eof ())
3281 if (m_encoding.compare (
"utf-8"))
3288 textscan::scan_one (delimited_stream& is,
const textscan_format_elt& fmt,
3291 skip_whitespace (is);
3298 if (fmt.type ==
'f' || fmt.type ==
'n')
3301 skip_whitespace (is);
3302 scan_complex (is, fmt, v);
3304 if (! fmt.discard && ! is.fail ())
3306 if (fmt.bitwidth == 64)
3308 if (ov.
isreal () && v.imag () == 0)
3320 if (ov.
isreal () && v.imag () == 0)
3339 skip_whitespace (is);
3340 v = read_double (is, fmt);
3341 if (! fmt.discard && ! is.fail ())
3342 switch (fmt.bitwidth)
3383 if (fmt.type ==
'd')
3396 if (fmt.type ==
'd')
3410 if (is.fail () & ! fmt.discard)
3411 ov =
cat_op (ov, m_empty_value, row);
3415 std::string vv (
" ");
3419 scan_string (is, fmt, vv);
3423 scan_qstring (is, fmt, vv);
3427 scan_cstring (is, fmt, vv);
3431 scan_bracket (is, fmt.char_class.c_str (), vv);
3435 scan_caret (is, fmt.char_class.c_str (), vv);
3445 is.clear (is.rdstate () & ~std::ios_base::failbit);
3455 textscan::read_format_once (delimited_stream& is,
3456 textscan_format_list& fmt_list,
3457 std::list<octave_value>& retval,
3460 const textscan_format_elt *elem = fmt_list.first ();
3461 auto out = retval.begin ();
3462 bool no_conversions =
true;
3464 bool conversion_failed =
false;
3465 bool nothing_worked =
true;
3469 for (std::size_t i = 0; i < fmt_list.numel (); i++)
3471 bool this_conversion_failed =
false;
3480 warning (
"%s: conversion %c not yet implemented",
3481 m_who.c_str (), elem->type);
3493 scan_one (is, *elem, *out, row);
3496 case textscan_format_elt::literal_conversion :
3497 match_literal (is, *elem);
3501 error (
"Unknown format element '%c'", elem->type);
3506 if (! elem->discard)
3507 no_conversions =
false;
3511 is.clear (is.rdstate () & ~std::ios::failbit);
3515 if (m_delim_list.isempty ())
3517 if (! is_delim (is.peek_undelim ()))
3518 this_conversion_failed =
true;
3522 char *pos = is.tellg ();
3523 if (-1 == lookahead (is, m_delim_list, m_delim_len))
3524 this_conversion_failed =
true;
3531 if (! elem->discard)
3534 elem = fmt_list.next ();
3535 char *pos = is.tellg ();
3540 if (elem->type != textscan_format_elt::literal_conversion)
3542 else if (! is_delim (elem->text[0]))
3554 if (this_conversion_failed)
3556 if (is.tellg () == pos && ! conversion_failed)
3560 conversion_failed =
true;
3563 this_conversion_failed =
false;
3565 else if (! done && ! conversion_failed)
3566 nothing_worked =
false;
3570 is.setstate (std::ios::eofbit);
3572 return no_conversions
3573 + (is.eof () ? 2 : 0)
3574 + (conversion_failed ? 4 : 0)
3575 + (nothing_worked ? 8 : 0);
3581 textscan_format_list& fmt_list)
3583 int last = args.
length ();
3587 error (
"%s: %d parameters given, but only %d values",
3588 m_who.c_str (),
n-
n/2,
n/2);
3591 bool have_delims =
false;
3592 for (
int i = 0; i < last; i += 2)
3594 std::string param = args(i).xstring_value (
"%s: Invalid parameter type <%s> for parameter %d",
3596 args(i).type_name ().c_str (),
3598 std::transform (param.begin (), param.end (), param.begin (), ::tolower);
3600 if (param ==
"delimiter")
3602 bool invalid =
true;
3603 if (args(i+1).is_string ())
3607 m_delims = args(i+1).string_value ();
3608 if (args(i+1).is_sq_string ())
3611 else if (args(i+1).iscell ())
3615 m_delim_table =
" ";
3618 for (
int j = 0; j < m_delim_list.numel (); j++)
3620 if (! m_delim_list(j).is_string ())
3624 if (m_delim_list(j).is_sq_string ())
3635 error (
"%s: Delimiters must be either a string or cell array of strings",
3638 else if (param ==
"commentstyle")
3640 if (args(i+1).is_string ())
3643 m_comment_style =
Cell (args(i+1));
3645 else if (args(i+1).iscell ())
3648 int len = m_comment_style.numel ();
3649 if ((
len >= 1 && ! m_comment_style (0).is_string ())
3650 || (
len >= 2 && ! m_comment_style (1).is_string ())
3652 error (
"%s: CommentStyle must be either a string or cell array of one or two strings",
3656 error (
"%s: CommentStyle must be either a string or cell array of one or two strings",
3661 if (m_comment_style.numel () >= 1)
3663 m_comment_len = m_comment_style (0).string_value ().size ();
3664 m_comment_char = m_comment_style (0).string_value ()[0];
3667 else if (param ==
"treatasempty")
3669 bool invalid =
false;
3670 if (args(i+1).is_string ())
3672 m_treat_as_empty =
Cell (args(i+1));
3673 m_treat_as_empty_len = args(i+1).string_value ().size ();
3675 else if (args(i+1).iscell ())
3678 for (
int j = 0; j < m_treat_as_empty.numel (); j++)
3679 if (! m_treat_as_empty (j).is_string ())
3683 int k = m_treat_as_empty (j).string_value ().
size ();
3684 if (k > m_treat_as_empty_len)
3685 m_treat_as_empty_len = k;
3689 error (
"%s: TreatAsEmpty must be either a string or cell array of one or two strings",
3694 else if (param ==
"collectoutput")
3696 m_collect_output = args(i+1).xbool_value (
"%s: CollectOutput must be logical or numeric",
3699 else if (param ==
"emptyvalue")
3701 m_empty_value = args(i+1).xscalar_value (
"%s: EmptyValue must be numeric", m_who.c_str ());
3703 else if (param ==
"headerlines")
3705 m_header_lines = args(i+1).xscalar_value (
"%s: HeaderLines must be numeric", m_who.c_str ());
3707 else if (param ==
"bufsize")
3709 m_buffer_size = args(i+1).xscalar_value (
"%s: BufSize must be numeric", m_who.c_str ());
3711 else if (param ==
"multipledelimsasone")
3713 m_multiple_delims_as_one = args(i
3714 +1).xbool_value (
"%s: MultipleDelimsAsOne must be logical or numeric", m_who.c_str ());
3716 else if (param ==
"returnonerror")
3718 m_return_on_error = args(i+1).xbool_value (
"%s: ReturnOnError must be logical or numeric",
3721 else if (param ==
"whitespace")
3723 m_whitespace = args(i+1).xstring_value (
"%s: Whitespace must be a character string",
3726 else if (param ==
"expchars")
3728 m_exp_chars = args(i+1).xstring_value (
"%s: ExpChars must be a character string", m_who.c_str ());
3729 m_default_exp =
false;
3731 else if (param ==
"endofline")
3734 std::string s = args(i+1).xstring_value (R
"(%s: EndOfLine must be at most one character or '\r\n')",
3736 if (args(i+1).is_sq_string ())
3738 int l = s.length ();
3740 m_eol1 = m_eol2 = -2;
3742 m_eol1 = m_eol2 = s.c_str ()[0];
3745 m_eol1 = s.c_str ()[0];
3746 m_eol2 = s.c_str ()[1];
3747 if (m_eol1 !=
'\r' || m_eol2 !=
'\n')
3754 error (R
"(%s: EndOfLine must be at most one character or '\r\n')",
3758 error (
"%s: unrecognized option '%s'", m_who.c_str (), param.c_str ());
3762 for (
unsigned int j = 0; j < m_delims.length (); j++)
3764 m_whitespace.erase (std::remove (m_whitespace.begin (),
3765 m_whitespace.end (),
3767 m_whitespace.end ());
3769 for (
int j = 0; j < m_delim_list.numel (); j++)
3771 std::string delim = m_delim_list(j).string_value ();
3772 if (delim.length () == 1)
3773 m_whitespace.erase (std::remove (m_whitespace.begin (),
3774 m_whitespace.end (),
3776 m_whitespace.end ());
3779 m_whitespace_table = std::string (256,
'\0');
3780 for (
unsigned int i = 0; i < m_whitespace.length (); i++)
3781 m_whitespace_table[m_whitespace[i]] =
'1';
3785 if (! (m_whitespace.empty () && fmt_list.has_string))
3786 m_whitespace_table[
' '] =
'1';
3789 m_delim_table = std::string (256,
'\0');
3790 if (m_eol1 >= 0 && m_eol1 < 256)
3791 m_delim_table[m_eol1] =
'1';
3792 if (m_eol2 >= 0 && m_eol2 < 256)
3793 m_delim_table[m_eol2] =
'1';
3795 for (
unsigned int i = 0; i < 256; i++)
3798 m_delim_table[i] =
'1';
3801 for (
unsigned int i = 0; i < m_delims.length (); i++)
3802 m_delim_table[m_delims[i]] =
'1';
3809 textscan::skip_whitespace (delimited_stream& is,
bool EOLstop)
3811 int c1 = std::istream::traits_type::eof ();
3812 bool found_comment =
false;
3816 found_comment =
false;
3819 && (c1 = is.get_undelim ()) != std::istream::traits_type::eof ()
3820 && ( ( (c1 == m_eol1 || c1 == m_eol2) && ++m_lines && ! EOLstop)
3823 if (prev == m_eol1 && m_eol1 != m_eol2 && c1 == m_eol2)
3828 if (c1 == m_comment_char)
3831 char *pos = is.tellg ();
3832 std::ios::iostate state = is.rdstate ();
3834 std::string tmp (m_comment_len,
'\0');
3835 char *look = is.read (&tmp[0], m_comment_len-1, pos);
3836 if (is && m_comment_style.numel () > 0
3837 && !
strncmp (m_comment_style(0).string_value ().substr (1).c_str (),
3838 look, m_comment_len-1))
3840 found_comment =
true;
3843 if (m_comment_style.numel () == 1)
3845 std::string eol (3,
'\0');
3849 scan_caret (is, eol, dummy);
3850 c1 = is.get_undelim ();
3851 if (c1 == m_eol1 && m_eol1 != m_eol2
3852 && is.peek_undelim () == m_eol2)
3858 std::string end_c = m_comment_style(1).string_value ();
3860 std::string last = end_c.substr (end_c.size () - 1);
3861 std::string may_match (
"");
3865 scan_caret (is, last, dummy);
3868 may_match = may_match + dummy + last;
3869 if (may_match.length () > end_c.length ())
3871 std::size_t start = may_match.length ()
3873 may_match = may_match.substr (start);
3876 while (may_match != end_c && is && ! is.eof ());
3886 while (found_comment);
3888 if (c1 != std::istream::traits_type::eof ())
3899 textscan::lookahead (delimited_stream& is,
const Cell& targets,
int max_len,
3900 bool case_sensitive)
const
3906 char *pos = is.tellg ();
3908 std::string tmp (max_len,
'\0');
3909 char *look = is.read (&tmp[0], tmp.size (), pos);
3916 int (*compare)(
const char *,
const char *, std::size_t);
3919 for (i = 0; i < targets.
numel (); i++)
3921 std::string s = targets (i).string_value ();
3922 if (! (*compare) (s.c_str (), look, s.size ()))
3924 is.read (&tmp[0], s.size (), pos);
3929 if (i == targets.
numel ())
3937 textscan::skip_delim (delimited_stream& is)
3939 int c1 = skip_whitespace (is);
3940 if (m_delim_list.numel () == 0)
3942 if (is_delim (c1) || c1 == m_eol1 || c1 == m_eol2)
3945 if (c1 == m_eol1 && is.peek_undelim () == m_eol2)
3948 if (m_multiple_delims_as_one)
3954 while (is && ((c1 = is.get_undelim ())
3955 != std::istream::traits_type::eof ())
3956 && (((c1 == m_eol1 || c1 == m_eol2) && ++m_lines)
3957 || isspace (c1) || is_delim (c1)))
3959 if (prev == m_eol1 && m_eol1 != m_eol2 && c1 == m_eol2)
3963 if (c1 != std::istream::traits_type::eof ())
3972 if (c1 == m_eol1 || c1 == m_eol2
3973 || (-1 != (first_match = lookahead (is, m_delim_list, m_delim_len))))
3978 if (is.peek_undelim () == m_eol2)
3981 else if (c1 == m_eol2)
3986 if (m_multiple_delims_as_one)
3992 while (is && ((c1 = skip_whitespace (is))
3993 != std::istream::traits_type::eof ())
3994 && (((c1 == m_eol1 || c1 == m_eol2) && ++m_lines)
3995 || -1 != lookahead (is, m_delim_list, m_delim_len)))
3997 if (prev == m_eol1 && m_eol1 != m_eol2 && c1 == m_eol2)
4013 textscan::match_literal (delimited_stream& is,
4014 const textscan_format_elt& fmt)
4018 skip_whitespace (is,
false);
4020 for (
unsigned int i = 0; i < fmt.width; i++)
4022 int ch = is.get_undelim ();
4023 if (ch != fmt.text[i])
4025 if (ch != std::istream::traits_type::eof ())
4027 is.setstate (std::ios::failbit);
4045 m_errmsg = who +
": " + msg;
4073 bool strip_newline,
const std::string& who)
4078 ::error (
"%s: unable to read from stdin while running interactively",
4090 invalid_operation (who,
"reading");
4094 std::istream& is = *isp;
4096 std::ostringstream buf;
4103 while (is && (c = is.get ()) != std::istream::traits_type::eof ())
4110 if (! strip_newline)
4111 buf << static_cast<char> (c);
4115 if (c != std::istream::traits_type::eof ())
4121 if (! strip_newline)
4122 buf << static_cast<char> (c);
4132 if (! strip_newline)
4133 buf << static_cast<char> (c);
4138 buf << static_cast<char> (c);
4140 if (max_len > 0 && char_count == max_len)
4145 if (! is.eof () && char_count > 0)
4150 int disgusting_compatibility_hack = is.get ();
4152 is.putback (disgusting_compatibility_hack);
4155 if (is.good () || (is.eof () && char_count > 0))
4157 retval = buf.str ();
4165 if (is.eof () && char_count == 0)
4166 error (who,
"at end of file");
4168 error (who,
"read error");
4177 const std::string& who)
4179 return do_gets (max_len, err,
true, who);
4184 const std::string& who)
4186 return do_gets (max_len, err,
false, who);
4190 base_stream::skipl (off_t num,
bool& err,
const std::string& who)
4195 ::error (
"%s: unable to read from stdin while running interactively",
4207 invalid_operation (who,
"reading");
4211 std::istream& is = *isp;
4217 while (is && (c = is.get ()) != std::istream::traits_type::eof ())
4220 if (c ==
'\r' || (c ==
'\n' && lastc !=
'\r'))
4230 if (c ==
'\r' && is.peek () ==
'\n')
4236 error (who,
"read error");
4246 template <
typename T>
4247 static std::istream&
4248 octave_scan_1 (std::istream& is,
const scanf_format_elt& fmt,
4254 std::streampos pos = is.tellg ();
4259 is >> std::oct >> value >> std::dec;
4264 is >> std::hex >> value >> std::dec;
4271 if (c1 != std::istream::traits_type::eof ())
4275 int c2 = is.peek ();
4277 if (c2 ==
'x' || c2 ==
'X')
4280 if (std::isxdigit (is.peek ()))
4281 is >> std::hex >> value >> std::dec;
4287 if (c2 ==
'0' || c2 ==
'1' || c2 ==
'2'
4288 || c2 ==
'3' || c2 ==
'4' || c2 ==
'5'
4289 || c2 ==
'6' || c2 ==
'7')
4290 is >> std::oct >> value >> std::dec;
4291 else if (c2 ==
'8' || c2 ==
'9')
4318 std::ios::iostate status = is.rdstate ();
4319 if (! (status & std::ios::failbit))
4333 is.clear (status & ~std::ios::failbit);
4342 is.setstate (status & ~std::ios_base::eofbit);
4349 template <
typename T>
4350 static std::istream&
4351 octave_scan (std::istream& is,
const scanf_format_elt& fmt, T *valptr)
4359 auto orig_pos = is.tellg ();
4361 is.width (fmt.width);
4364 std::istringstream ss (strbuf);
4366 octave_scan_1 (ss, fmt, valptr);
4377 is.seekg (orig_pos, is.beg);
4379 int chars_read = ss.tellg ();
4382 is.width (chars_read);
4389 is.setstate (std::ios::failbit);
4393 octave_scan_1 (is, fmt, valptr);
4401 (std::istream& is,
const scanf_format_elt& fmt,
double *valptr)
4413 std::streampos pos = is.tellg ();
4415 double value = read_value<double> (is);
4417 std::ios::iostate status = is.rdstate ();
4418 if (! (status & std::ios::failbit))
4429 is.setstate (status & ~std::ios_base::eofbit);
4442 template <
typename T>
4444 do_scanf_conv (std::istream& is,
const scanf_format_elt& fmt,
4454 if (idx == max_size && ! discard)
4459 mval.
resize (nr, max_size / nr, 0.0);
4461 mval.
resize (max_size, 1, 0.0);
4469 data[idx++] = *(valptr);
4478 #define DO_WHITESPACE_CONVERSION() \
4481 int c = std::istream::traits_type::eof (); \
4484 while (is && (c = is.get ()) != std::istream::traits_type::eof () \
4488 if (c == std::istream::traits_type::eof ()) \
4490 is.clear (is.rdstate () & (~std::ios::failbit)); \
4497 #define DO_LITERAL_CONVERSION() \
4500 int c = std::istream::traits_type::eof (); \
4502 int n = fmt.length (); \
4505 while (i < n && is \
4506 && (c = is.get ()) != std::istream::traits_type::eof ()) \
4508 if (c == static_cast<unsigned char> (fmt[i])) \
4521 is.setstate (std::ios::failbit); \
4525 #define DO_PCT_CONVERSION() \
4528 int c = is.get (); \
4530 if (c != std::istream::traits_type::eof ()) \
4535 is.setstate (std::ios::failbit); \
4539 is.setstate (std::ios::failbit); \
4543 #define BEGIN_C_CONVERSION() \
4544 is.unsetf (std::ios::skipws); \
4546 int width = (elt->width ? elt->width : 1); \
4548 std::string tmp (width, '\0'); \
4550 int c = std::istream::traits_type::eof (); \
4553 while (is && n < width \
4554 && (c = is.get ()) != std::istream::traits_type::eof ()) \
4555 tmp[n++] = static_cast<char> (c); \
4557 if (c == std::istream::traits_type::eof ()) \
4558 is.clear (is.rdstate () & (~std::ios::failbit)); \
4564 #define BEGIN_S_CONVERSION() \
4565 int width = elt->width; \
4573 tmp = std::string (width, '\0'); \
4575 int c = std::istream::traits_type::eof (); \
4579 while (is && (c = is.get ()) != std::istream::traits_type::eof ()) \
4581 if (! isspace (c)) \
4583 tmp[n++] = static_cast<char> (c); \
4588 while (is && n < width \
4589 && (c = is.get ()) != std::istream::traits_type::eof ()) \
4597 tmp[n++] = static_cast<char> (c); \
4600 if (c == std::istream::traits_type::eof ()) \
4601 is.clear (is.rdstate () & (~std::ios::failbit)); \
4607 is >> std::ws >> tmp; \
4613 #define BEGIN_CHAR_CLASS_CONVERSION() \
4614 int width = (elt->width ? elt->width \
4615 : std::numeric_limits<int>::max ()); \
4621 std::ostringstream buf; \
4623 std::string char_class = elt->char_class; \
4625 int c = std::istream::traits_type::eof (); \
4627 if (elt->type == '[') \
4629 int chars_read = 0; \
4630 while (is && chars_read++ < width \
4631 && (c = is.get ()) != std::istream::traits_type::eof ()) \
4633 if (char_class.find (c) != std::string::npos) \
4634 buf << static_cast<char> (c); \
4644 int chars_read = 0; \
4645 while (is && chars_read++ < width \
4646 && (c = is.get ()) != std::istream::traits_type::eof ()) \
4648 if (char_class.find (c) == std::string::npos) \
4649 buf << static_cast<char> (c); \
4661 is.setstate (std::ios::failbit); \
4662 else if (c == std::istream::traits_type::eof ()) \
4663 is.clear (is.rdstate () & (~std::ios::failbit)); \
4668 #define FINISH_CHARACTER_CONVERSION() \
4671 if (encoding ().compare ("utf-8")) \
4672 tmp = string::u8_from_encoding (who, tmp, encoding ()); \
4673 width = tmp.length (); \
4675 if (is && width > 0) \
4681 conversion_count++; \
4685 if (data_index == max_size) \
4689 if (all_char_conv) \
4691 if (one_elt_size_spec) \
4692 mval.resize (1, max_size, 0.0); \
4694 mval.resize (nr, max_size / nr, 0.0); \
4696 panic_impossible (); \
4699 mval.resize (nr, max_size / nr, 0.0); \
4701 mval.resize (max_size, 1, 0.0); \
4703 data = mval.fortran_vec (); \
4706 data[data_index++] = static_cast<unsigned char> \
4715 base_stream::do_scanf (scanf_format_list& fmt_list,
4717 bool one_elt_size_spec,
4719 const std::string& who)
4724 ::error (
"%s: unable to read from stdin while running interactively",
4729 conversion_count = 0;
4735 if (nr == 0 || nc == 0)
4737 if (one_elt_size_spec)
4740 return Matrix (nr, nc, 0.0);
4745 bool all_char_conv = fmt_list.all_character_conversions ();
4758 if (one_elt_size_spec)
4761 mval.
resize (1, max_size, 0.0);
4770 mval.
resize (nr, nc, 0.0);
4771 max_size = max_conv = nr * nc;
4775 mval.
resize (nr, 32, 0.0);
4787 mval.
resize (nr, nc, 0.0);
4789 max_conv = max_size;
4794 mval.
resize (nr, 32, 0.0);
4801 mval.
resize (32, 1, 0.0);
4809 std::istream& is = *isp;
4811 const scanf_format_elt *elt = fmt_list.first ();
4813 std::ios::fmtflags flags = is.flags ();
4825 if (elt->type == scanf_format_elt::null
4826 || (! (elt->type == scanf_format_elt::whitespace_conversion
4827 || elt->type == scanf_format_elt::literal_conversion
4828 || elt->type ==
'%')
4829 && max_conv > 0 && conversion_count == max_conv))
4836 if (all_char_conv && one_elt_size_spec)
4839 final_nc = data_index;
4844 final_nc = (data_index - 1) / nr + 1;
4849 else if (data_index == max_size)
4855 if (one_elt_size_spec)
4856 mval.
resize (1, max_size, 0.0);
4858 mval.
resize (nr, max_size / nr, 0.0);
4863 mval.
resize (nr, max_size / nr, 0.0);
4865 mval.
resize (max_size, 1, 0.0);
4870 std::string fmt = elt->text;
4872 bool discard = elt->discard;
4876 case scanf_format_elt::whitespace_conversion:
4880 case scanf_format_elt::literal_conversion:
4890 switch (elt->modifier)
4896 data_index, conversion_count,
4897 nr, max_size, discard);
4905 data_index, conversion_count,
4906 nr, max_size, discard);
4914 data_index, conversion_count,
4915 nr, max_size, discard);
4922 case 'o':
case 'u':
case 'x':
case 'X':
4924 switch (elt->modifier)
4930 data_index, conversion_count,
4931 nr, max_size, discard);
4939 data_index, conversion_count,
4940 nr, max_size, discard);
4948 data_index, conversion_count,
4949 nr, max_size, discard);
4956 case 'e':
case 'f':
case 'g':
4962 data_index, conversion_count,
4963 nr, max_size, discard);
4994 error (who,
"unsupported format specifier");
4998 error (who,
"internal format error");
5006 else if (is.eof () || ! is)
5010 if (one_elt_size_spec)
5013 final_nc = data_index;
5015 else if (data_index > nr)
5018 final_nc = (data_index - 1) / nr + 1;
5022 final_nr = data_index;
5028 if (data_index > nr)
5031 final_nc = (data_index - 1) / nr + 1;
5035 final_nr = data_index;
5041 final_nr = data_index;
5047 if (is.rdstate () & std::ios::failbit)
5049 is.clear (is.rdstate () & (~std::ios::failbit));
5050 error (who,
"format failed to match");
5056 &&
name () ==
"stdin")
5062 do_gets (-1, err,
false, who);
5070 error (who,
"internal format error");
5074 if (m_nconv == 0 && ++trips == num_fmt_elts)
5076 if (all_char_conv && one_elt_size_spec)
5079 final_nc = data_index;
5084 final_nc = (data_index - 1) / nr + 1;
5095 elt = fmt_list.next (m_nconv > 0
5097 || conversion_count < max_conv));
5102 mval.
resize (final_nr, final_nc, 0.0);
5113 base_stream::scanf (
const std::string& fmt,
const Array<double>& size,
5115 const std::string& who)
5119 conversion_count = 0;
5124 invalid_operation (who,
"reading");
5127 scanf_format_list fmt_list (fmt);
5129 if (fmt_list.num_conversions () == -1)
5130 ::error (
"%s: invalid format specified", who.c_str ());
5135 bool one_elt_size_spec;
5137 get_size (size, nr, nc, one_elt_size_spec, who);
5139 retval = do_scanf (fmt_list, nr, nc, one_elt_size_spec,
5140 conversion_count, who);
5147 base_stream::do_oscanf (
const scanf_format_elt *elt,
5157 std::istream& is = *isp;
5159 std::ios::fmtflags flags = is.flags ();
5163 std::string fmt = elt->text;
5165 bool discard = elt->discard;
5169 case scanf_format_elt::whitespace_conversion:
5173 case scanf_format_elt::literal_conversion:
5188 switch (elt->modifier)
5232 case 'o':
case 'u':
case 'x':
case 'X':
5234 switch (elt->modifier)
5278 case 'e':
case 'f':
case 'g':
5333 error (who,
"unsupported format specifier");
5337 error (who,
"internal format error");
5342 if (
ok () && is.fail ())
5344 error (
"%s: read error", who.c_str ());
5351 &&
name () ==
"stdin")
5355 do_gets (-1, err,
false, who);
5363 base_stream::oscanf (
const std::string& fmt,
const std::string& who)
5370 invalid_operation (who,
"reading");
5373 std::istream& is = *isp;
5375 scanf_format_list fmt_list (fmt);
5380 ::error (
"%s: invalid format specified", who.c_str ());
5388 const scanf_format_elt *elt = fmt_list.first ();
5398 quit = do_oscanf (elt, tmp, who);
5405 retval(num_values++) = tmp;
5410 elt = fmt_list.next (m_nconv > 0);
5414 retval(m_nconv) = num_values;
5417 retval(m_nconv+1) =
error (
false, err_num);
5422 if (
ok () &&
len > m_nconv)
5426 elt = fmt_list.next ();
5428 do_oscanf (elt, tmp, who);
5437 base_stream::do_textscan (
const std::string& fmt,
5440 const std::string& who,
5446 ::error (
"%s: unable to read from stdin while running interactively",
5454 invalid_operation (who,
"reading");
5459 retval =
scanner.scan (*isp, fmt, ntimes, options, read_count);
5469 base_stream::flush ()
5476 invalid_operation (
"fflush",
"writing");
5493 enum state { ok, conversion_error };
5496 : m_values (args), m_val_idx (0), m_elt_idx (0),
5497 m_n_vals (m_values.length ()), m_n_elts (0), m_have_data (false),
5509 OCTAVE_DISABLE_COPY_MOVE (printf_value_cache)
5511 ~printf_value_cache () =
default;
5522 operator bool ()
const {
return (m_curr_state == ok); }
5524 bool exhausted () {
return (m_val_idx >= m_n_vals); }
5529 printf_value_cache ();
5544 printf_value_cache::get_next_value (
char type)
5549 m_curr_state = conversion_error;
5551 while (! exhausted ())
5555 m_curr_val = m_values (m_val_idx);
5558 m_n_elts = m_curr_val.numel ();
5562 if (m_elt_idx < m_n_elts)
5566 if (m_curr_val.is_string ())
5573 retval = sval.substr (m_elt_idx);
5576 m_elt_idx = m_n_elts;
5586 for (; idx < m_n_elts; idx++)
5588 double dval = val(idx);
5591 || dval < 0 || dval > 255)
5599 std::string sval (
n,
'\0');
5602 sval[i] = val(m_elt_idx++);
5614 if (type ==
'c' && ! retval.
is_string ())
5618 if (
math::x_nint (dval) == dval && dval >= 0 && dval < 256)
5619 retval =
static_cast<char> (dval);
5623 if (m_elt_idx >= m_n_elts)
5627 m_have_data =
false;
5635 m_have_data =
false;
5641 if (type ==
's' || type ==
'c')
5650 m_curr_state = conversion_error;
5659 printf_value_cache::int_value ()
5668 m_curr_state = conversion_error;
5677 template <
typename T>
5679 do_printf_conv (std::ostream& os,
const char *fmt,
int nsa,
int sa_1,
5680 int sa_2, T arg,
const std::string& who)
5687 retval =
format (os, fmt, sa_1, sa_2, arg);
5691 retval =
format (os, fmt, sa_1, arg);
5695 retval =
format (os, fmt, arg);
5699 ::error (
"%s: internal error handling format", who.c_str ());
5707 do_printf_string (std::ostream& os,
const printf_format_elt *elt,
5708 int nsa,
int sa_1,
int sa_2,
const std::string& arg,
5709 const std::string& who)
5712 ::error (
"%s: internal error handling format", who.c_str ());
5714 std::string flags = elt->flags;
5716 bool left = flags.find (
'-') != std::string::npos;
5718 std::size_t
len = arg.length ();
5720 std::size_t prec = (nsa > 1 ? sa_2 : (elt->prec == -1 ?
len : elt->prec));
5722 std::string print_str = prec < arg.length () ? arg.substr (0, prec) : arg;
5724 std::size_t fw = (nsa > 0 ? sa_1 : (elt->fw == -1 ?
len : elt->fw));
5726 os << std::setw (fw) << (left ? std::left : std::right) << print_str;
5728 return len > fw ?
len : fw;
5753 if (ival.
value () <= limit)
5763 if (dval ==
math::fix (dval) && dval <= limit)
5782 return ov_is_ge_zero.
is_true ();
5790 if (dval ==
math::fix (dval) && dval >= 0 && dval <= limit)
5798 switch_to_g_format (
const printf_format_elt *elt)
5800 std::string tfmt = elt->text;
5802 tfmt.replace (tfmt.rfind (elt->type), 1,
"g");
5808 base_stream::do_numeric_printf_conv (std::ostream& os,
5809 const printf_format_elt *elt,
5810 int nsa,
int sa_1,
int sa_2,
5812 const std::string& who)
5816 std::string tfmt = elt->text;
5818 if (is_nan_or_inf (val))
5822 std::string::size_type i1, i2;
5824 tfmt.replace ((i1 = tfmt.rfind (elt->type)), 1, 1,
's');
5826 if ((i2 = tfmt.rfind (
'.')) != std::string::npos && i2 < i1)
5828 tfmt.erase (i2, i1-i2);
5829 if (elt->prec == -2)
5836 if (elt->flags.find (
'+') != std::string::npos)
5837 tval = (dval < 0 ?
"-Inf" :
"+Inf");
5839 tval = (dval < 0 ?
"-Inf" :
"Inf");
5843 if (elt->flags.find (
'+') != std::string::npos)
5849 retval += do_printf_conv (os, tfmt.c_str (), nsa, sa_1, sa_2, tval,
5854 static std::string llmod
5855 = (
sizeof (long) ==
sizeof (int64_t) ?
"l" :
"ll");
5857 char type = elt->type;
5861 case 'd':
case 'i':
case 'c':
5862 if (ok_for_signed_int_conv (val))
5867 tfmt.replace (tfmt.rfind (type), 1, llmod + type);
5869 retval += do_printf_conv (os, tfmt.c_str (), nsa, sa_1, sa_2,
5870 tval.
value (), who);
5874 tfmt = switch_to_g_format (elt);
5878 retval += do_printf_conv (os, tfmt.c_str (), nsa, sa_1, sa_2,
5883 case 'o':
case 'x':
case 'X':
case 'u':
5884 if (ok_for_unsigned_int_conv (val))
5889 tfmt.replace (tfmt.rfind (type), 1, llmod + type);
5891 retval += do_printf_conv (os, tfmt.c_str (), nsa, sa_1, sa_2,
5892 tval.
value (), who);
5896 tfmt = switch_to_g_format (elt);
5900 retval += do_printf_conv (os, tfmt.c_str (), nsa, sa_1, sa_2,
5905 case 'f':
case 'e':
case 'E':
5910 retval += do_printf_conv (os, tfmt.c_str (), nsa, sa_1, sa_2,
5918 error (who,
"invalid format specifier");
5928 base_stream::field_width_error (
const std::string& who)
const
5930 ::error (
"%s: invalid field width, must be integer >= 0 and <= INT_MAX",
5935 base_stream::do_printf (printf_format_list& fmt_list,
5937 const std::string& who)
5946 invalid_operation (who,
"writing");
5949 std::ostream& os = *osp;
5953 const printf_format_elt *elt = fmt_list.first ();
5955 printf_value_cache val_cache (args, who);
5962 ::error (
"%s: internal error handling format", who.c_str ());
5965 int nsa = (elt->fw == -2) + (elt->prec == -2);
5972 sa_1 = val_cache.int_value ();
5976 field_width_error (who);
5983 sa_2 = val_cache.int_value ();
5987 field_width_error (who);
5994 if (elt->type ==
'%')
5999 else if (elt->args == 0 && ! elt->text.empty ())
6002 retval += (elt->text.length ());
6004 else if (elt->type ==
's' || elt->type ==
'c')
6006 octave_value val = val_cache.get_next_value (elt->type);
6014 retval += do_printf_string (os, elt, nsa, sa_1,
6018 retval += do_numeric_printf_conv (os, elt, nsa, sa_1,
6031 retval += do_numeric_printf_conv (os, elt, nsa, sa_1,
6040 error (who,
"write error");
6044 elt = fmt_list.next (m_nconv > 0 && ! val_cache.exhausted ());
6046 if (! elt || (val_cache.exhausted () && elt->args > 0))
6055 base_stream::printf (
const std::string& fmt,
6057 const std::string& who)
6059 printf_format_list fmt_list (fmt);
6061 if (fmt_list.num_conversions () == -1)
6062 ::error (
"%s: invalid format specified", who.c_str ());
6064 return do_printf (fmt_list, args, who);
6068 base_stream::puts (
const std::string& s,
const std::string& who)
6075 invalid_operation (who,
"writing");
6078 std::ostream& os = *osp;
6083 error (who,
"write error");
6097 error (who,
"write error");
6109 err_num = (m_fail ? -1 : 0);
6111 std::string tmp = m_errmsg;
6120 base_stream::invalid_operation (
const std::string& who,
const char *rw)
6123 error (who, std::string (
"stream not open for ") + rw);
6132 retval = m_rep->flush ();
6143 retval = m_rep->getl (max_len, err, who);
6150 const std::string& who)
6160 max_len = convert_to_valid_int (tc_max_len, conv_err);
6162 if (conv_err || max_len < 0)
6165 ::error (
"%s: invalid maximum length specified", who.c_str ());
6169 return getl (max_len, err, who);
6178 retval = m_rep->gets (max_len, err, who);
6185 const std::string& who)
6195 max_len = convert_to_valid_int (tc_max_len, conv_err);
6197 if (conv_err || max_len < 0)
6200 ::error (
"%s: invalid maximum length specified", who.c_str ());
6204 return gets (max_len, err, who);
6213 retval = m_rep->skipl (count, err, who);
6220 const std::string& who)
6235 count = convert_to_valid_int (tc_count, conv_err);
6237 if (conv_err || count < 0)
6240 ::error (
"%s: invalid number of lines specified",
6246 return skipl (count, err, who);
6259 off_t orig_pos = m_rep->tell ();
6262 status = m_rep->seek (0,
SEEK_END);
6266 off_t eof_pos = m_rep->tell ();
6278 status = m_rep->seek (offset, origin);
6283 off_t desired_pos = m_rep->tell ();
6287 if (desired_pos > eof_pos || desired_pos < 0)
6318 off_t xoffset = val.
value ();
6326 std::string xorigin = tc_origin.
xstring_value (
"fseek: invalid value for origin");
6328 if (xorigin ==
"bof")
6330 else if (xorigin ==
"cof")
6332 else if (xorigin ==
"eof")
6339 int xorigin = convert_to_valid_int (tc_origin, conv_err);
6345 else if (xorigin == 0)
6347 else if (xorigin == 1)
6355 ::error (
"fseek: invalid value for origin");
6357 retval =
seek (xoffset, origin);
6361 error (
"fseek: failed to seek to requested position");
6372 retval = m_rep->tell ();
6386 bool retval =
false;
6389 retval = m_rep->is_open ();
6404 template <
typename SRC_T,
typename DST_T>
6406 convert_and_copy (std::list<void *>& input_buf_list,
6410 bool do_float_fmt_conv,
bool do_NA_conv,
6413 typedef typename DST_T::element_type dst_elt_type;
6417 dst_elt_type *conv_data = conv.fortran_vec ();
6421 for (
auto it = input_buf_list.cbegin (); it != input_buf_list.cend (); it++)
6423 SRC_T *data =
static_cast<SRC_T *
> (*it);
6425 if (swap || do_float_fmt_conv)
6433 swap_bytes<sizeof (SRC_T)> (&data[i]);
6434 else if (do_float_fmt_conv)
6446 conv_data[j] = data[i];
6455 swap_bytes<sizeof (SRC_T)> (&data[i]);
6456 else if (do_float_fmt_conv)
6461 conv_data[j] = data[i];
6473 conv_data[j] = data[i];
6480 conv_data[j] = data[i];
6487 input_buf_list.clear ();
6490 conv_data[i] = dst_elt_type (0);
6498 bool swap,
bool do_float_fmt_conv,
bool do_NA_conv,
6501 #define TABLE_ELT(T, U, V, W) \
6502 conv_fptr_table[oct_data_conv::T][oct_data_conv::U] = convert_and_copy<V, W>
6504 #define FILL_TABLE_ROW(T, V) \
6505 TABLE_ELT (T, dt_int8, V, int8NDArray); \
6506 TABLE_ELT (T, dt_uint8, V, uint8NDArray); \
6507 TABLE_ELT (T, dt_int16, V, int16NDArray); \
6508 TABLE_ELT (T, dt_uint16, V, uint16NDArray); \
6509 TABLE_ELT (T, dt_int32, V, int32NDArray); \
6510 TABLE_ELT (T, dt_uint32, V, uint32NDArray); \
6511 TABLE_ELT (T, dt_int64, V, int64NDArray); \
6512 TABLE_ELT (T, dt_uint64, V, uint64NDArray); \
6513 TABLE_ELT (T, dt_single, V, FloatNDArray); \
6514 TABLE_ELT (T, dt_double, V, NDArray); \
6515 TABLE_ELT (T, dt_char, V, charNDArray); \
6516 TABLE_ELT (T, dt_schar, V, charNDArray); \
6517 TABLE_ELT (T, dt_uchar, V, charNDArray); \
6518 TABLE_ELT (T, dt_logical, V, boolNDArray);
6521 stream::finalize_read (std::list<void *>& input_buf_list,
6531 static bool initialized =
false;
6540 for (
int j = 0; j < 14; j++)
6541 conv_fptr_table[i][j] =
nullptr;
6577 switch (output_type)
6596 retval =
fptr (input_buf_list, input_buf_elts, elts_read,
6597 nr, nc, swap, do_float_fmt_conv, do_NA_conv, ffmt);
6602 ::error (
"read: invalid type specification");
6623 bool one_elt_size_spec =
false;
6631 std::ptrdiff_t tmp_count = 0;
6635 get_size (size, nr, nc, one_elt_size_spec,
"fread");
6639 invalid_operation (
"fread",
"reading");
6644 if (one_elt_size_spec)
6667 if (nr == 0 || nc == 0)
6673 bool read_to_eof = elts_to_read < 0;
6680 input_buf_elts = 1024 * 1024;
6682 input_buf_elts = elts_to_read;
6685 input_buf_elts = block_size;
6690 std::ptrdiff_t input_buf_size
6691 =
static_cast<std::ptrdiff_t
> (input_buf_elts) * input_elt_size;
6699 error (
"fread: invalid input stream");
6702 std::istream& is = *isp;
6707 if (skip != 0 && is && ! is.eof ())
6709 cur_pos = is.tellg ();
6710 is.seekg (0, is.end);
6711 eof_pos = is.tellg ();
6712 is.seekg (cur_pos, is.beg);
6715 std::list<void *> input_buf_list;
6717 while (is && ! is.eof ()
6718 && (read_to_eof || tmp_count < elts_to_read))
6724 if (remaining_elts < input_buf_elts)
6725 input_buf_size = remaining_elts * input_elt_size;
6728 char *input_buf =
new char [input_buf_size];
6730 is.read (input_buf, input_buf_size);
6732 std::size_t gcount = is.gcount ();
6740 input_buf_list.push_back (input_buf);
6742 if (skip != 0 && nel == block_size && is)
6746 off_t remaining = eof_pos - cur_pos;
6748 if (remaining < skip)
6750 is.seekg (0, is.end);
6755 is.seekg (skip, is.cur);
6765 nc = tmp_count / nr;
6767 if (tmp_count % nr != 0)
6773 else if (tmp_count == 0)
6778 else if (tmp_count != nr * nc)
6780 if (tmp_count % nr != 0)
6781 nc = tmp_count / nr + 1;
6783 nc = tmp_count / nr;
6790 error (
"fread: number of elements read exceeds max index size");
6794 retval = finalize_read (input_buf_list, input_buf_elts, count,
6795 nr, nc, input_type, output_type, ffmt);
6809 invalid_operation (
"fwrite",
"writing");
6819 error (
"fwrite: write error");
6827 template <
typename T,
typename V>
6829 convert_chars (
const void *data,
void *conv_data,
octave_idx_type n_elts)
6831 const T *tt_data =
static_cast<const T *
> (data);
6833 V *vt_data =
static_cast<V *
> (conv_data);
6836 vt_data[i] = tt_data[i];
6839 template <
typename T,
typename V>
6844 typedef typename V::val_type val_type;
6846 val_type *vt_data =
static_cast<val_type *
> (conv_data);
6853 vt_data[i] = val.value ();
6856 swap_bytes<sizeof (val_type)> (&vt_data[i]);
6860 template <
typename T>
6861 class ultimate_element_type
6867 template <
typename T>
6874 template <
typename T>
6891 typedef typename ultimate_element_type<T>::type ult_elt_type;
6893 switch (output_type)
6896 convert_chars<ult_elt_type, char> (data, conv_data, n_elts);
6900 convert_chars<ult_elt_type, signed char> (data, conv_data, n_elts);
6904 convert_chars<ult_elt_type, unsigned char> (data, conv_data, n_elts);
6908 convert_ints<T, octave_int8> (data, conv_data, n_elts, swap);
6912 convert_ints<T, octave_uint8> (data, conv_data, n_elts, swap);
6916 convert_ints<T, octave_int16> (data, conv_data, n_elts, swap);
6920 convert_ints<T, octave_uint16> (data, conv_data, n_elts, swap);
6924 convert_ints<T, octave_int32> (data, conv_data, n_elts, swap);
6928 convert_ints<T, octave_uint32> (data, conv_data, n_elts, swap);
6932 convert_ints<T, octave_int64> (data, conv_data, n_elts, swap);
6936 convert_ints<T, octave_uint64> (data, conv_data, n_elts, swap);
6941 float *vt_data =
static_cast<float *
> (conv_data);
6945 vt_data[i] = data[i];
6947 if (do_float_conversion)
6955 double *vt_data =
static_cast<double *
> (conv_data);
6959 vt_data[i] = data[i];
6961 if (do_float_conversion)
6968 ::error (
"write: invalid type specification");
6977 bool status =
false;
6983 std::ostream& os = *osp;
6987 os.write (
static_cast<const char *
> (data), nbytes);
7000 bool status =
false;
7007 std::ostream& os = *osp;
7011 off_t orig_pos =
tell ();
7015 off_t eof_pos =
tell ();
7020 std::size_t remaining = eof_pos - orig_pos;
7022 if (remaining < skip)
7027 unsigned char zero = 0;
7028 for (std::size_t j = 0; j < skip - remaining; j++)
7029 os.write (
reinterpret_cast<const char *
> (&zero), 1);
7040 template <
typename T>
7054 bool do_data_conversion = (swap || ! is_equivalent_type<T> (output_type)
7062 chunk_size = block_size;
7063 else if (do_data_conversion)
7064 chunk_size = 1024 * 1024;
7070 const T *pdata = data.
data ();
7082 if (chunk_size > remaining_nel)
7083 chunk_size = remaining_nel;
7085 bool status =
false;
7087 if (do_data_conversion)
7089 std::size_t output_size
7094 status = convert_data (&pdata[i], conv_data, chunk_size,
7095 output_type, flt_fmt);
7101 status =
write_bytes (pdata,
sizeof (T) * chunk_size);
7112 #define INSTANTIATE_WRITE(T) \
7114 OCTINTERP_API octave_idx_type \
7115 stream::write (const Array<T>& data, octave_idx_type block_size, \
7116 oct_data_conv::data_type output_type, \
7117 octave_idx_type skip, \
7118 mach_info::float_format flt_fmt)
7137 #if defined (OCTAVE_HAVE_OVERLOAD_CHAR_INT8_TYPES)
7150 retval = m_rep->scanf (fmt, size, count, who);
7168 retval =
scanf (sfmt, size, count, who);
7173 error (who +
": format must be a string");
7185 retval = m_rep->oscanf (fmt, who);
7202 retval =
oscanf (sfmt, who);
7207 error (who +
": format must be a string");
7218 return (stream_ok ()
7219 ? m_rep->do_textscan (fmt, ntimes, options, who, count)
7225 const std::string& who)
7230 retval = m_rep->printf (fmt, args, who);
7237 const std::string& who)
7248 retval =
printf (sfmt, args, who);
7253 error (who +
": format must be a string");
7265 retval = m_rep->puts (s, who);
7280 retval =
puts (s, who);
7285 error (who +
": argument must be a string");
7297 retval = m_rep->eof ();
7305 std::string retval =
"invalid stream object";
7307 if (stream_ok (
false))
7308 retval = m_rep->error (clear, err_num);
7319 retval = m_rep->name ();
7330 retval = m_rep->mode ();
7341 retval = m_rep->float_format ();
7349 std::string retval =
"???";
7350 std::ios::openmode in_mode =
static_cast<std::ios::openmode
> (
mode);
7352 if (in_mode == std::ios::in)
7354 else if (in_mode == std::ios::out
7357 else if (in_mode == (std::ios::out | std::ios::app))
7359 else if (in_mode == (std::ios::in | std::ios::out))
7363 else if (in_mode == (std::ios::in | std::ios::out | std::ios::ate))
7365 else if (in_mode == (std::ios::in | std::ios::binary))
7367 else if (in_mode == (std::ios::out | std::ios::binary)
7370 else if (in_mode == (std::ios::out | std::ios::app | std::ios::binary))
7372 else if (in_mode == (std::ios::in | std::ios::out | std::ios::binary))
7375 | std::ios::binary))
7377 else if (in_mode == (std::ios::in | std::ios::out | std::ios::ate
7378 | std::ios::binary))
7385 : m_list (), m_lookup_cache (m_list.end ()), m_stdin_file (-1),
7386 m_stdout_file (-1), m_stderr_file (-1)
7402 m_stdin_file =
insert (stdin_stream);
7403 m_stdout_file =
insert (stdout_stream);
7404 m_stderr_file =
insert (stderr_stream);
7419 if (stream_number == -1)
7420 return stream_number;
7435 if (m_list.size () >= m_list.max_size ())
7436 ::error (
"could not create file id");
7438 m_list[stream_number] = os;
7440 return stream_number;
7443 OCTAVE_NORETURN
static
7445 err_invalid_file_id (
int fid,
const std::string& who)
7448 ::error (
"invalid stream number = %d", fid);
7450 ::error (
"%s: invalid stream number = %d", who.c_str (), fid);
7459 err_invalid_file_id (fid, who);
7461 if (m_lookup_cache != m_list.end () && m_lookup_cache->first == fid)
7462 retval = m_lookup_cache->second;
7465 ostrl_map::const_iterator iter = m_list.find (fid);
7467 if (iter == m_list.end ())
7468 err_invalid_file_id (fid, who);
7470 retval = iter->second;
7471 m_lookup_cache = iter;
7479 const std::string& who)
const
7491 err_invalid_file_id (fid, who);
7493 auto iter = m_list.find (fid);
7495 if (iter == m_list.end ())
7496 err_invalid_file_id (fid, who);
7498 stream os = iter->second;
7499 m_list.erase (iter);
7500 m_lookup_cache = m_list.end ();
7504 err_invalid_file_id (fid, who);
7526 retval =
remove (i, who);
7542 for (
auto iter = m_list.begin (); iter != m_list.end (); )
7544 int fid = iter->first;
7551 stream os = iter->second;
7553 std::string name = os.
name ();
7554 std::transform (name.begin (), name.end (), name.begin (), tolower);
7557 if (name.find (
"gnuplot") != std::string::npos)
7568 m_list.erase (iter++);
7571 m_lookup_cache = m_list.end ();
7583 if (m_lookup_cache != m_list.end () && m_lookup_cache->first == fid)
7584 os = m_lookup_cache->second;
7587 ostrl_map::const_iterator iter = m_list.find (fid);
7589 if (iter == m_list.end ())
7593 m_lookup_cache = iter;
7599 retval(0) = os.
name ();
7613 ::error (
"file id must be a file object or integer value");
7615 int int_fid = convert_to_valid_int (fid, conv_err);
7618 ::error (
"file id must be a file object or integer value");
7626 std::ostringstream buf;
7629 <<
" number mode arch name\n"
7630 <<
" ------ ---- ---- ----\n";
7632 for (
const auto& fid_strm : m_list)
7634 stream os = fid_strm.second;
7637 << std::setiosflags (std::ios::right)
7638 << std::setw (4) << fid_strm.first <<
" "
7640 << std::resetiosflags (std::ios::adjustfield)
7641 << std::setiosflags (std::ios::left)
7648 << os.
name () <<
"\n";
7659 Matrix retval (1, m_list.size (), 0.0);
7663 for (
const auto& fid_strm : m_list)
7666 if (fid_strm.first > 2 && fid_strm.second)
7667 retval(0, num_open++) = fid_strm.first;
7670 retval.
resize ((num_open > 0), num_open);
7684 for (
const auto& fid_strm : m_list)
7687 if (fid_strm.first > 2)
7689 stream os = fid_strm.second;
7691 if (os && os.
name () == nm)
7693 retval = fid_strm.first;
7700 ::error (
"file id must be a file object, std::string, or integer value");
7705 int int_fid = convert_to_valid_int (fid, conv_err);
7708 ::error (
"file id must be a file object, std::string, or integer value");
7734 OCTAVE_END_NAMESPACE(
octave)
charNDArray max(char d, const charNDArray &m)
charNDArray min(char d, const charNDArray &m)
T * fortran_vec()
Size of the specified dimension.
size_type size(const size_type d) const
Size of the specified dimension.
const T * data() const
Size of the specified dimension.
octave_idx_type numel() const
Number of elements in the array.
void resize(octave_idx_type nr, octave_idx_type nc, double rfv=0)
static bool forced_interactive()
virtual std::string name() const =0
std::string encoding() const
std::string error(bool clear, int &err_num)
virtual std::istream * input_stream()
virtual int file_number() const
std::ostream * preferred_output_stream()
Vector representing the dimensions (size) of an Array.
output_system & get_output_system()
void recover_from_exception()
static stream create(std::istream *arg=nullptr, const std::string &n="")
static std::size_t data_type_size(data_type dt)
virtual bool fast_elem_insert(octave_idx_type n, const octave_value &x)
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
octave_idx_type length() const
octave_base_value * internal_rep() const
octave_value isinf() const
octave_uint64 uint64_scalar_value() const
octave_int64 int64_scalar_value() const
bool is_scalar_type() const
bool is_sq_string() const
bool is_single_type() const
octave_value isnan() const
bool is_uint64_type() const
octave_value reshape(const dim_vector &dv) const
octave_int64 xint64_scalar_value(const char *fmt,...) const
double scalar_value(bool frc_str_conv=false) const
octave_value fast_elem_extract(octave_idx_type n) const
Extract the n-th element, aka 'val(n)'.
std::string string_value(bool force=false) const
NDArray array_value(bool frc_str_conv=false) const
int write(octave::stream &os, int block_size, oct_data_conv::data_type output_type, int skip, octave::mach_info::float_format flt_fmt) const
octave_value convert_to_str(bool pad=false, bool force=false, char type='\'') const
std::string xstring_value(const char *fmt,...) const
double double_value(bool frc_str_conv=false) const
static stream create(std::ostream *arg, const std::string &n="")
std::ostream & __stdout__()
octave_value stdin_file() const
int get_file_number(const octave_value &fid) const
std::string list_open_files() const
octave_value stdout_file() const
stream_list(interpreter &interp)
stream lookup(int fid, const std::string &who="") const
octave_value open_file_numbers() const
string_vector get_info(int fid) const
int remove(int fid, const std::string &who="")
void clear(bool flush=true)
octave_value stderr_file() const
static std::string mode_as_string(int mode)
octave_value scanf(const std::string &fmt, const Array< double > &size, octave_idx_type &count, const std::string &who)
std::istream * input_stream()
std::string gets(octave_idx_type max_len, bool &err, const std::string &who)
bool skip_bytes(std::size_t n_elts)
std::ostream * output_stream()
off_t skipl(off_t count, bool &err, const std::string &who)
octave_value textscan(const std::string &fmt, octave_idx_type ntimes, const octave_value_list &options, const std::string &who, octave_idx_type &count)
int puts(const std::string &s, const std::string &who)
int printf(const std::string &fmt, const octave_value_list &args, const std::string &who)
bool write_bytes(const void *data, std::size_t n_elts)
mach_info::float_format float_format() const
int seek(off_t offset, int origin)
octave_value_list oscanf(const std::string &fmt, const std::string &who)
std::string getl(octave_idx_type max_len, bool &err, const std::string &who)
std::string error(bool clear, int &err_num)
octave_value read(const Array< double > &size, octave_idx_type block_size, oct_data_conv::data_type input_type, oct_data_conv::data_type output_type, octave_idx_type skip, mach_info::float_format flt_fmt, octave_idx_type &count)
octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, mach_info::float_format flt_fmt)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void do_float_format_conversion(void *data, octave_idx_type len, octave::mach_info::float_format from_fmt, octave::mach_info::float_format to_fmt)
void do_double_format_conversion(void *data, octave_idx_type len, octave::mach_info::float_format from_fmt, octave::mach_info::float_format to_fmt)
void warning(const char *fmt,...)
void warning_with_id(const char *id, const char *fmt,...)
#define panic_impossible()
void err_wrong_type_arg(const char *name, const char *s)
ColumnVector transform(const Matrix &m, double x, double y, double z)
interpreter & __get_interpreter__()
F77_RET_T const F77_INT const F77_INT const F77_INT const F77_DBLE const F77_DBLE F77_INT F77_DBLE * V
bool is_NaN_or_NA(const Complex &x)
octave_idx_type nint_big(double x)
std::complex< T > trunc(const std::complex< T > &x)
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
F77_RET_T const F77_DBLE * x
F77_RET_T const F77_DBLE const F77_DBLE * f
FloatComplex(* fptr)(const FloatComplex &, float, int, octave_idx_type &)
std::string float_format_as_string(float_format flt_fmt)
float_format native_float_format()
@ flt_fmt_ieee_big_endian
@ flt_fmt_ieee_little_endian
std::complex< double > w(std::complex< double > z, double relerr=0)
std::complex< double > Complex
std::complex< float > FloatComplex
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
template void do_scanf_conv(std::istream &, const scanf_format_elt &, double *, Matrix &, double *, octave_idx_type &, octave_idx_type &, octave_idx_type, octave_idx_type, bool)
#define BEGIN_S_CONVERSION()
#define BEGIN_CHAR_CLASS_CONVERSION()
#define BEGIN_C_CONVERSION()
#define DO_WHITESPACE_CONVERSION()
std::istream & octave_scan(std::istream &is, const scanf_format_elt &fmt, double *valptr)
void base_stream::() error(const std::string &msg,)
#define DO_LITERAL_CONVERSION()
octave_value(* conv_fptr)(std::list< void * > &input_buf_list, octave_idx_type input_buf_elts, octave_idx_type elts_read, octave_idx_type nr, octave_idx_type nc, bool swap, bool do_float_fmt_conv, bool do_NA_conv, mach_info::float_format from_flt_fmt)
#define FILL_TABLE_ROW(T, V)
#define INSTANTIATE_WRITE(T)
#define DO_PCT_CONVERSION()
#define FINISH_CHARACTER_CONVERSION()
T::size_type numel(const T &str)
bool strncmp(const T &str_a, const T &str_b, const typename T::size_type n)
True if the first N characters are the same.
std::string u8_from_encoding(const std::string &who, const std::string &native_string, const std::string &encoding)
const octave_base_value const Array< octave_idx_type > & ra_idx
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_value cat_op(type_info &ti, const octave_value &a, const octave_value &b, const Array< octave_idx_type > &ra_idx)
octave_value binary_op(type_info &ti, octave_value::binary_op op, const octave_value &a, const octave_value &b)
int octave_strncasecmp(const char *s1, const char *s2, size_t n)
std::string do_string_escapes(const std::string &s)
std::string undo_string_escapes(const std::string &s)
std::size_t format(std::ostream &os, const char *fmt,...)