26 #if defined (HAVE_CONFIG_H)
134 ::error (
"%s: NaN invalid as size specification", who.c_str ());
141 ::error (
"%s: negative value invalid as size specification",
144 static const double out_of_range_top
147 if (
d >= out_of_range_top)
148 ::error (
"%s: dimension too large for Octave's index type",
160 bool& one_elt_size_spec,
const std::string& who)
165 one_elt_size_spec =
false;
174 one_elt_size_spec =
true;
178 dnc = (dnr == 0.0) ? 0.0 : 1.0;
180 else if (sz_len == 2)
185 ::error (
"%s: infinite value invalid as size specification",
191 ::error (
"%s: invalid size specification (must be 2-D)", who.c_str ());
202 ::error (
"%s: size too large for Octave's index type", who.c_str ());
211 std::size_t
len = s.length ();
217 unsigned char c = s[i++];
219 if (c ==
'-' && i > 1 && i <
len
220 && (
static_cast<unsigned char> (s[i-2])
221 <=
static_cast<unsigned char> (s[i])))
226 for (c = s[i-2]+1; c < s[i]; c++)
234 if (c !=
'-' || i ==
len)
249 whitespace_conversion = 1,
250 literal_conversion = 2,
255 char typ =
'\0',
char mod =
'\0',
256 const std::string& ch_class =
"")
257 : text (txt), width (
w), discard (
d), type (typ),
258 modifier (
mod), char_class (ch_class)
309 std::size_t
length (
void)
const {
return m_fmt_elts.size (); }
319 return length () > 0 ? m_fmt_elts[m_curr_idx] :
nullptr;
329 if (m_curr_idx >= length ())
340 void printme (
void)
const;
342 bool ok (
void)
const {
return (m_nconv >= 0); }
344 operator bool ()
const {
return ok (); }
346 bool all_character_conversions (
void);
348 bool all_numeric_conversions (
void);
352 void add_elt_to_list (
int width,
bool discard,
char type,
char modifier,
353 const std::string& char_class =
"");
355 void process_conversion (
const std::string& s, std::size_t& i,
356 std::size_t
n,
int& width,
bool& discard,
357 char& type,
char& modifier);
359 int finish_conversion (
const std::string& s, std::size_t& i, std::size_t
n,
360 int width,
bool discard,
char& type,
381 : m_nconv (0), m_curr_idx (0), m_fmt_elts (), m_buf ()
383 std::size_t
n = s.length ();
388 bool discard =
false;
389 char modifier =
'\0';
392 bool have_more =
true;
404 have_more = (
m_buf.tellp () != 0);
406 else if (isspace (s[i]))
415 while (++i <
n && isspace (s[i]))
430 while (i <
n && ! isspace (s[i]) && s[i] !=
'%')
456 for (std::size_t i = 0; i <
n; i++)
466 const std::string& char_class)
468 std::string text =
m_buf.str ();
474 modifier, char_class);
485 std::size_t
n,
int& width,
486 bool& discard,
char& type,
496 bool have_width =
false;
512 case '0':
case '1':
case '2':
case '3':
case '4':
513 case '5':
case '6':
case '7':
case '8':
case '9':
519 width = 10 * width + c -
'0';
522 while (i <
n && isdigit (s[i]))
525 width = 10 * width + c -
'0';
531 case 'h':
case 'l':
case 'L':
532 if (modifier !=
'\0')
539 case 'd':
case 'i':
case 'o':
case 'u':
case 'x':
550 case 'e':
case 'f':
case 'g':
563 case 'c':
case 's':
case 'p':
case '%':
case '[':
564 if (modifier !=
'\0')
574 type, modifier) == 0)
593 std::size_t
n,
int width,
bool discard,
594 char& type,
char modifier)
598 std::string char_class;
600 std::size_t beg_idx = std::string::npos;
601 std::size_t end_idx = std::string::npos;
633 else if (s[i] ==
']')
637 while (i <
n && s[i] !=
']')
640 if (i <
n && s[i] ==
']')
657 if (beg_idx != std::string::npos && end_idx != std::string::npos)
659 end_idx - beg_idx + 1));
672 for (std::size_t i = 0; i <
n; i++)
677 <<
"width: " << elt->
width <<
"\n"
678 <<
"discard: " << elt->
discard <<
"\n"
682 std::cerr <<
"literal text\n";
684 std::cerr <<
"whitespace\n";
686 std::cerr << elt->
type <<
"\n";
689 <<
"modifier: " << elt->
modifier <<
"\n"
702 for (std::size_t i = 0; i <
n; i++)
708 case 'c':
case 's':
case '%':
case '[':
case '^':
732 for (std::size_t i = 0; i <
n; i++)
738 case 'd':
case 'i':
case 'o':
case 'u':
case 'x':
case 'X':
739 case 'e':
case 'f':
case 'g':
case 'E':
case 'G':
760 int p = -1,
const std::string&
f =
"",
761 char typ =
'\0',
char mod =
'\0')
762 : text (txt), args (
n), fw (
w), prec (p), flags (
f),
763 type (typ), modifier (
mod)
820 return length () > 0 ? m_fmt_elts[m_curr_idx] :
nullptr;
823 std::size_t
length (
void)
const {
return m_fmt_elts.size (); }
829 if (m_curr_idx >= length ())
840 bool last_elt_p (
void) {
return (m_curr_idx + 1 == length ()); }
842 void printme (
void)
const;
844 bool ok (
void)
const {
return (m_nconv >= 0); }
846 operator bool ()
const {
return ok (); }
850 void add_elt_to_list (
int args,
const std::string& flags,
int fw,
851 int prec,
char type,
char modifier);
853 void process_conversion (
const std::string& s, std::size_t& i,
855 int& args, std::string& flags,
int& fw,
856 int& prec,
char& modifier,
char& type);
858 void finish_conversion (
const std::string& s, std::size_t& i,
int args,
859 const std::string& flags,
int fw,
int prec,
860 char modifier,
char& type);
880 : m_nconv (0), m_curr_idx (0), m_fmt_elts (), m_buf ()
882 std::size_t
n = s.length ();
890 char modifier =
'\0';
893 bool have_more =
true;
894 bool empty_buf =
true;
909 empty_buf = (
m_buf.tellp () == 0);
926 have_more = (
m_buf.tellp () != 0);
965 for (std::size_t i = 0; i <
n; i++)
974 int fw,
int prec,
char type,
977 std::string text =
m_buf.str ();
994 std::size_t
n,
int& args,
995 std::string& flags,
int& fw,
996 int& prec,
char& modifier,
1014 case '-':
case '+':
case ' ':
case '0':
case '#':
1041 std::string tmp = s.substr (i);
1042 sscanf (tmp.c_str (),
"%d%n", &fw, &
nn);
1045 while (i <
n && isdigit (s[i]))
1050 if (i <
n && s[i] ==
'.')
1074 std::string tmp = s.substr (i);
1075 sscanf (tmp.c_str (),
"%d%n", &prec, &
nn);
1078 while (i <
n && isdigit (s[i]))
1092 case 'h':
case 'l':
case 'L':
1109 int args,
const std::string& flags,
1110 int fw,
int prec,
char modifier,
1115 case 'd':
case 'i':
case 'o':
case 'x':
case 'X':
1117 if (modifier ==
'L')
1124 case 'f':
case 'e':
case 'E':
case 'g':
case 'G':
1125 if (modifier ==
'h' || modifier ==
'l')
1132 case 's':
case 'p':
case '%':
1133 if (modifier !=
'\0')
1146 if (type !=
'%' || args != 0)
1167 for (std::size_t i = 0; i <
n; i++)
1172 <<
"args: " << elt->
args <<
"\n"
1173 <<
"flags: '" << elt->
flags <<
"'\n"
1174 <<
"width: " << elt->
fw <<
"\n"
1175 <<
"prec: " << elt->
prec <<
"\n"
1176 <<
"type: '" << elt->
type <<
"'\n"
1177 <<
"modifier: '" << elt->
modifier <<
"'\n"
1190 for (
unsigned int d =
n;
d;
d >>= 1)
1246 if (m_idx >= m_last)
1259 return eof () ? std::istream::traits_type::eof () : *m_idx++;
1261 return get_undelim ();
1265 int get_undelim (
void);
1272 {
return eof () ? std::istream::traits_type::eof () : *m_idx; }
1275 int peek_undelim (
void);
1281 void putback (
char = 0) {
if (! eof ()) --m_idx; }
1283 int getline (std::string& dest,
char delim);
1287 char * read (
char *buffer,
int size,
char *&new_start);
1293 void seekg (
char *old_idx) { m_idx = old_idx; }
1297 return (m_eob == m_buf + m_overlap && m_i_stream.eof ())
1298 || (m_flags & std::ios_base::eofbit);
1301 operator const void *(void)
1302 {
return (! eof () && ! m_flags) ?
this :
nullptr; }
1304 bool fail (
void) {
return m_flags & std::ios_base::failbit; }
1306 std::ios_base::iostate
rdstate (
void) {
return m_flags; }
1308 void setstate (std::ios_base::iostate
m) { m_flags = m_flags |
m; }
1311 = (std::ios_base::eofbit & ~std::ios_base::eofbit))
1313 m_flags = m_flags &
m;
1328 if (m_eob < m_buf + m_bufsize)
1329 return m_eob - m_idx;
1381 const std::string& delimiters,
1382 int longest_lookahead,
1384 : m_bufsize (bsize), m_i_stream (is), m_longest (longest_lookahead),
1385 m_delims (delimiters),
1386 m_flags (std::ios::failbit & ~std::ios::failbit)
1424 return std::istream::traits_type::eof ();
1436 retval = std::istream::traits_type::eof ();
1469 return std::istream::traits_type::eof ();
1477 std::size_t old_overlap = 0;
1528 retval = std::istream::traits_type::eof ();
1548 if (retval == std::istream::traits_type::eof ())
1613 for (i = 0; i < size && !
eof (); i++)
1616 memset (buffer, 0, size - i);
1630 int len = out.length ();
1634 && ch != std::istream::traits_type::eof ())
1658 whitespace_conversion = 1,
1659 literal_conversion = 2
1663 int bw = 0,
bool dis =
false,
char typ =
'\0',
1664 const std::string& ch_class = std::string ())
1665 : text (txt), width (
w), prec (p), bitwidth (bw),
1666 char_class (ch_class), type (typ), discard (dis),
1667 numeric (typ ==
'd' || typ ==
'u' || type ==
'f' || type ==
'n')
1671 : text (e.text), width (e.width), prec (e.prec),
1672 bitwidth (e.bitwidth), char_class (e.char_class), type (e.type),
1673 discard (e.discard), numeric (e.numeric)
1731 const std::string& who =
"textscan");
1747 std::size_t
numel (
void)
const {
return m_fmt_elts.size (); }
1757 return numel () > 0 ? m_fmt_elts[m_curr_idx] :
nullptr;
1764 if (m_curr_idx >=
numel ())
1775 void printme (
void)
const;
1777 bool ok (
void)
const {
return (m_nconv >= 0); }
1779 operator const void *(void)
const {
return ok () ? this :
nullptr; }
1793 {
return (m_output_container); }
1797 void add_elt_to_list (
unsigned int width,
int prec,
int bitwidth,
1800 const std::string& char_class = std::string ());
1802 void process_conversion (
const std::string& s, std::size_t& i,
1805 std::string parse_char_class (
const std::string& pattern)
const;
1807 int finish_conversion (
const std::string& s, std::size_t& i, std::size_t
n,
1808 unsigned int width,
int prec,
int bitwidth,
1810 bool discard,
char& type);
1846 textscan (
const std::string& who_arg =
"textscan",
1847 const std::string& encoding =
"utf-8");
1873 std::list<octave_value>& retval,
1887 std::string& val)
const;
1890 std::string& val)
const;
1893 std::string& val)
const;
1896 std::string& val)
const;
1903 const std::string& ends)
const;
1906 bool case_sensitive =
true)
const;
1916 return ((m_delim_table.empty ()
1917 && (isspace (ch) || ch == m_eol1 || ch == m_eol2))
1918 || m_delim_table[ch] !=
'\0');
1922 {
return m_whitespace_table[ch & 0xff]; }
1992 const std::string& who_arg)
1996 std::size_t
n = s.length ();
2000 unsigned int width = -1;
2003 bool discard =
false;
2006 bool have_more =
true;
2031 if (s[i] ==
'%' && (i+1 ==
n || s[i+1] !=
'%'))
2043 have_more = (
m_buf.tellp () != 0);
2045 else if (isspace (s[i]))
2047 while (++i <
n && isspace (s[i]))
2061 while (i <
n && ! isspace (s[i])
2062 && (s[i] !=
'%' || (i+1 <
n && s[i+1] ==
'%')))
2093 std::size_t
n =
numel ();
2095 for (std::size_t i = 0; i <
n; i++)
2105 bool discard,
char type,
2106 const std::string& char_class)
2108 std::string text =
m_buf.str ();
2110 if (! text.empty ())
2128 std::size_t& i, std::size_t
n)
2133 bool discard =
false;
2139 bool have_width =
false;
2155 case '0':
case '1':
case '2':
case '3':
case '4':
2156 case '5':
case '6':
case '7':
case '8':
case '9':
2162 width = width * 10 + c -
'0';
2165 while (i <
n && isdigit (s[i]))
2168 width = width * 10 + c -
'0';
2172 if (i <
n && s[i] ==
'.')
2176 while (i <
n && isdigit (s[i]))
2179 prec = prec * 10 + c -
'0';
2189 m_buf << (type = s[i++]);
2201 else if (s[i] ==
'1' && i+1 <
n && s[i+1] ==
'6')
2211 else if (s[i] ==
'3' && i+1 <
n && s[i+1] ==
'2')
2217 else if (s[i] ==
'6' && i+1 <
n && s[i+1] ==
'4')
2245 m_buf << (type = s[i++]);
2249 if (s[i] ==
'3' && i+1 <
n && s[i+1] ==
'2')
2256 else if (s[i] ==
'6' && i+1 <
n && s[i+1] ==
'4')
2270 m_buf << (type = s[i++]);
2275 case 's':
case 'q':
case '[':
case 'c':
2278 m_buf << (type = s[i++]);
2289 width =
static_cast<unsigned int> (-1);
2293 discard, type) == 0)
2299 error (
"%s: '%%%c' is not a valid format specifier",
2300 who.c_str (), s[i]);
2325 int len = pattern.length ();
2329 std::string retval (256,
'\0');
2330 std::string mask (256,
'\0');
2332 int in = 0, out = 0;
2333 unsigned char ch, prev = 0;
2342 mask[pattern[in]] =
'\1';
2343 retval[out++] = pattern[in++];
2345 bool prev_was_range =
false;
2346 bool prev_prev_was_range =
false;
2347 for (; in <
len; in++)
2349 bool was_range =
false;
2354 if (prev ==
'-' && in > 1 && isalnum (ch) && ! prev_prev_was_range)
2356 unsigned char start_of_range = pattern[in-2];
2357 if (start_of_range < ch
2358 && ((isupper (ch) && isupper (start_of_range))
2359 || (islower (ch) && islower (start_of_range))
2360 || (isdigit (ch) && isdigit (start_of_range))
2366 for (
int i = start_of_range; i <= ch; i++)
2368 if (mask[i] ==
'\0')
2378 if (mask[ch]++ == 0)
2382 "%s: [...] contains two '%c's",
2385 if (prev ==
'-' && mask[
'-'] >= 2)
2387 (
"Octave:textscan-pattern",
2388 "%s: [...] contains two '-'s outside range expressions",
2392 prev_prev_was_range = prev_was_range;
2393 prev_was_range = was_range;
2399 for (
int i = 0; i < 256; i++)
2404 retval.resize (out);
2411 std::size_t
n,
unsigned int width,
2412 int prec,
int bitwidth,
2418 std::string char_class;
2420 std::size_t beg_idx = std::string::npos;
2421 std::size_t end_idx = std::string::npos;
2445 else if (s[i] ==
']')
2449 while (i <
n && s[i] !=
']')
2452 if (i <
n && s[i] ==
']')
2465 if (beg_idx != std::string::npos && end_idx != std::string::npos)
2467 end_idx - beg_idx + 1));
2479 std::size_t
n =
numel ();
2481 for (std::size_t i = 0; i <
n; i++)
2486 <<
"width: " << elt->
width <<
"\n"
2487 <<
"digits " << elt->
prec <<
"\n"
2488 <<
"bitwidth: " << elt->
bitwidth <<
"\n"
2489 <<
"discard: " << elt->
discard <<
"\n"
2493 std::cerr <<
"literal text\n";
2495 std::cerr <<
"whitespace\n";
2497 std::cerr << elt->
type <<
"\n";
2512 std::string first_line (20,
' ');
2516 if (! first_line.empty () && first_line.back () == ts.
m_eol1)
2517 first_line.pop_back ();
2519 std::istringstream strstr (first_line);
2526 int max_empty = 1000;
2532 bool already_skipped_delim =
false;
2551 already_skipped_delim =
true;
2559 if (val.imag () == 0)
2566 if (! already_skipped_delim)
2585 : m_who (who_arg), m_encoding (encoding),
m_buf (), m_whitespace_table (),
2586 m_delim_table (), m_delims (), m_comment_style (), m_comment_len (0),
2587 m_comment_char (-2), m_buffer_size (0), m_date_locale (),
2589 m_empty_value (numeric_limits<double>::
NaN ()),
2590 m_exp_chars (
"edED"), m_header_lines (0), m_treat_as_empty (),
2591 m_treat_as_empty_len (0), m_whitespace (
" \b\t"), m_eol1 (
'\r'),
2592 m_eol2 (
'\n'), m_return_on_error (1), m_collect_output (false),
2593 multiple_delims_as_one (false), m_default_exp (true), m_lines (0)
2611 std::ios::iostate
state = isp.rdstate ();
2614 isp.setstate (
state);
2626 error (
"%s: invalid format specified",
m_who.c_str ());
2629 error (
"%s: no valid format conversion specifiers",
m_who.c_str ());
2634 getline (isp, dummy,
static_cast<char> (
m_eol2));
2646 else if (ntimes > 0)
2650 buf_size =
std::max (buf_size, ntimes);
2656 max_lookahead, buf_size);
2678 done_after = fmt_list.
numel () + 1;
2683 done_after = fmt_list.
out_buf ().size () + 1;
2685 std::list<octave_value> out = fmt_list.
out_buf ();
2693 bool merge_with_prev[fmt_list.
numel ()];
2698 for (
const auto& col : out)
2700 if (col.type_id () == prev_type
2702 merge_with_prev[conv++] =
true;
2704 merge_with_prev[conv++] =
false;
2706 prev_type = col.type_id ();
2713 error (
"%s: No conversions specified",
m_who.c_str ());
2719 row < ntimes || ntimes == -1;
2722 if (row == 0 || row >= size)
2725 for (
auto& col : out)
2732 if ((err & ~1) > 0 || ! is || (
m_lines >= ntimes && ntimes > -1))
2738 error (
"%s: Read error in field %d of row %" OCTAVE_IDX_TYPE_FORMAT,
2739 m_who.c_str (), done_after + 1, row + 1);
2742 bool uneven_columns =
false;
2744 uneven_columns =
true;
2745 else if (isp.eof ())
2748 isp.seekg (-1, std::ios_base::end);
2749 int last_char = isp.get ();
2750 isp.setstate (isp.eofbit);
2751 uneven_columns = (last_char !=
m_eol1 && last_char !=
m_eol2);
2760 done_after = out.size () + 1;
2762 int valid_rows = (row == ntimes
2764 : ((err & 1) && (err & 8)) ? row : row+1);
2772 for (
auto& col : out)
2775 if (i == done_after && uneven_columns)
2792 for (
auto& col : out)
2794 if (! merge_with_prev[conv++])
2796 if (prev_type != -1)
2803 prev_type = col.type_id ();
2807 ra_idx(1) = group_size++;
2826 unsigned int width_left = fmt.
width;
2851 if (ch >=
'0' && ch <=
'9')
2853 while (width_left-- && is && (ch = is.
get ()) >=
'0' && ch <=
'9')
2854 retval = retval * 10 + (ch -
'0');
2859 if (ch ==
'.' && width_left)
2861 double multiplier = 1;
2862 int precision = fmt.
prec;
2867 if (precision == -1)
2873 for (i = 0; i < precision; i++)
2875 if (width_left-- && is && (ch = is.
get ()) >=
'0' && ch <=
'9')
2876 retval += (ch -
'0') * (multiplier *= 0.1);
2885 if ((i == precision || ! width_left) && (ch = is.
get ()) >=
'5'
2887 retval += multiplier;
2899 while (width_left-- && is && (ch = is.
get ()) >=
'0' && ch <=
'9')
2906 bool used_exp =
false;
2907 if (valid && width_left > 1 &&
m_exp_chars.find (ch) != std::string::npos)
2910 if (ch1 ==
'-' || ch1 ==
'+' || (ch1 >=
'0' && ch1 <=
'9'))
2921 else if (ch1 ==
'-')
2928 while (width_left-- && is && (ch = is.
get_undelim ()) >=
'0' && ch <=
'9')
2930 exp = exp*10 + ch -
'0';
2934 if (ch != std::istream::traits_type::eof () && width_left)
2937 double multiplier =
pown (10, exp);
2939 retval *= multiplier;
2941 retval /= multiplier;
2947 if (! used_exp && ch != std::istream::traits_type::eof () && width_left)
2951 if (! valid && width_left >= 3 && is.
remaining () >= 3)
2971 return retval * sign;
2984 bool as_empty =
false;
2988 if (ch ==
'+' || ch ==
'-')
2992 if (ch2 ==
'i' || ch2 ==
'j')
2999 char *pos = is.
tellg ();
3020 im = (ch ==
'+') ? value : -value;
3028 char *pos = is.
tellg ();
3059 char *look = is.
read (&look_buf[0], look_buf.size (), pos);
3068 if (!
strncmp (s.c_str (), look, s.size ()))
3072 is.
read (&look_buf[0], s.size (), pos);
3079 if (! is.
eof () && ! as_empty)
3085 if (ch ==
'i' || ch ==
'j')
3091 else if (ch ==
'+' || ch ==
'-')
3127 std::string& val)
const
3129 int c1 = std::istream::traits_type::eof ();
3130 std::ostringstream obuf;
3132 while (is && ((c1 = (is && ! is.
eof ())
3134 : std::istream::traits_type::eof ())
3135 != std::istream::traits_type::eof ())
3136 && pattern.find (c1) == std::string::npos)
3137 obuf << static_cast<char> (c1);
3141 if (c1 != std::istream::traits_type::eof ())
3152 const std::string& ends)
const
3154 std::string retval (
"");
3161 retval = retval +
next;
3163 int last = (! is.
eof ()
3164 ? is.
get_undelim () : std::istream::traits_type::eof ());
3166 if (last != std::istream::traits_type::eof ())
3171 retval = retval +
static_cast<char> (last);
3172 for (
int i = 0; i < delimiters.
numel (); i++)
3174 std::string delim = delimiters(i).string_value ();
3175 std::size_t start = (retval.length () > delim.length ()
3176 ? retval.length () - delim.length ()
3178 std::string may_match = retval.substr (start);
3179 if (may_match == delim)
3182 retval = retval.substr (0, start);
3190 while (! done && is && ! is.
eof ());
3201 std::string& val)
const
3206 unsigned int width = fmt.
width;
3208 for (i = 0; i < width; i++)
3211 if (i >= val.length ())
3212 val.append (
std::max (val.length (),
3213 static_cast<std::size_t
> (16)),
'\0');
3216 if (
is_delim (ch) || ch == std::istream::traits_type::eof ())
3224 val = val.substr (0, i);
3233 ends[i] = tmp.back ();
3249 std::string& val)
const
3251 int c1 = std::istream::traits_type::eof ();
3252 std::ostringstream obuf;
3254 while (is && pattern.find (c1 = is.
get_undelim ()) != std::string::npos)
3255 obuf << static_cast<char> (c1);
3258 if (c1 != std::istream::traits_type::eof ())
3287 val = val + '"' + val1;
3302 std::string& val)
const
3304 val.resize (fmt.
width);
3306 for (
unsigned int i = 0; is && i < fmt.
width; i++)
3309 if (ch != std::istream::traits_type::eof ())
3336 if (fmt.
type ==
'f' || fmt.
type ==
'n')
3346 if (ov.
isreal () && v.imag () == 0)
3358 if (ov.
isreal () && v.imag () == 0)
3421 if (fmt.
type ==
'd')
3434 if (fmt.
type ==
'd')
3453 std::string vv (
" ");
3495 std::list<octave_value>& retval,
3499 auto out = retval.begin ();
3500 bool no_conversions =
true;
3502 bool conversion_failed =
false;
3503 bool nothing_worked =
true;
3507 for (std::size_t i = 0; i < fmt_list.
numel (); i++)
3509 bool this_conversion_failed =
false;
3518 warning (
"%s: conversion %c not yet implemented",
3539 error (
"Unknown format element '%c'",
elem->type);
3544 if (!
elem->discard)
3545 no_conversions =
false;
3556 this_conversion_failed =
true;
3560 char *pos = is.
tellg ();
3562 this_conversion_failed =
true;
3569 if (!
elem->discard)
3573 char *pos = is.
tellg ();
3592 if (this_conversion_failed)
3594 if (is.
tellg () == pos && ! conversion_failed)
3598 conversion_failed =
true;
3601 this_conversion_failed =
false;
3603 else if (! done && ! conversion_failed)
3604 nothing_worked =
false;
3610 return no_conversions
3611 + (is.
eof () ? 2 : 0)
3612 + (conversion_failed ? 4 : 0)
3613 + (nothing_worked ? 8 : 0);
3621 int last = args.
length ();
3625 error (
"%s: %d parameters given, but only %d values",
3629 bool have_delims =
false;
3630 for (
int i = 0; i < last; i += 2)
3632 std::string param = args(i).xstring_value (
"%s: Invalid parameter type <%s> for parameter %d",
3634 args(i).type_name ().c_str (),
3636 std::transform (param.begin (), param.end (), param.begin (), ::tolower);
3638 if (param ==
"delimiter")
3640 bool invalid =
true;
3641 if (args(i+1).is_string ())
3645 m_delims = args(i+1).string_value ();
3646 if (args(i+1).is_sq_string ())
3649 else if (args(i+1).iscell ())
3673 error (
"%s: Delimiters must be either a string or cell array of strings",
3676 else if (param ==
"commentstyle")
3678 if (args(i+1).is_string ())
3683 else if (args(i+1).iscell ())
3690 error (
"%s: CommentStyle must be either a string or cell array of one or two strings",
3694 error (
"%s: CommentStyle must be either a string or cell array of one or two strings",
3705 else if (param ==
"treatasempty")
3707 bool invalid =
false;
3708 if (args(i+1).is_string ())
3713 else if (args(i+1).iscell ())
3727 error (
"%s: TreatAsEmpty must be either a string or cell array of one or two strings",
3732 else if (param ==
"collectoutput")
3734 m_collect_output = args(i+1).xbool_value (
"%s: CollectOutput must be logical or numeric",
3737 else if (param ==
"emptyvalue")
3739 m_empty_value = args(i+1).xscalar_value (
"%s: EmptyValue must be numeric",
m_who.c_str ());
3741 else if (param ==
"headerlines")
3743 m_header_lines = args(i+1).xscalar_value (
"%s: HeaderLines must be numeric",
m_who.c_str ());
3745 else if (param ==
"bufsize")
3747 m_buffer_size = args(i+1).xscalar_value (
"%s: BufSize must be numeric",
m_who.c_str ());
3749 else if (param ==
"multipledelimsasone")
3752 +1).xbool_value (
"%s: MultipleDelimsAsOne must be logical or numeric",
m_who.c_str ());
3754 else if (param ==
"returnonerror")
3756 m_return_on_error = args(i+1).xbool_value (
"%s: ReturnOnError must be logical or numeric",
3759 else if (param ==
"whitespace")
3761 m_whitespace = args(i+1).xstring_value (
"%s: Whitespace must be a character string",
3764 else if (param ==
"expchars")
3766 m_exp_chars = args(i+1).xstring_value (
"%s: ExpChars must be a character string",
m_who.c_str ());
3769 else if (param ==
"endofline")
3772 std::string s = args(i+1).xstring_value (R
"(%s: EndOfLine must be at most one character or '\r\n')",
3774 if (args(i+1).is_sq_string ())
3776 int l = s.length ();
3792 error (R
"(%s: EndOfLine must be at most one character or '\r\n')",
3796 error (
"%s: unrecognized option '%s'",
m_who.c_str (), param.c_str ());
3800 for (
unsigned int j = 0; j <
m_delims.length (); j++)
3810 if (delim.length () == 1)
3818 for (
unsigned int i = 0; i <
m_whitespace.length (); i++)
3833 for (
unsigned int i = 0; i < 256; i++)
3839 for (
unsigned int i = 0; i <
m_delims.length (); i++)
3849 int c1 = std::istream::traits_type::eof ();
3850 bool found_comment =
false;
3854 found_comment =
false;
3857 && (c1 = is.
get_undelim ()) != std::istream::traits_type::eof ()
3869 char *pos = is.
tellg ();
3878 found_comment =
true;
3883 std::string eol (3,
'\0');
3898 std::string last = end_c.substr (end_c.size () - 1);
3899 std::string may_match (
"");
3906 may_match = may_match + dummy + last;
3907 if (may_match.length () > end_c.length ())
3909 std::size_t start = may_match.length ()
3911 may_match = may_match.substr (start);
3914 while (may_match != end_c && is && ! is.
eof ());
3924 while (found_comment);
3926 if (c1 != std::istream::traits_type::eof ())
3938 bool case_sensitive)
const
3944 char *pos = is.
tellg ();
3946 std::string tmp (max_len,
'\0');
3947 char *look = is.
read (&tmp[0], tmp.size (), pos);
3954 int (*compare)(
const char *,
const char *, std::size_t);
3957 for (i = 0; i < targets.
numel (); i++)
3959 std::string s = targets (i).string_value ();
3960 if (! (*compare) (s.c_str (), look, s.size ()))
3962 is.
read (&tmp[0], s.size (), pos);
3967 if (i == targets.
numel ())
3993 != std::istream::traits_type::eof ())
4001 if (c1 != std::istream::traits_type::eof ())
4031 != std::istream::traits_type::eof ())
4058 for (
unsigned int i = 0; i < fmt.
width; i++)
4061 if (ch != fmt.
text[i])
4063 if (ch != std::istream::traits_type::eof ())
4111 bool strip_newline,
const std::string&
who)
4116 ::error (
"%s: unable to read from stdin while running interactively",
4132 std::istream& is = *isp;
4134 std::ostringstream buf;
4141 while (is && (c = is.get ()) != std::istream::traits_type::eof ())
4148 if (! strip_newline)
4149 buf << static_cast<char> (c);
4153 if (c != std::istream::traits_type::eof ())
4159 if (! strip_newline)
4160 buf << static_cast<char> (c);
4170 if (! strip_newline)
4171 buf << static_cast<char> (c);
4176 buf << static_cast<char> (c);
4178 if (max_len > 0 && char_count == max_len)
4183 if (! is.eof () && char_count > 0)
4188 int disgusting_compatibility_hack = is.get ();
4190 is.putback (disgusting_compatibility_hack);
4193 if (is.good () || (is.eof () && char_count > 0))
4195 retval = buf.str ();
4203 if (is.eof () && char_count == 0)
4215 const std::string&
who)
4222 const std::string&
who)
4233 ::error (
"%s: unable to read from stdin while running interactively",
4249 std::istream& is = *isp;
4255 while (is && (c = is.get ()) != std::istream::traits_type::eof ())
4258 if (c ==
'\r' || (c ==
'\n' && lastc !=
'\r'))
4268 if (c ==
'\r' && is.peek () ==
'\n')
4284 template <
typename T>
4285 static std::istream&
4294 is >> std::oct >> value >> std::dec;
4299 is >> std::hex >> value >> std::dec;
4304 int c1 = std::istream::traits_type::eof ();
4306 while (is && (c1 = is.get ()) != std::istream::traits_type::eof ()
4310 if (c1 != std::istream::traits_type::eof ())
4314 int c2 = is.peek ();
4316 if (c2 ==
'x' || c2 ==
'X')
4319 if (std::isxdigit (is.peek ()))
4320 is >> std::hex >> value >> std::dec;
4326 if (c2 ==
'0' || c2 ==
'1' || c2 ==
'2'
4327 || c2 ==
'3' || c2 ==
'4' || c2 ==
'5'
4328 || c2 ==
'6' || c2 ==
'7')
4329 is >> std::oct >> value >> std::dec;
4330 else if (c2 ==
'8' || c2 ==
'9')
4362 if ((is.rdstate () & std::ios::failbit) && value != T ())
4363 is.clear (is.rdstate () & ~std::ios::failbit);
4367 if (! (is.rdstate () & std::ios::failbit))
4373 template <
typename T>
4374 static std::istream&
4383 auto orig_pos = is.tellg ();
4385 is.width (fmt.
width);
4388 std::istringstream ss (strbuf);
4401 is.seekg (orig_pos, is.beg);
4403 int chars_read = ss.tellg ();
4406 is.width (chars_read);
4413 is.setstate (std::ios::failbit);
4424 octave_scan<> (std::istream& is,
const scanf_format_elt& fmt,
double *valptr)
4426 double& ref = *valptr;
4436 int c1 = std::istream::traits_type::eof ();
4438 while (is && (c1 = is.get ()) != std::istream::traits_type::eof ()
4442 if (c1 != std::istream::traits_type::eof ())
4446 ref = read_value<double> (is);
4459 template <
typename T>
4471 if (idx == max_size && ! discard)
4476 mval.
resize (nr, max_size / nr, 0.0);
4478 mval.
resize (max_size, 1, 0.0);
4486 data[idx++] = *(valptr);
4495 #define DO_WHITESPACE_CONVERSION() \
4498 int c = std::istream::traits_type::eof (); \
4500 while (is && (c = is.get ()) != std::istream::traits_type::eof () \
4504 if (c != std::istream::traits_type::eof ()) \
4509 #define DO_LITERAL_CONVERSION() \
4512 int c = std::istream::traits_type::eof (); \
4514 int n = fmt.length (); \
4517 while (i < n && is \
4518 && (c = is.get ()) != std::istream::traits_type::eof ()) \
4520 if (c == static_cast<unsigned char> (fmt[i])) \
4533 is.setstate (std::ios::failbit); \
4537 #define DO_PCT_CONVERSION() \
4540 int c = is.get (); \
4542 if (c != std::istream::traits_type::eof ()) \
4547 is.setstate (std::ios::failbit); \
4551 is.setstate (std::ios::failbit); \
4555 #define BEGIN_C_CONVERSION() \
4556 is.unsetf (std::ios::skipws); \
4558 int width = (elt->width ? elt->width : 1); \
4560 std::string tmp (width, '\0'); \
4562 int c = std::istream::traits_type::eof (); \
4565 while (is && n < width \
4566 && (c = is.get ()) != std::istream::traits_type::eof ()) \
4567 tmp[n++] = static_cast<char> (c); \
4569 if (n > 0 && c == std::istream::traits_type::eof ()) \
4576 #define BEGIN_S_CONVERSION() \
4577 int width = elt->width; \
4585 tmp = std::string (width, '\0'); \
4587 int c = std::istream::traits_type::eof (); \
4591 while (is && (c = is.get ()) != std::istream::traits_type::eof ()) \
4593 if (! isspace (c)) \
4595 tmp[n++] = static_cast<char> (c); \
4600 while (is && n < width \
4601 && (c = is.get ()) != std::istream::traits_type::eof ()) \
4609 tmp[n++] = static_cast<char> (c); \
4612 if (n > 0 && c == std::istream::traits_type::eof ()) \
4619 is >> std::ws >> tmp; \
4625 #define BEGIN_CHAR_CLASS_CONVERSION() \
4626 int width = elt->width; \
4633 width = std::numeric_limits<int>::max (); \
4635 std::ostringstream buf; \
4637 std::string char_class = elt->char_class; \
4639 int c = std::istream::traits_type::eof (); \
4641 if (elt->type == '[') \
4643 int chars_read = 0; \
4644 while (is && chars_read++ < width \
4645 && (c = is.get ()) != std::istream::traits_type::eof () \
4646 && char_class.find (c) != std::string::npos) \
4647 buf << static_cast<char> (c); \
4651 int chars_read = 0; \
4652 while (is && chars_read++ < width \
4653 && (c = is.get ()) != std::istream::traits_type::eof () \
4654 && char_class.find (c) == std::string::npos) \
4655 buf << static_cast<char> (c); \
4658 if (width == std::numeric_limits<int>::max () \
4659 && c != std::istream::traits_type::eof ()) \
4665 is.setstate (std::ios::failbit); \
4666 else if (c == std::istream::traits_type::eof ()) \
4672 #define FINISH_CHARACTER_CONVERSION() \
4675 if (encoding ().compare ("utf-8")) \
4676 tmp = string::u8_from_encoding (who, tmp, encoding ()); \
4677 width = tmp.length (); \
4685 conversion_count++; \
4689 if (data_index == max_size) \
4693 if (all_char_conv) \
4695 if (one_elt_size_spec) \
4696 mval.resize (1, max_size, 0.0); \
4698 mval.resize (nr, max_size / nr, 0.0); \
4700 panic_impossible (); \
4703 mval.resize (nr, max_size / nr, 0.0); \
4705 mval.resize (max_size, 1, 0.0); \
4707 data = mval.fortran_vec (); \
4710 data[data_index++] = static_cast<unsigned char> \
4721 bool one_elt_size_spec,
4723 const std::string&
who)
4728 ::error (
"%s: unable to read from stdin while running interactively",
4733 conversion_count = 0;
4739 if (nr == 0 || nc == 0)
4741 if (one_elt_size_spec)
4744 return Matrix (nr, nc, 0.0);
4762 if (one_elt_size_spec)
4765 mval.
resize (1, max_size, 0.0);
4774 mval.
resize (nr, nc, 0.0);
4775 max_size = max_conv = nr * nc;
4779 mval.
resize (nr, 32, 0.0);
4791 mval.
resize (nr, nc, 0.0);
4793 max_conv = max_size;
4798 mval.
resize (nr, 32, 0.0);
4805 mval.
resize (32, 1, 0.0);
4813 std::istream& is = *isp;
4817 std::ios::fmtflags flags = is.flags ();
4832 || elt->
type ==
'%')
4833 && max_conv > 0 && conversion_count == max_conv))
4840 if (all_char_conv && one_elt_size_spec)
4843 final_nc = data_index;
4848 final_nc = (data_index - 1) / nr + 1;
4853 else if (data_index == max_size)
4859 if (one_elt_size_spec)
4860 mval.
resize (1, max_size, 0.0);
4862 mval.
resize (nr, max_size / nr, 0.0);
4867 mval.
resize (nr, max_size / nr, 0.0);
4869 mval.
resize (max_size, 1, 0.0);
4874 std::string fmt = elt->
text;
4900 data_index, conversion_count,
4901 nr, max_size, discard);
4909 data_index, conversion_count,
4910 nr, max_size, discard);
4918 data_index, conversion_count,
4919 nr, max_size, discard);
4926 case 'o':
case 'u':
case 'x':
case 'X':
4934 data_index, conversion_count,
4935 nr, max_size, discard);
4943 data_index, conversion_count,
4944 nr, max_size, discard);
4952 data_index, conversion_count,
4953 nr, max_size, discard);
4960 case 'e':
case 'f':
case 'g':
4966 data_index, conversion_count,
4967 nr, max_size, discard);
4998 error (
who,
"unsupported format specifier");
5002 error (
who,
"internal format error");
5010 else if (is.eof () || ! is)
5014 if (one_elt_size_spec)
5017 final_nc = data_index;
5019 else if (data_index > nr)
5022 final_nc = (data_index - 1) / nr + 1;
5026 final_nr = data_index;
5032 if (data_index > nr)
5035 final_nc = (data_index - 1) / nr + 1;
5039 final_nr = data_index;
5045 final_nr = data_index;
5051 if (! is.eof () && is.rdstate () & std::ios::failbit)
5053 error (
who,
"format failed to match");
5054 is.clear (is.rdstate () & (~std::ios::failbit));
5060 &&
name () ==
"stdin")
5074 error (
who,
"internal format error");
5078 if (
m_nconv == 0 && ++trips == num_fmt_elts)
5080 if (all_char_conv && one_elt_size_spec)
5083 final_nc = data_index;
5088 final_nc = (data_index - 1) / nr + 1;
5101 || conversion_count < max_conv));
5106 mval.
resize (final_nr, final_nc, 0.0);
5119 const std::string&
who)
5123 conversion_count = 0;
5134 ::error (
"%s: invalid format specified",
who.c_str ());
5139 bool one_elt_size_spec;
5143 retval =
do_scanf (fmt_list, nr, nc, one_elt_size_spec,
5144 conversion_count,
who);
5161 std::istream& is = *isp;
5163 std::ios::fmtflags flags = is.flags ();
5167 std::string fmt = elt->
text;
5236 case 'o':
case 'u':
case 'x':
case 'X':
5282 case 'e':
case 'f':
case 'g':
5337 error (
who,
"unsupported format specifier");
5341 error (
who,
"internal format error");
5346 if (
ok () && is.fail ())
5348 error (
"%s: read error",
who.c_str ());
5355 &&
name () ==
"stdin")
5377 std::istream& is = *isp;
5384 ::error (
"%s: invalid format specified",
who.c_str ());
5409 retval(num_values++) = tmp;
5430 elt = fmt_list.
next ();
5444 const std::string&
who,
5450 ::error (
"%s: unable to read from stdin while running interactively",
5463 retval =
scanner.scan (*isp, fmt, ntimes, options, read_count);
5500 : m_values (args), m_val_idx (0), m_elt_idx (0),
5501 m_n_vals (m_values.length ()), m_n_elts (0), m_have_data (false),
5528 int int_value (
void);
5530 operator bool ()
const {
return (m_curr_state ==
ok); }
5596 double dval = val(idx);
5599 || dval < 0 || dval > 255)
5607 std::string sval (
n,
'\0');
5622 if (type ==
'c' && ! retval.
is_string ())
5626 if (
math::x_nint (dval) == dval && dval >= 0 && dval < 256)
5627 retval =
static_cast<char> (dval);
5649 if (type ==
's' || type ==
'c')
5685 template <
typename T>
5688 int sa_2, T arg,
const std::string&
who)
5695 retval =
format (os, fmt, sa_1, sa_2, arg);
5699 retval =
format (os, fmt, sa_1, arg);
5703 retval =
format (os, fmt, arg);
5707 ::error (
"%s: internal error handling format",
who.c_str ());
5716 int nsa,
int sa_1,
int sa_2,
const std::string& arg,
5717 const std::string&
who)
5720 ::error (
"%s: internal error handling format",
who.c_str ());
5722 std::string flags = elt->
flags;
5724 bool left = flags.find (
'-') != std::string::npos;
5726 std::size_t
len = arg.length ();
5728 std::size_t prec = (nsa > 1 ? sa_2 : (elt->
prec == -1 ?
len : elt->
prec));
5730 std::string print_str = prec < arg.length () ? arg.substr (0, prec) : arg;
5732 std::size_t fw = (nsa > 0 ? sa_1 : (elt->
fw == -1 ?
len : elt->
fw));
5734 os << std::setw (fw) << (
left ?
std::left : std::right) << print_str;
5736 return len > fw ?
len : fw;
5761 if (ival.
value () <= limit)
5771 if (dval ==
math::fix (dval) && dval <= limit)
5790 return ov_is_ge_zero.
is_true ();
5798 if (dval ==
math::fix (dval) && dval >= 0 && dval <= limit)
5808 std::string tfmt = elt->
text;
5810 tfmt.replace (tfmt.rfind (elt->
type), 1,
"g");
5818 int nsa,
int sa_1,
int sa_2,
5820 const std::string&
who)
5824 std::string tfmt = elt->
text;
5830 std::string::size_type i1, i2;
5832 tfmt.replace ((i1 = tfmt.rfind (elt->
type)), 1, 1,
's');
5834 if ((i2 = tfmt.rfind (
'.')) != std::string::npos && i2 < i1)
5836 tfmt.erase (i2, i1-i2);
5837 if (elt->
prec == -2)
5844 if (elt->
flags.find (
'+') != std::string::npos)
5845 tval = (dval < 0 ?
"-Inf" :
"+Inf");
5847 tval = (dval < 0 ?
"-Inf" :
"Inf");
5851 if (elt->
flags.find (
'+') != std::string::npos)
5857 retval +=
do_printf_conv (os, tfmt.c_str (), nsa, sa_1, sa_2, tval,
5862 static std::string llmod
5863 = (
sizeof (long) ==
sizeof (int64_t) ?
"l" :
"ll");
5865 char type = elt->
type;
5869 case 'd':
case 'i':
case 'c':
5875 tfmt.replace (tfmt.rfind (type), 1, llmod + type);
5891 case 'o':
case 'x':
case 'X':
case 'u':
5897 tfmt.replace (tfmt.rfind (type), 1, llmod + type);
5913 case 'f':
case 'e':
case 'E':
5926 error (
who,
"invalid format specifier");
5938 ::error (
"%s: invalid field width, must be integer >= 0 and <= INT_MAX",
5945 const std::string&
who)
5957 std::ostream& os = *osp;
5970 ::error (
"%s: internal error handling format",
who.c_str ());
5973 int nsa = (elt->
fw == -2) + (elt->
prec == -2);
6002 if (elt->
type ==
'%')
6007 else if (elt->
args == 0 && ! elt->
text.empty ())
6010 retval += (elt->
text.length ());
6012 else if (elt->
type ==
's' || elt->
type ==
'c')
6065 const std::string&
who)
6070 ::error (
"%s: invalid format specified",
who.c_str ());
6086 std::ostream& os = *osp;
6117 err_num = (
m_fail ? -1 : 0);
6131 error (
who, std::string (
"stream not open for ") + rw);
6140 retval =
m_rep->flush ();
6151 retval =
m_rep->getl (max_len, err,
who);
6158 const std::string&
who)
6170 if (conv_err || max_len < 0)
6173 ::error (
"%s: invalid maximum length specified",
who.c_str ());
6177 return getl (max_len, err,
who);
6186 retval =
m_rep->gets (max_len, err,
who);
6193 const std::string&
who)
6205 if (conv_err || max_len < 0)
6208 ::error (
"%s: invalid maximum length specified",
who.c_str ());
6212 return gets (max_len, err,
who);
6221 retval =
m_rep->skipl (count, err,
who);
6228 const std::string&
who)
6245 if (conv_err || count < 0)
6248 ::error (
"%s: invalid number of lines specified",
6267 off_t orig_pos =
m_rep->tell ();
6274 off_t eof_pos =
m_rep->tell ();
6286 status =
m_rep->seek (offset, origin);
6291 off_t desired_pos =
m_rep->tell ();
6295 if (desired_pos > eof_pos || desired_pos < 0)
6326 off_t xoffset = val.
value ();
6334 std::string xorigin = tc_origin.
xstring_value (
"fseek: invalid value for origin");
6336 if (xorigin ==
"bof")
6338 else if (xorigin ==
"cof")
6340 else if (xorigin ==
"eof")
6353 else if (xorigin == 0)
6355 else if (xorigin == 1)
6363 ::error (
"fseek: invalid value for origin");
6365 retval =
seek (xoffset, origin);
6369 error (
"fseek: failed to seek to requested position");
6380 retval =
m_rep->tell ();
6394 bool retval =
false;
6397 retval =
m_rep->is_open ();
6412 template <
typename SRC_T,
typename DST_T>
6418 bool do_float_fmt_conv,
bool do_NA_conv,
6421 typedef typename DST_T::element_type dst_elt_type;
6425 dst_elt_type *conv_data = conv.fortran_vec ();
6429 for (
auto it = input_buf_list.cbegin (); it != input_buf_list.cend (); it++)
6431 SRC_T *data =
static_cast<SRC_T *
> (*it);
6433 if (swap || do_float_fmt_conv)
6441 swap_bytes<sizeof (SRC_T)> (&data[i]);
6442 else if (do_float_fmt_conv)
6454 conv_data[j] = data[i];
6463 swap_bytes<sizeof (SRC_T)> (&data[i]);
6464 else if (do_float_fmt_conv)
6469 conv_data[j] = data[i];
6481 conv_data[j] = data[i];
6488 conv_data[j] = data[i];
6495 input_buf_list.clear ();
6498 conv_data[i] = dst_elt_type (0);
6506 bool swap,
bool do_float_fmt_conv,
bool do_NA_conv,
6509 #define TABLE_ELT(T, U, V, W) \
6510 conv_fptr_table[oct_data_conv::T][oct_data_conv::U] = convert_and_copy<V, W>
6512 #define FILL_TABLE_ROW(T, V) \
6513 TABLE_ELT (T, dt_int8, V, int8NDArray); \
6514 TABLE_ELT (T, dt_uint8, V, uint8NDArray); \
6515 TABLE_ELT (T, dt_int16, V, int16NDArray); \
6516 TABLE_ELT (T, dt_uint16, V, uint16NDArray); \
6517 TABLE_ELT (T, dt_int32, V, int32NDArray); \
6518 TABLE_ELT (T, dt_uint32, V, uint32NDArray); \
6519 TABLE_ELT (T, dt_int64, V, int64NDArray); \
6520 TABLE_ELT (T, dt_uint64, V, uint64NDArray); \
6521 TABLE_ELT (T, dt_single, V, FloatNDArray); \
6522 TABLE_ELT (T, dt_double, V, NDArray); \
6523 TABLE_ELT (T, dt_char, V, charNDArray); \
6524 TABLE_ELT (T, dt_schar, V, charNDArray); \
6525 TABLE_ELT (T, dt_uchar, V, charNDArray); \
6526 TABLE_ELT (T, dt_logical, V, boolNDArray);
6539 static bool initialized =
false;
6548 for (
int j = 0; j < 14; j++)
6549 conv_fptr_table[i][j] =
nullptr;
6585 switch (output_type)
6604 retval =
fptr (input_buf_list, input_buf_elts, elts_read,
6605 nr, nc, swap, do_float_fmt_conv, do_NA_conv, ffmt);
6610 ::error (
"read: invalid type specification");
6631 bool one_elt_size_spec =
false;
6639 std::ptrdiff_t tmp_count = 0;
6643 get_size (size, nr, nc, one_elt_size_spec,
"fread");
6652 if (one_elt_size_spec)
6675 if (nr == 0 || nc == 0)
6681 bool read_to_eof = elts_to_read < 0;
6688 input_buf_elts = 1024 * 1024;
6690 input_buf_elts = elts_to_read;
6693 input_buf_elts = block_size;
6698 std::ptrdiff_t input_buf_size
6699 =
static_cast<std::ptrdiff_t
> (input_buf_elts) * input_elt_size;
6707 error (
"fread: invalid input stream");
6710 std::istream& is = *isp;
6715 if (skip != 0 && is && ! is.eof ())
6717 cur_pos = is.tellg ();
6718 is.seekg (0, is.end);
6719 eof_pos = is.tellg ();
6720 is.seekg (cur_pos, is.beg);
6723 std::list<void *> input_buf_list;
6725 while (is && ! is.eof ()
6726 && (read_to_eof || tmp_count < elts_to_read))
6732 if (remaining_elts < input_buf_elts)
6733 input_buf_size = remaining_elts * input_elt_size;
6736 char *input_buf =
new char [input_buf_size];
6738 is.read (input_buf, input_buf_size);
6740 std::size_t gcount = is.gcount ();
6748 input_buf_list.push_back (input_buf);
6750 if (skip != 0 && nel == block_size && is)
6754 off_t remaining = eof_pos - cur_pos;
6756 if (remaining < skip)
6758 is.seekg (0, is.end);
6763 is.seekg (skip, is.cur);
6773 nc = tmp_count / nr;
6775 if (tmp_count % nr != 0)
6781 else if (tmp_count == 0)
6786 else if (tmp_count != nr * nc)
6788 if (tmp_count % nr != 0)
6789 nc = tmp_count / nr + 1;
6791 nc = tmp_count / nr;
6798 error (
"fread: number of elements read exceeds max index size");
6802 retval =
finalize_read (input_buf_list, input_buf_elts, count,
6803 nr, nc, input_type, output_type, ffmt);
6827 error (
"fwrite: write error");
6835 template <
typename T,
typename V>
6839 const T *tt_data =
static_cast<const T *
> (data);
6841 V *vt_data =
static_cast<V *
> (conv_data);
6844 vt_data[i] = tt_data[i];
6847 template <
typename T,
typename V>
6852 typedef typename V::val_type val_type;
6854 val_type *vt_data =
static_cast<val_type *
> (conv_data);
6861 vt_data[i] = val.value ();
6864 swap_bytes<sizeof (val_type)> (&vt_data[i]);
6868 template <
typename T>
6875 template <
typename T>
6882 template <
typename T>
6901 switch (output_type)
6904 convert_chars<ult_elt_type, char> (data, conv_data, n_elts);
6908 convert_chars<ult_elt_type, signed char> (data, conv_data, n_elts);
6912 convert_chars<ult_elt_type, unsigned char> (data, conv_data, n_elts);
6916 convert_ints<T, octave_int8> (data, conv_data, n_elts, swap);
6920 convert_ints<T, octave_uint8> (data, conv_data, n_elts, swap);
6924 convert_ints<T, octave_int16> (data, conv_data, n_elts, swap);
6928 convert_ints<T, octave_uint16> (data, conv_data, n_elts, swap);
6932 convert_ints<T, octave_int32> (data, conv_data, n_elts, swap);
6936 convert_ints<T, octave_uint32> (data, conv_data, n_elts, swap);
6940 convert_ints<T, octave_int64> (data, conv_data, n_elts, swap);
6944 convert_ints<T, octave_uint64> (data, conv_data, n_elts, swap);
6949 float *vt_data =
static_cast<float *
> (conv_data);
6953 vt_data[i] = data[i];
6955 if (do_float_conversion)
6963 double *vt_data =
static_cast<double *
> (conv_data);
6967 vt_data[i] = data[i];
6969 if (do_float_conversion)
6976 ::error (
"write: invalid type specification");
6985 bool status =
false;
6991 std::ostream& os = *osp;
6995 os.write (
static_cast<const char *
> (data), nbytes);
7008 bool status =
false;
7015 std::ostream& os = *osp;
7019 off_t orig_pos =
tell ();
7023 off_t eof_pos =
tell ();
7028 std::size_t remaining = eof_pos - orig_pos;
7030 if (remaining < skip)
7035 unsigned char zero = 0;
7036 for (std::size_t j = 0; j < skip - remaining; j++)
7037 os.write (
reinterpret_cast<const char *
> (&zero), 1);
7048 template <
typename T>
7062 bool do_data_conversion = (swap || ! is_equivalent_type<T> (output_type)
7070 chunk_size = block_size;
7071 else if (do_data_conversion)
7072 chunk_size = 1024 * 1024;
7078 const T *pdata = data.
data ();
7090 if (chunk_size > remaining_nel)
7091 chunk_size = remaining_nel;
7093 bool status =
false;
7095 if (do_data_conversion)
7097 std::size_t output_size
7102 status =
convert_data (&pdata[i], conv_data, chunk_size,
7103 output_type, flt_fmt);
7109 status =
write_bytes (pdata,
sizeof (T) * chunk_size);
7120 #define INSTANTIATE_WRITE(T) \
7122 OCTINTERP_API octave_idx_type \
7123 stream::write (const Array<T>& data, octave_idx_type block_size, \
7124 oct_data_conv::data_type output_type, \
7125 octave_idx_type skip, \
7126 mach_info::float_format flt_fmt)
7145 #if defined (OCTAVE_HAVE_OVERLOAD_CHAR_INT8_TYPES)
7158 retval =
m_rep->scanf (fmt, size, count, who);
7176 retval =
scanf (sfmt, size, count, who);
7181 error (who +
": format must be a string");
7193 retval =
m_rep->oscanf (fmt, who);
7210 retval =
oscanf (sfmt, who);
7215 error (who +
": format must be a string");
7227 ?
m_rep->do_textscan (fmt, ntimes, options, who, count)
7233 const std::string& who)
7238 retval =
m_rep->printf (fmt, args, who);
7245 const std::string& who)
7256 retval =
printf (sfmt, args, who);
7261 error (who +
": format must be a string");
7273 retval =
m_rep->puts (s, who);
7288 retval =
puts (s, who);
7293 error (who +
": argument must be a string");
7305 retval =
m_rep->eof ();
7313 std::string retval =
"invalid stream object";
7316 retval =
m_rep->error (clear, err_num);
7327 retval =
m_rep->name ();
7338 retval =
m_rep->mode ();
7349 retval =
m_rep->float_format ();
7357 std::string retval =
"???";
7358 std::ios::openmode in_mode =
static_cast<std::ios::openmode
> (
mode);
7360 if (in_mode == std::ios::in)
7362 else if (in_mode == std::ios::out
7365 else if (in_mode == (std::ios::out | std::ios::app))
7367 else if (in_mode == (std::ios::in | std::ios::out))
7371 else if (in_mode == (std::ios::in | std::ios::out | std::ios::ate))
7373 else if (in_mode == (std::ios::in | std::ios::binary))
7375 else if (in_mode == (std::ios::out | std::ios::binary)
7378 else if (in_mode == (std::ios::out | std::ios::app | std::ios::binary))
7380 else if (in_mode == (std::ios::in | std::ios::out | std::ios::binary))
7383 | std::ios::binary))
7385 else if (in_mode == (std::ios::in | std::ios::out | std::ios::ate
7386 | std::ios::binary))
7393 : m_list (), m_lookup_cache (m_list.end ()), m_stdin_file (-1),
7394 m_stdout_file (-1), m_stderr_file (-1)
7426 if (stream_number == -1)
7427 return stream_number;
7443 ::error (
"could not create file id");
7445 m_list[stream_number] = os;
7447 return stream_number;
7450 OCTAVE_NORETURN
static
7455 ::error (
"invalid stream number = %d", fid);
7457 ::error (
"%s: invalid stream number = %d", who.c_str (), fid);
7471 ostrl_map::const_iterator iter =
m_list.find (fid);
7473 if (iter ==
m_list.end ())
7476 retval = iter->second;
7484 const std::string& who)
const
7497 auto iter =
m_list.find (fid);
7499 if (iter ==
m_list.end ())
7502 stream os = iter->second;
7529 retval =
remove (i, who);
7544 for (
auto iter =
m_list.begin (); iter !=
m_list.end (); )
7546 int fid = iter->first;
7553 stream os = iter->second;
7555 std::string name = os.
name ();
7556 std::transform (name.begin (), name.end (), name.begin (), tolower);
7559 if (name.find (
"gnuplot") != std::string::npos)
7588 ostrl_map::const_iterator iter =
m_list.find (fid);
7590 if (iter ==
m_list.end ())
7600 retval(0) = os.
name ();
7613 ::error (
"file id must be a file object or integer value");
7618 ::error (
"file id must be a file object or integer value");
7625 std::ostringstream buf;
7628 <<
" number mode arch name\n"
7629 <<
" ------ ---- ---- ----\n";
7631 for (
const auto& fid_strm :
m_list)
7633 stream os = fid_strm.second;
7636 << std::setiosflags (std::ios::right)
7637 << std::setw (4) << fid_strm.first <<
" "
7639 << std::resetiosflags (std::ios::adjustfield)
7647 << os.
name () <<
"\n";
7661 for (
const auto& fid_strm :
m_list)
7664 if (fid_strm.first > 2 && fid_strm.second)
7665 retval(0, num_open++) = fid_strm.first;
7668 retval.
resize ((num_open > 0), num_open);
7681 for (
const auto& fid_strm :
m_list)
7684 if (fid_strm.first > 2)
7686 stream os = fid_strm.second;
7688 if (os && os.
name () == nm)
7690 retval = fid_strm.first;
7697 ::error (
"file id must be a file object, std::string, or integer value");
7705 ::error (
"file id must be a file object, std::string, or integer value");
charNDArray max(char d, const charNDArray &m)
charNDArray min(char d, const charNDArray &m)
OCTARRAY_OVERRIDABLE_FUNC_API const T * data(void) const
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API bool isempty(void) const
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_API T * fortran_vec(void)
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API size_type size(const size_type d) const
Size of the specified dimension.
void resize(octave_idx_type nr, octave_idx_type nc, double rfv=0)
static bool forced_interactive(void)
OCTINTERP_API int flush(void)
OCTINTERP_API std::string getl(octave_idx_type max_len, bool &err, const std::string &who)
virtual int file_number(void) const
virtual std::string name(void) const =0
OCTINTERP_API int do_numeric_printf_conv(std::ostream &os, const printf_format_elt *elt, int nsa, int sa_1, int sa_2, const octave_value &val, const std::string &who)
OCTINTERP_API int do_printf(printf_format_list &fmt_list, const octave_value_list &args, const std::string &who)
OCTINTERP_API octave_value_list oscanf(const std::string &fmt, const std::string &who)
OCTINTERP_API std::string gets(octave_idx_type max_len, bool &err, const std::string &who)
OCTINTERP_API void clear(void)
OCTINTERP_API void invalid_operation(const std::string &who, const char *rw)
OCTINTERP_API void clearerr(void)
OCTINTERP_API std::string do_gets(octave_idx_type max_len, bool &err, bool strip_newline, const std::string &who)
OCTINTERP_API octave_value scanf(const std::string &fmt, const Array< double > &size, octave_idx_type &count, const std::string &who)
virtual std::istream * input_stream(void)
OCTINTERP_API bool do_oscanf(const scanf_format_elt *elt, octave_value &, const std::string &who)
OCTINTERP_API int puts(const std::string &s, const std::string &who)
std::string error(bool clear, int &err_num)
OCTINTERP_API octave_value do_scanf(scanf_format_list &fmt_list, octave_idx_type nr, octave_idx_type nc, bool one_elt_size_spec, octave_idx_type &count, const std::string &who)
OCTINTERP_API off_t skipl(off_t count, bool &err, const std::string &who)
std::ostream * preferred_output_stream(void)
OCTINTERP_API octave_value do_textscan(const std::string &fmt, octave_idx_type ntimes, const octave_value_list &options, const std::string &who, octave_idx_type &count)
OCTINTERP_API void field_width_error(const std::string &who) const
std::string encoding(void) const
OCTINTERP_API int printf(const std::string &fmt, const octave_value_list &args, const std::string &who)
void clear(std::ios_base::iostate m=(std::ios_base::eofbit &~std::ios_base::eofbit))
const std::string m_delims
int getline(std::string &dest, char delim)
delimited_stream(std::istream &is, const std::string &delimiters, int longest_lookahead, octave_idx_type bsize=4096)
std::streampos m_buf_in_file
void progress_benchmark(void)
void seekg(char *old_idx)
std::ios_base::iostate m_flags
std::istream & m_i_stream
std::ios_base::iostate rdstate(void)
void setstate(std::ios_base::iostate m)
int refresh_buf(bool initialize=false)
delimited_stream(const delimited_stream &)=delete
char * read(char *buffer, int size, char *&new_start)
std::ptrdiff_t remaining(void)
Vector representing the dimensions (size) of an Array.
output_system & get_output_system(void)
bool interactive(void) const
void recover_from_exception(void)
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)
Cell cell_value(void) const
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
octave_idx_type length(void) const
octave_value isnan(void) const
octave_int64 int64_scalar_value(void) const
OCTINTERP_API std::string xstring_value(const char *fmt,...) const
OCTINTERP_API 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_idx_type numel(void) const
bool is_scalar_type(void) const
octave_base_value * internal_rep(void) const
bool is_string(void) const
bool is_defined(void) const
bool isinteger(void) const
bool isstruct(void) const
octave_value reshape(const dim_vector &dv) 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
bool is_uint64_type(void) const
octave_value isinf(void) const
octave_uint64 uint64_scalar_value(void) const
NDArray array_value(bool frc_str_conv=false) const
OCTINTERP_API octave_int64 xint64_scalar_value(const char *fmt,...) const
bool is_single_type(void) const
octave_value convert_to_str(bool pad=false, bool force=false, char type='\'') const
bool isobject(void) const
bool is_sq_string(void) const
double double_value(bool frc_str_conv=false) const
static stream create(std::ostream *arg, const std::string &n="")
std::ostream & __stdout__(void)
printf_value_cache(const octave_value_list &args, const std::string &who)
~printf_value_cache(void)=default
printf_value_cache(const printf_value_cache &)=delete
const octave_value_list m_values
octave_value get_next_value(char type=0)
octave_idx_type m_elt_idx
octave_idx_type m_val_idx
OCTINTERP_API octave_value stdout_file(void) const
OCTINTERP_API int insert(stream &os)
OCTINTERP_API ~stream_list(void)
OCTINTERP_API octave_value open_file_numbers(void) const
OCTINTERP_API octave_value stderr_file(void) const
ostrl_map::const_iterator m_lookup_cache
OCTINTERP_API std::string list_open_files(void) const
OCTINTERP_API int get_file_number(const octave_value &fid) const
OCTINTERP_API stream_list(interpreter &interp)
OCTINTERP_API stream lookup(int fid, const std::string &who="") const
OCTINTERP_API string_vector get_info(int fid) const
OCTINTERP_API int remove(int fid, const std::string &who="")
OCTINTERP_API octave_value stdin_file(void) const
OCTINTERP_API void clear(bool flush=true)
OCTINTERP_API octave_value finalize_read(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, oct_data_conv::data_type input_type, oct_data_conv::data_type output_type, mach_info::float_format ffmt)
static OCTINTERP_API std::string mode_as_string(int mode)
OCTINTERP_API octave_value scanf(const std::string &fmt, const Array< double > &size, octave_idx_type &count, const std::string &who)
std::istream * input_stream(void)
OCTINTERP_API mach_info::float_format float_format(void) const
OCTINTERP_API std::string gets(octave_idx_type max_len, bool &err, const std::string &who)
std::ostream * output_stream(void)
bool is_valid(void) const
OCTINTERP_API bool skip_bytes(std::size_t n_elts)
OCTINTERP_API bool eof(void) const
OCTINTERP_API int rewind(void)
OCTINTERP_API std::string name(void) const
bool stream_ok(bool clear=true) const
std::shared_ptr< base_stream > m_rep
OCTINTERP_API off_t skipl(off_t count, bool &err, const std::string &who)
OCTINTERP_API octave_value textscan(const std::string &fmt, octave_idx_type ntimes, const octave_value_list &options, const std::string &who, octave_idx_type &count)
OCTINTERP_API int puts(const std::string &s, const std::string &who)
OCTINTERP_API int printf(const std::string &fmt, const octave_value_list &args, const std::string &who)
OCTINTERP_API int flush(void)
OCTINTERP_API bool write_bytes(const void *data, std::size_t n_elts)
OCTINTERP_API bool is_open(void) const
OCTINTERP_API int mode(void) const
OCTINTERP_API int seek(off_t offset, int origin)
void invalid_operation(const std::string &who, const char *rw)
OCTINTERP_API octave_value_list oscanf(const std::string &fmt, const std::string &who)
OCTINTERP_API off_t tell(void)
OCTINTERP_API std::string getl(octave_idx_type max_len, bool &err, const std::string &who)
std::string encoding(void)
OCTINTERP_API void close(void)
OCTINTERP_API std::string error(bool clear, int &err_num)
OCTINTERP_API 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)
OCTINTERP_API 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)
textscan_format_elt(const textscan_format_elt &e)
textscan_format_elt(const std::string &txt, int w=0, int p=-1, int bw=0, bool dis=false, char typ='\0', const std::string &ch_class=std::string())
std::string parse_char_class(const std::string &pattern) const
textscan_format_list(const std::string &fmt=std::string(), const std::string &who="textscan")
std::deque< textscan_format_elt * > m_fmt_elts
const textscan_format_elt * first(void)
textscan_format_list(const textscan_format_list &)=delete
const textscan_format_elt * current(void) const
int read_first_row(delimited_stream &is, textscan &ts)
octave_idx_type num_conversions(void) const
~textscan_format_list(void)
std::list< octave_value > m_output_container
void process_conversion(const std::string &s, std::size_t &i, std::size_t n)
int finish_conversion(const std::string &s, std::size_t &i, std::size_t n, unsigned int width, int prec, int bitwidth, octave_value &val_type, bool discard, char &type)
textscan_format_list & operator=(const textscan_format_list &)=delete
std::size_t numel(void) const
const textscan_format_elt * next(bool cycle=true)
void add_elt_to_list(unsigned int width, int prec, int bitwidth, octave_value val_type, bool discard, char type, const std::string &char_class=std::string())
std::list< octave_value > out_buf(void) const
int scan_bracket(delimited_stream &is, const std::string &pattern, std::string &val) const
std::string m_whitespace_table
int skip_delim(delimited_stream &is)
textscan & operator=(const textscan &)=delete
int lookahead(delimited_stream &is, const Cell &targets, int max_len, bool case_sensitive=true) const
int skip_whitespace(delimited_stream &is, bool EOLstop=true)
void scan_complex(delimited_stream &is, const textscan_format_elt &fmt, Complex &val) const
octave_idx_type m_buffer_size
std::string read_until(delimited_stream &is, const Cell &delimiters, const std::string &ends) const
std::string m_date_locale
int read_format_once(delimited_stream &isp, textscan_format_list &fmt_list, std::list< octave_value > &retval, Array< octave_idx_type > row, int &done_after)
void scan_string(delimited_stream &is, const textscan_format_elt &fmt, std::string &val) const
void scan_qstring(delimited_stream &is, const textscan_format_elt &fmt, std::string &val)
std::string m_delim_table
bool whitespace_delim(void) const
octave_value scan(std::istream &isp, const std::string &fmt, octave_idx_type ntimes, const octave_value_list &options, octave_idx_type &read_count)
textscan(const std::string &who_arg="textscan", const std::string &encoding="utf-8")
bool is_delim(unsigned char ch) const
bool isspace(unsigned int ch) const
octave_value do_scan(std::istream &isp, textscan_format_list &fmt_list, octave_idx_type ntimes)
void scan_one(delimited_stream &is, const textscan_format_elt &fmt, octave_value &ov, Array< octave_idx_type > row)
friend class textscan_format_list
void scan_cstring(delimited_stream &is, const textscan_format_elt &fmt, std::string &val) const
octave_value m_empty_value
int scan_caret(delimited_stream &is, const std::string &pattern, std::string &val) const
bool match_literal(delimited_stream &isp, const textscan_format_elt &elem)
double read_double(delimited_stream &is, const textscan_format_elt &fmt) const
void parse_options(const octave_value_list &args, textscan_format_list &fmt_list)
textscan(const textscan &)=delete
bool multiple_delims_as_one
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,...)
void error(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__(void)
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 &)
bool words_big_endian(void)
std::string float_format_as_string(float_format flt_fmt)
float_format native_float_format(void)
@ 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)
#define BEGIN_S_CONVERSION()
static bool ok_for_unsigned_int_conv(const octave_value &val)
static bool convert_data(const T *data, void *conv_data, octave_idx_type n_elts, oct_data_conv::data_type output_type, mach_info::float_format flt_fmt)
static void convert_chars(const void *data, void *conv_data, octave_idx_type n_elts)
#define BEGIN_CHAR_CLASS_CONVERSION()
#define BEGIN_C_CONVERSION()
static Cell init_inf_nan(void)
static octave_value convert_and_copy(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 DO_WHITESPACE_CONVERSION()
static void do_scanf_conv(std::istream &is, const scanf_format_elt &fmt, T valptr, Matrix &mval, double *data, octave_idx_type &idx, octave_idx_type &conversion_count, octave_idx_type nr, octave_idx_type max_size, bool discard)
static octave_idx_type get_size(double d, const std::string &who)
static std::string switch_to_g_format(const printf_format_elt *elt)
static bool is_nan_or_inf(const octave_value &val)
static bool ok_for_signed_int_conv(const octave_value &val)
static std::istream & octave_scan(std::istream &is, const scanf_format_elt &fmt, T *valptr)
static int convert_to_valid_int(const octave_value &tc, int &conv_err)
#define DO_LITERAL_CONVERSION()
static OCTAVE_NORETURN void err_invalid_file_id(int fid, const std::string &who)
static std::istream & octave_scan_1(std::istream &is, const scanf_format_elt &fmt, T *valptr)
static std::size_t do_printf_string(std::ostream &os, const printf_format_elt *elt, int nsa, int sa_1, int sa_2, const std::string &arg, const std::string &who)
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)
static std::string expand_char_class(const std::string &s)
static int do_printf_conv(std::ostream &os, const char *fmt, int nsa, int sa_1, int sa_2, T arg, const std::string &who)
static void convert_ints(const T *data, void *conv_data, octave_idx_type n_elts, bool swap)
#define DO_PCT_CONVERSION()
#define FINISH_CHARACTER_CONVERSION()
static double pown(double x, unsigned int n)
T::size_type numel(const T &str)
OCTAVE_API std::string u8_from_encoding(const std::string &who, const std::string &native_string, const std::string &encoding)
OCTAVE_API 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.
static void initialize(void)
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()) ? '\'' :'"'))
OCTINTERP_API octave_value cat_op(type_info &ti, const octave_value &a, const octave_value &b, const Array< octave_idx_type > &ra_idx)
OCTINTERP_API octave_value binary_op(type_info &ti, octave_value::binary_op op, const octave_value &a, const octave_value &b)
static uint32_t state[624]
static void parse_options(regexp::opts &options, const octave_value_list &args, const std::string &who, int skip, bool &extra_args)
OCTAVE_API 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,...)