26#if defined (HAVE_CONFIG_H)
133 ::error (
"%s: NaN invalid as size specification", who.c_str ());
140 ::error (
"%s: negative value invalid as size specification",
143 static const double out_of_range_top
146 if (
d >= out_of_range_top)
147 ::error (
"%s: dimension too large for Octave's index type",
159 bool& one_elt_size_spec,
const std::string& who)
164 one_elt_size_spec =
false;
173 one_elt_size_spec =
true;
177 dnc = (dnr == 0.0) ? 0.0 : 1.0;
179 else if (sz_len == 2)
184 ::error (
"%s: infinite value invalid as size specification",
190 ::error (
"%s: invalid size specification (must be 2-D)", who.c_str ());
201 ::error (
"%s: size too large for Octave's index type", who.c_str ());
210 std::size_t
len = s.length ();
216 unsigned char c = s[i++];
218 if (c ==
'-' && i > 1 && i <
len
219 && (
static_cast<unsigned char> (s[i-2])
220 <=
static_cast<unsigned char> (s[i])))
225 for (c = s[i-2]+1; c < s[i]; c++)
233 if (c !=
'-' || i ==
len)
248 whitespace_conversion = 1,
249 literal_conversion = 2,
254 char typ =
'\0',
char mod =
'\0',
255 const std::string& ch_class =
"")
256 : text (txt), width (
w), discard (
d), type (typ),
257 modifier (
mod), char_class (ch_class)
308 std::size_t
length (
void)
const {
return m_fmt_elts.size (); }
318 return length () > 0 ? m_fmt_elts[m_curr_idx] :
nullptr;
328 if (m_curr_idx >= length ())
339 void printme (
void)
const;
341 bool ok (
void)
const {
return (m_nconv >= 0); }
343 operator bool ()
const {
return ok (); }
345 bool all_character_conversions (
void);
347 bool all_numeric_conversions (
void);
351 void add_elt_to_list (
int width,
bool discard,
char type,
char modifier,
352 const std::string& char_class =
"");
354 void process_conversion (
const std::string& s, std::size_t& i, std::size_t n,
355 int& width,
bool& discard,
char& type,
358 int finish_conversion (
const std::string& s, std::size_t& i, std::size_t n,
359 int width,
bool discard,
char& type,
380 : m_nconv (0), m_curr_idx (0), m_fmt_elts (), m_buf ()
382 std::size_t n = s.length ();
387 bool discard =
false;
388 char modifier =
'\0';
391 bool have_more =
true;
403 have_more = (
m_buf.tellp () != 0);
405 else if (isspace (s[i]))
414 while (++i < n && isspace (s[i]))
429 while (i < n && ! isspace (s[i]) && s[i] !=
'%')
455 for (std::size_t i = 0; i < n; i++)
465 const std::string& char_class)
467 std::string text =
m_buf.str ();
473 modifier, char_class);
484 std::size_t n,
int& width,
485 bool& discard,
char& type,
495 bool have_width =
false;
511 case '0':
case '1':
case '2':
case '3':
case '4':
512 case '5':
case '6':
case '7':
case '8':
case '9':
518 width = 10 * width + c -
'0';
521 while (i < n && isdigit (s[i]))
524 width = 10 * width + c -
'0';
530 case 'h':
case 'l':
case 'L':
531 if (modifier !=
'\0')
538 case 'd':
case 'i':
case 'o':
case 'u':
case 'x':
549 case 'e':
case 'f':
case 'g':
562 case 'c':
case 's':
case 'p':
case '%':
case '[':
563 if (modifier !=
'\0')
573 type, modifier) == 0)
592 std::size_t n,
int width,
bool discard,
593 char& type,
char modifier)
597 std::string char_class;
599 std::size_t beg_idx = std::string::npos;
600 std::size_t end_idx = std::string::npos;
632 else if (s[i] ==
']')
636 while (i < n && s[i] !=
']')
639 if (i < n && s[i] ==
']')
656 if (beg_idx != std::string::npos && end_idx != std::string::npos)
658 end_idx - beg_idx + 1));
671 for (std::size_t i = 0; i < n; i++)
676 <<
"width: " << elt->
width <<
"\n"
677 <<
"discard: " << elt->
discard <<
"\n"
681 std::cerr <<
"literal text\n";
683 std::cerr <<
"whitespace\n";
685 std::cerr << elt->
type <<
"\n";
688 <<
"modifier: " << elt->
modifier <<
"\n"
701 for (std::size_t i = 0; i < n; i++)
707 case 'c':
case 's':
case '%':
case '[':
case '^':
731 for (std::size_t i = 0; i < n; i++)
737 case 'd':
case 'i':
case 'o':
case 'u':
case 'x':
case 'X':
738 case 'e':
case 'f':
case 'g':
case 'E':
case 'G':
759 int p = -1,
const std::string&
f =
"",
760 char typ =
'\0',
char mod =
'\0')
761 : text (txt), args (n), fw (
w), prec (p), flags (
f),
762 type (typ), modifier (
mod)
819 return length () > 0 ? m_fmt_elts[m_curr_idx] :
nullptr;
822 std::size_t
length (
void)
const {
return m_fmt_elts.size (); }
828 if (m_curr_idx >= length ())
839 bool last_elt_p (
void) {
return (m_curr_idx + 1 == length ()); }
841 void printme (
void)
const;
843 bool ok (
void)
const {
return (m_nconv >= 0); }
845 operator bool ()
const {
return ok (); }
849 void add_elt_to_list (
int args,
const std::string& flags,
int fw,
850 int prec,
char type,
char modifier);
852 void process_conversion (
const std::string& s, std::size_t& i,
854 int& args, std::string& flags,
int& fw,
855 int& prec,
char& modifier,
char& type);
857 void finish_conversion (
const std::string& s, std::size_t& i,
int args,
858 const std::string& flags,
int fw,
int prec,
859 char modifier,
char& type);
879 : m_nconv (0), m_curr_idx (0), m_fmt_elts (), m_buf ()
881 std::size_t n = s.length ();
889 char modifier =
'\0';
892 bool have_more =
true;
893 bool empty_buf =
true;
908 empty_buf = (
m_buf.tellp () == 0);
925 have_more = (
m_buf.tellp () != 0);
964 for (std::size_t i = 0; i < n; i++)
973 int fw,
int prec,
char type,
976 std::string text =
m_buf.str ();
993 std::size_t n,
int& args,
994 std::string& flags,
int& fw,
995 int& prec,
char& modifier,
1013 case '-':
case '+':
case ' ':
case '0':
case '#':
1040 std::string tmp = s.substr (i);
1041 sscanf (tmp.c_str (),
"%d%n", &fw, &
nn);
1044 while (i < n && isdigit (s[i]))
1049 if (i < n && s[i] ==
'.')
1073 std::string tmp = s.substr (i);
1074 sscanf (tmp.c_str (),
"%d%n", &prec, &
nn);
1077 while (i < n && isdigit (s[i]))
1091 case 'h':
case 'l':
case 'L':
1108 int args,
const std::string& flags,
1109 int fw,
int prec,
char modifier,
1114 case 'd':
case 'i':
case 'o':
case 'x':
case 'X':
1116 if (modifier ==
'L')
1123 case 'f':
case 'e':
case 'E':
case 'g':
case 'G':
1124 if (modifier ==
'h' || modifier ==
'l')
1131 case 's':
case 'p':
case '%':
1132 if (modifier !=
'\0')
1145 if (type !=
'%' || args != 0)
1166 for (std::size_t i = 0; i < n; i++)
1171 <<
"args: " << elt->
args <<
"\n"
1172 <<
"flags: '" << elt->
flags <<
"'\n"
1173 <<
"width: " << elt->
fw <<
"\n"
1174 <<
"prec: " << elt->
prec <<
"\n"
1175 <<
"type: '" << elt->
type <<
"'\n"
1176 <<
"modifier: '" << elt->
modifier <<
"'\n"
1189 for (
unsigned int d = n;
d;
d >>= 1)
1245 if (m_idx >= m_last)
1251 int refresh_buf (
void);
1258 return eof () ? std::istream::traits_type::eof () : *m_idx++;
1260 return get_undelim ();
1264 int get_undelim (
void);
1271 {
return eof () ? std::istream::traits_type::eof () : *m_idx; }
1274 int peek_undelim (
void);
1280 void putback (
char = 0) {
if (! eof ()) --m_idx; }
1282 int getline (std::string& dest,
char delim);
1286 char * read (
char *buffer,
int size,
char* &new_start);
1292 void seekg (
char *old_idx) { m_idx = old_idx; }
1296 return (m_eob == m_buf && m_i_stream.eof ())
1297 || (m_flags & std::ios_base::eofbit);
1300 operator const void* (void)
1301 {
return (! eof () && ! m_flags) ?
this :
nullptr; }
1303 bool fail (
void) {
return m_flags & std::ios_base::failbit; }
1305 std::ios_base::iostate
rdstate (
void) {
return m_flags; }
1307 void setstate (std::ios_base::iostate m) { m_flags = m_flags | m; }
1310 = (std::ios_base::eofbit & ~std::ios_base::eofbit))
1312 m_flags = m_flags & m;
1366 const std::string& delimiters,
1367 int longest_lookahead,
1369 : m_bufsize (bsize), m_i_stream (is), m_longest (longest_lookahead),
1370 m_delims (delimiters),
1371 m_flags (
std::ios::failbit & ~
std::ios::failbit)
1409 return std::istream::traits_type::eof ();
1421 retval = std::istream::traits_type::eof ();
1454 return std::istream::traits_type::eof ();
1465 if (old_remaining > 0)
1495 retval = std::istream::traits_type::eof ();
1514 if (retval == std::istream::traits_type::eof ())
1579 for (i = 0; i < size && !
eof (); i++)
1582 memset (buffer, 0, size - i);
1596 int len = out.length ();
1600 && ch != std::istream::traits_type::eof ())
1624 whitespace_conversion = 1,
1625 literal_conversion = 2
1629 int bw = 0,
bool dis =
false,
char typ =
'\0',
1630 const std::string& ch_class = std::string ())
1631 : text (txt), width (
w), prec (p), bitwidth (bw),
1632 char_class (ch_class), type (typ), discard (dis),
1633 numeric (typ ==
'd' || typ ==
'u' || type ==
'f' || type ==
'n')
1637 : text (e.text), width (e.width), prec (e.prec),
1638 bitwidth (e.bitwidth), char_class (e.char_class), type (e.type),
1639 discard (e.discard), numeric (e.numeric)
1697 const std::string& who =
"textscan");
1713 std::size_t
numel (
void)
const {
return m_fmt_elts.size (); }
1723 return numel () > 0 ? m_fmt_elts[m_curr_idx] :
nullptr;
1730 if (m_curr_idx >=
numel ())
1741 void printme (
void)
const;
1743 bool ok (
void)
const {
return (m_nconv >= 0); }
1745 operator const void* (void)
const {
return ok () ? this :
nullptr; }
1758 std::list<octave_value>
out_buf (
void)
const {
return (m_output_container); }
1762 void add_elt_to_list (
unsigned int width,
int prec,
int bitwidth,
1765 const std::string& char_class = std::string ());
1767 void process_conversion (
const std::string& s, std::size_t& i,
1770 std::string parse_char_class (
const std::string& pattern)
const;
1772 int finish_conversion (
const std::string& s, std::size_t& i, std::size_t n,
1773 unsigned int width,
int prec,
int bitwidth,
1775 bool discard,
char& type);
1811 textscan (
const std::string& who_arg =
"textscan",
1812 const std::string& encoding =
"utf-8");
1822 octave_value scan (std::istream& isp,
const std::string& fmt,
1838 std::list<octave_value>& retval,
1852 std::string& val)
const;
1855 std::string& val)
const;
1858 std::string& val)
const;
1861 std::string& val)
const;
1868 const std::string& ends)
const;
1871 bool case_sensitive =
true)
const;
1881 return ((m_delim_table.empty ()
1882 && (isspace (ch) || ch == m_eol1 || ch == m_eol2))
1883 || m_delim_table[ch] !=
'\0');
1887 {
return m_whitespace_table[ch & 0xff]; }
1957 const std::string& who_arg)
1958 : who (who_arg), set_from_first (false), has_string (false),
1959 m_nconv (0), m_curr_idx (0), m_fmt_elts (), m_buf ()
1961 std::size_t n = s.length ();
1965 unsigned int width = -1;
1968 bool discard =
false;
1971 bool have_more =
true;
1996 if (s[i] ==
'%' && (i+1 == n || s[i+1] !=
'%'))
2008 have_more = (
m_buf.tellp () != 0);
2010 else if (isspace (s[i]))
2012 while (++i < n && isspace (s[i]))
2026 while (i < n && ! isspace (s[i])
2027 && (s[i] !=
'%' || (i+1 < n && s[i+1] ==
'%')))
2058 std::size_t n =
numel ();
2060 for (std::size_t i = 0; i < n; i++)
2070 bool discard,
char type,
2071 const std::string& char_class)
2073 std::string text =
m_buf.str ();
2075 if (! text.empty ())
2093 std::size_t& i, std::size_t n)
2098 bool discard =
false;
2104 bool have_width =
false;
2120 case '0':
case '1':
case '2':
case '3':
case '4':
2121 case '5':
case '6':
case '7':
case '8':
case '9':
2127 width = width * 10 + c -
'0';
2130 while (i < n && isdigit (s[i]))
2133 width = width * 10 + c -
'0';
2137 if (i < n && s[i] ==
'.')
2141 while (i < n && isdigit (s[i]))
2144 prec = prec * 10 + c -
'0';
2154 m_buf << (type = s[i++]);
2166 else if (s[i] ==
'1' && i+1 < n && s[i+1] ==
'6')
2176 else if (s[i] ==
'3' && i+1 < n && s[i+1] ==
'2')
2182 else if (s[i] ==
'6' && i+1 < n && s[i+1] ==
'4')
2210 m_buf << (type = s[i++]);
2214 if (s[i] ==
'3' && i+1 < n && s[i+1] ==
'2')
2221 else if (s[i] ==
'6' && i+1 < n && s[i+1] ==
'4')
2235 m_buf << (type = s[i++]);
2240 case 's':
case 'q':
case '[':
case 'c':
2243 m_buf << (type = s[i++]);
2254 width =
static_cast<unsigned int> (-1);
2258 discard, type) == 0)
2264 error (
"%s: '%%%c' is not a valid format specifier",
2265 who.c_str (), s[i]);
2290 int len = pattern.length ();
2294 std::string retval (256,
'\0');
2295 std::string mask (256,
'\0');
2297 int in = 0, out = 0;
2298 unsigned char ch, prev = 0;
2307 mask[pattern[in]] =
'\1';
2308 retval[out++] = pattern[in++];
2310 bool prev_was_range =
false;
2311 bool prev_prev_was_range =
false;
2312 for (; in <
len; in++)
2314 bool was_range =
false;
2319 if (prev ==
'-' && in > 1 && isalnum (ch) && ! prev_prev_was_range)
2321 unsigned char start_of_range = pattern[in-2];
2322 if (start_of_range < ch
2323 && ((isupper (ch) && isupper (start_of_range))
2324 || (islower (ch) && islower (start_of_range))
2325 || (isdigit (ch) && isdigit (start_of_range))
2331 for (
int i = start_of_range; i <= ch; i++)
2333 if (mask[i] ==
'\0')
2343 if (mask[ch]++ == 0)
2347 "%s: [...] contains two '%c's",
2350 if (prev ==
'-' && mask[
'-'] >= 2)
2352 (
"Octave:textscan-pattern",
2353 "%s: [...] contains two '-'s outside range expressions",
2357 prev_prev_was_range = prev_was_range;
2358 prev_was_range = was_range;
2364 for (
int i = 0; i < 256; i++)
2369 retval.resize (out);
2376 std::size_t n,
unsigned int width,
2377 int prec,
int bitwidth,
2383 std::string char_class;
2385 std::size_t beg_idx = std::string::npos;
2386 std::size_t end_idx = std::string::npos;
2410 else if (s[i] ==
']')
2414 while (i < n && s[i] !=
']')
2417 if (i < n && s[i] ==
']')
2430 if (beg_idx != std::string::npos && end_idx != std::string::npos)
2432 end_idx - beg_idx + 1));
2444 std::size_t n =
numel ();
2446 for (std::size_t i = 0; i < n; i++)
2451 <<
"width: " << elt->
width <<
"\n"
2452 <<
"digits " << elt->
prec <<
"\n"
2453 <<
"bitwidth: " << elt->
bitwidth <<
"\n"
2454 <<
"discard: " << elt->
discard <<
"\n"
2458 std::cerr <<
"literal text\n";
2460 std::cerr <<
"whitespace\n";
2462 std::cerr << elt->
type <<
"\n";
2477 std::string first_line (20,
' ');
2481 if (! first_line.empty () && first_line.back () == ts.
m_eol1)
2482 first_line.pop_back ();
2484 std::istringstream strstr (first_line);
2491 int max_empty = 1000;
2497 bool already_skipped_delim =
false;
2516 already_skipped_delim =
true;
2524 if (val.imag () == 0)
2531 if (! already_skipped_delim)
2550 : m_who (who_arg), m_encoding (encoding), m_buf (), m_whitespace_table (),
2551 m_delim_table (), m_delims (), m_comment_style (), m_comment_len (0),
2552 m_comment_char (-2), m_buffer_size (0), m_date_locale (),
2554 m_empty_value (numeric_limits<
double>::
NaN ()),
2555 m_exp_chars (
"edED"), m_header_lines (0), m_treat_as_empty (),
2556 m_treat_as_empty_len (0), m_whitespace (
" \b\t"), m_eol1 (
'\r'),
2557 m_eol2 (
'\n'), m_return_on_error (1), m_collect_output (false),
2558 multiple_delims_as_one (false), m_default_exp (true), m_lines (0)
2576 std::ios::iostate
state = isp.rdstate ();
2579 isp.setstate (
state);
2591 error (
"%s: invalid format specified",
m_who.c_str ());
2594 error (
"%s: no valid format conversion specifiers",
m_who.c_str ());
2599 getline (isp, dummy,
static_cast<char> (
m_eol2));
2611 else if (ntimes > 0)
2615 buf_size =
std::max (buf_size, ntimes);
2621 max_lookahead, buf_size);
2643 done_after = fmt_list.
numel () + 1;
2648 done_after = fmt_list.
out_buf ().size () + 1;
2650 std::list<octave_value> out = fmt_list.
out_buf ();
2658 bool merge_with_prev[fmt_list.
numel ()];
2663 for (
const auto& col : out)
2665 if (col.type_id () == prev_type
2667 merge_with_prev[conv++] =
true;
2669 merge_with_prev[conv++] =
false;
2671 prev_type = col.type_id ();
2678 error (
"%s: No conversions specified",
m_who.c_str ());
2684 row < ntimes || ntimes == -1;
2687 if (row == 0 || row >= size)
2690 for (
auto& col : out)
2697 if ((err & ~1) > 0 || ! is || (
m_lines >= ntimes && ntimes > -1))
2703 error (
"%s: Read error in field %d of row %" OCTAVE_IDX_TYPE_FORMAT,
2704 m_who.c_str (), done_after + 1, row + 1);
2707 bool uneven_columns =
false;
2709 uneven_columns =
true;
2710 else if (isp.eof ())
2713 isp.seekg (-1, std::ios_base::end);
2714 int last_char = isp.get ();
2715 isp.setstate (isp.eofbit);
2716 uneven_columns = (last_char !=
m_eol1 && last_char !=
m_eol2);
2725 done_after = out.size () + 1;
2727 int valid_rows = (row == ntimes
2729 : ((err & 1) && (err & 8)) ? row : row+1);
2737 for (
auto& col : out)
2740 if (i == done_after && uneven_columns)
2757 for (
auto& col : out)
2759 if (! merge_with_prev[conv++])
2761 if (prev_type != -1)
2768 prev_type = col.type_id ();
2772 ra_idx(1) = group_size++;
2791 unsigned int width_left = fmt.
width;
2795 int ch = is.
peek ();
2816 if (ch >=
'0' && ch <=
'9')
2818 while (width_left-- && is && (ch = is.
get ()) >=
'0' && ch <=
'9')
2819 retval = retval * 10 + (ch -
'0');
2824 if (ch ==
'.' && width_left)
2826 double multiplier = 1;
2827 int precision = fmt.
prec;
2832 if (precision == -1)
2838 for (i = 0; i < precision; i++)
2840 if (width_left-- && is && (ch = is.
get ()) >=
'0' && ch <=
'9')
2841 retval += (ch -
'0') * (multiplier *= 0.1);
2850 if ((i == precision || ! width_left) && (ch = is.
get ()) >=
'5'
2852 retval += multiplier;
2859 while (width_left-- && is && (ch = is.
get ()) >=
'0' && ch <=
'9')
2866 bool used_exp =
false;
2867 if (valid && width_left > 1 &&
m_exp_chars.find (ch) != std::string::npos)
2869 int ch1 = is.
peek ();
2870 if (ch1 ==
'-' || ch1 ==
'+' || (ch1 >=
'0' && ch1 <=
'9'))
2881 else if (ch1 ==
'-')
2888 while (width_left-- && is && (ch = is.
get ()) >=
'0' && ch <=
'9')
2890 exp = exp*10 + ch -
'0';
2894 if (ch != std::istream::traits_type::eof () && width_left)
2897 double multiplier =
pown (10, exp);
2899 retval *= multiplier;
2901 retval /= multiplier;
2907 if (! used_exp && ch != std::istream::traits_type::eof () && width_left)
2911 if (! valid && width_left >= 3)
2931 return retval * sign;
2944 bool as_empty =
false;
2947 int ch = is.
peek ();
2948 if (ch ==
'+' || ch ==
'-')
2951 int ch2 = is.
peek ();
2952 if (ch2 ==
'i' || ch2 ==
'j')
2957 if (is.
peek () ==
'n')
2959 char *pos = is.
tellg ();
2978 im = (ch ==
'+') ? value : -value;
2986 char *pos = is.
tellg ();
3016 char *look = is.
read (&look_buf[0], look_buf.size (), pos);
3025 if (!
strncmp (s.c_str (), look, s.size ()))
3029 is.
read (&look_buf[0], s.size (), pos);
3036 if (! is.
eof () && ! as_empty)
3041 if (ch ==
'i' || ch ==
'j')
3047 else if (ch ==
'+' || ch ==
'-')
3058 if (is.
peek () ==
'i' || is.
peek () ==
'j')
3081 std::string& val)
const
3083 int c1 = std::istream::traits_type::eof ();
3084 std::ostringstream obuf;
3086 while (is && ((c1 = (is && ! is.
eof ())
3088 : std::istream::traits_type::eof ())
3089 != std::istream::traits_type::eof ())
3090 && pattern.find (c1) == std::string::npos)
3091 obuf << static_cast<char> (c1);
3095 if (c1 != std::istream::traits_type::eof ())
3106 const std::string& ends)
const
3108 std::string retval (
"");
3115 retval = retval +
next;
3117 int last = (! is.
eof ()
3118 ? is.
get_undelim () : std::istream::traits_type::eof ());
3120 if (last != std::istream::traits_type::eof ())
3125 retval = retval +
static_cast<char> (last);
3126 for (
int i = 0; i < delimiters.
numel (); i++)
3128 std::string delim = delimiters(i).string_value ();
3129 std::size_t start = (retval.length () > delim.length ()
3130 ? retval.length () - delim.length ()
3132 std::string may_match = retval.substr (start);
3133 if (may_match == delim)
3136 retval = retval.substr (0, start);
3144 while (! done && is && ! is.
eof ());
3155 std::string& val)
const
3160 unsigned int width = fmt.
width;
3162 for (i = 0; i < width; i++)
3165 if (i >= val.length ())
3166 val.append (
std::max (val.length (),
3167 static_cast<std::size_t
> (16)),
'\0');
3170 if (
is_delim (ch) || ch == std::istream::traits_type::eof ())
3178 val = val.substr (0, i);
3187 ends[i] = tmp.back ();
3203 std::string& val)
const
3205 int c1 = std::istream::traits_type::eof ();
3206 std::ostringstream obuf;
3208 while (is && pattern.find (c1 = is.
get_undelim ()) != std::string::npos)
3209 obuf << static_cast<char> (c1);
3212 if (c1 != std::istream::traits_type::eof ())
3227 if (is.
peek () !=
'"')
3240 val = val + '"' + val1;
3255 std::string& val)
const
3257 val.resize (fmt.
width);
3259 for (
unsigned int i = 0; is && i < fmt.
width; i++)
3262 if (ch != std::istream::traits_type::eof ())
3289 if (fmt.
type ==
'f' || fmt.
type ==
'n')
3299 if (ov.
isreal () && v.imag () == 0)
3311 if (ov.
isreal () && v.imag () == 0)
3374 if (fmt.
type ==
'd')
3387 if (fmt.
type ==
'd')
3406 std::string vv (
" ");
3448 std::list<octave_value>& retval,
3452 auto out = retval.begin ();
3453 bool no_conversions =
true;
3455 bool conversion_failed =
false;
3456 bool nothing_worked =
true;
3460 for (std::size_t i = 0; i < fmt_list.
numel (); i++)
3462 bool this_conversion_failed =
false;
3471 warning (
"%s: conversion %c not yet implemented",
3492 error (
"Unknown format element '%c'",
elem->type);
3497 if (!
elem->discard)
3498 no_conversions =
false;
3509 this_conversion_failed =
true;
3513 char *pos = is.
tellg ();
3515 this_conversion_failed =
true;
3522 if (!
elem->discard)
3526 char *pos = is.
tellg ();
3545 if (this_conversion_failed)
3547 if (is.
tellg () == pos && ! conversion_failed)
3551 conversion_failed =
true;
3554 this_conversion_failed =
false;
3556 else if (! done && ! conversion_failed)
3557 nothing_worked =
false;
3563 return no_conversions
3564 + (is.
eof () ? 2 : 0)
3565 + (conversion_failed ? 4 : 0)
3566 + (nothing_worked ? 8 : 0);
3574 int last = args.
length ();
3578 error (
"%s: %d parameters given, but only %d values",
3579 m_who.c_str (), n-n/2, n/2);
3582 bool have_delims =
false;
3583 for (
int i = 0; i < last; i += 2)
3585 std::string param = args(i).xstring_value (
"%s: Invalid parameter type <%s> for parameter %d",
3587 args(i).type_name ().c_str (),
3589 std::transform (param.begin (), param.end (), param.begin (), ::tolower);
3591 if (param ==
"delimiter")
3593 bool invalid =
true;
3594 if (args(i+1).is_string ())
3598 m_delims = args(i+1).string_value ();
3599 if (args(i+1).is_sq_string ())
3602 else if (args(i+1).iscell ())
3626 error (
"%s: Delimiters must be either a string or cell array of strings",
3629 else if (param ==
"commentstyle")
3631 if (args(i+1).is_string ())
3636 else if (args(i+1).iscell ())
3643 error (
"%s: CommentStyle must be either a string or cell array of one or two strings",
3647 error (
"%s: CommentStyle must be either a string or cell array of one or two strings",
3658 else if (param ==
"treatasempty")
3660 bool invalid =
false;
3661 if (args(i+1).is_string ())
3666 else if (args(i+1).iscell ())
3680 error (
"%s: TreatAsEmpty must be either a string or cell array of one or two strings",
3685 else if (param ==
"collectoutput")
3687 m_collect_output = args(i+1).xbool_value (
"%s: CollectOutput must be logical or numeric",
m_who.c_str ());
3689 else if (param ==
"emptyvalue")
3691 m_empty_value = args(i+1).xscalar_value (
"%s: EmptyValue must be numeric",
m_who.c_str ());
3693 else if (param ==
"headerlines")
3695 m_header_lines = args(i+1).xscalar_value (
"%s: HeaderLines must be numeric",
m_who.c_str ());
3697 else if (param ==
"bufsize")
3699 m_buffer_size = args(i+1).xscalar_value (
"%s: BufSize must be numeric",
m_who.c_str ());
3701 else if (param ==
"multipledelimsasone")
3705 else if (param ==
"returnonerror")
3707 m_return_on_error = args(i+1).xbool_value (
"%s: ReturnOnError must be logical or numeric",
m_who.c_str ());
3709 else if (param ==
"whitespace")
3711 m_whitespace = args(i+1).xstring_value (
"%s: Whitespace must be a character string",
m_who.c_str ());
3713 else if (param ==
"expchars")
3715 m_exp_chars = args(i+1).xstring_value (
"%s: ExpChars must be a character string",
m_who.c_str ());
3718 else if (param ==
"endofline")
3721 std::string s = args(i+1).xstring_value (R
"(%s: EndOfLine must be at most one character or '\r\n')", m_who.c_str ());
3722 if (args(i+1).is_sq_string ())
3724 int l = s.length ();
3740 error (R
"(%s: EndOfLine must be at most one character or '\r\n')",
3744 error (
"%s: unrecognized option '%s'",
m_who.c_str (), param.c_str ());
3748 for (
unsigned int j = 0; j <
m_delims.length (); j++)
3758 if (delim.length () == 1)
3766 for (
unsigned int i = 0; i <
m_whitespace.length (); i++)
3781 for (
unsigned int i = 0; i < 256; i++)
3787 for (
unsigned int i = 0; i <
m_delims.length (); i++)
3797 int c1 = std::istream::traits_type::eof ();
3798 bool found_comment =
false;
3802 found_comment =
false;
3805 && (c1 = is.
get_undelim ()) != std::istream::traits_type::eof ()
3817 char *pos = is.
tellg ();
3826 found_comment =
true;
3831 std::string eol (3,
'\0');
3846 std::string last = end_c.substr (end_c.size () - 1);
3847 std::string may_match (
"");
3854 may_match = may_match + dummy + last;
3855 if (may_match.length () > end_c.length ())
3857 std::size_t start = may_match.length ()
3859 may_match = may_match.substr (start);
3862 while (may_match != end_c && is && ! is.
eof ());
3872 while (found_comment);
3874 if (c1 != std::istream::traits_type::eof ())
3886 bool case_sensitive)
const
3892 char *pos = is.
tellg ();
3894 std::string tmp (max_len,
'\0');
3895 char *look = is.
read (&tmp[0], tmp.size (), pos);
3902 int (*compare)(
const char *,
const char *, std::size_t);
3905 for (i = 0; i < targets.
numel (); i++)
3907 std::string s = targets (i).string_value ();
3908 if (! (*compare) (s.c_str (), look, s.size ()))
3910 is.
read (&tmp[0], s.size (), pos);
3915 if (i == targets.
numel ())
3941 != std::istream::traits_type::eof ())
3949 if (c1 != std::istream::traits_type::eof ())
3979 != std::istream::traits_type::eof ())
4006 for (
unsigned int i = 0; i < fmt.
width; i++)
4009 if (ch != fmt.
text[i])
4011 if (ch != std::istream::traits_type::eof ())
4059 bool strip_newline,
const std::string& who)
4064 ::error (
"%s: unable to read from stdin while running interactively",
4080 std::istream& is = *isp;
4082 std::ostringstream buf;
4089 while (is && (c = is.get ()) != std::istream::traits_type::eof ())
4096 if (! strip_newline)
4097 buf << static_cast<char> (c);
4101 if (c != std::istream::traits_type::eof ())
4107 if (! strip_newline)
4108 buf << static_cast<char> (c);
4118 if (! strip_newline)
4119 buf << static_cast<char> (c);
4124 buf << static_cast<char> (c);
4126 if (max_len > 0 && char_count == max_len)
4131 if (! is.eof () && char_count > 0)
4136 int disgusting_compatibility_hack = is.get ();
4138 is.putback (disgusting_compatibility_hack);
4141 if (is.good () || (is.eof () && char_count > 0))
4143 retval = buf.str ();
4151 if (is.eof () && char_count == 0)
4152 error (who,
"at end of file");
4154 error (who,
"read error");
4163 const std::string& who)
4165 return do_gets (max_len, err,
true, who);
4170 const std::string& who)
4172 return do_gets (max_len, err,
false, who);
4181 ::error (
"%s: unable to read from stdin while running interactively",
4197 std::istream& is = *isp;
4203 while (is && (c = is.get ()) != std::istream::traits_type::eof ())
4206 if (c ==
'\r' || (c ==
'\n' && lastc !=
'\r'))
4216 if (c ==
'\r' && is.peek () ==
'\n')
4222 error (who,
"read error");
4232 template <
typename T>
4233 static std::istream&
4242 is >> std::oct >> value >> std::dec;
4247 is >> std::hex >> value >> std::dec;
4252 int c1 = std::istream::traits_type::eof ();
4254 while (is && (c1 = is.get ()) != std::istream::traits_type::eof ()
4258 if (c1 != std::istream::traits_type::eof ())
4262 int c2 = is.peek ();
4264 if (c2 ==
'x' || c2 ==
'X')
4267 if (std::isxdigit (is.peek ()))
4268 is >> std::hex >> value >> std::dec;
4274 if (c2 ==
'0' || c2 ==
'1' || c2 ==
'2'
4275 || c2 ==
'3' || c2 ==
'4' || c2 ==
'5'
4276 || c2 ==
'6' || c2 ==
'7')
4277 is >> std::oct >> value >> std::dec;
4278 else if (c2 ==
'8' || c2 ==
'9')
4310 if ((is.rdstate () & std::ios::failbit) && value != T ())
4311 is.clear (is.rdstate () & ~std::ios::failbit);
4315 if (! (is.rdstate () & std::ios::failbit))
4321 template <
typename T>
4322 static std::istream&
4331 auto orig_pos = is.tellg ();
4333 is.width (fmt.
width);
4336 std::istringstream ss (strbuf);
4349 is.seekg (orig_pos, is.beg);
4351 int chars_read = ss.tellg ();
4354 is.width (chars_read);
4361 is.setstate (std::ios::failbit);
4372 octave_scan<> (std::istream& is,
const scanf_format_elt& fmt,
double *valptr)
4374 double& ref = *valptr;
4384 int c1 = std::istream::traits_type::eof ();
4386 while (is && (c1 = is.get ()) != std::istream::traits_type::eof ()
4390 if (c1 != std::istream::traits_type::eof ())
4394 ref = read_value<double> (is);
4407 template <
typename T>
4419 if (idx == max_size && ! discard)
4424 mval.
resize (nr, max_size / nr, 0.0);
4426 mval.
resize (max_size, 1, 0.0);
4434 data[idx++] = *(valptr);
4443#define DO_WHITESPACE_CONVERSION() \
4446 int c = std::istream::traits_type::eof (); \
4448 while (is && (c = is.get ()) != std::istream::traits_type::eof () \
4452 if (c != std::istream::traits_type::eof ()) \
4457#define DO_LITERAL_CONVERSION() \
4460 int c = std::istream::traits_type::eof (); \
4462 int n = fmt.length (); \
4465 while (i < n && is \
4466 && (c = is.get ()) != std::istream::traits_type::eof ()) \
4468 if (c == static_cast<unsigned char> (fmt[i])) \
4481 is.setstate (std::ios::failbit); \
4485#define DO_PCT_CONVERSION() \
4488 int c = is.get (); \
4490 if (c != std::istream::traits_type::eof ()) \
4495 is.setstate (std::ios::failbit); \
4499 is.setstate (std::ios::failbit); \
4503#define BEGIN_C_CONVERSION() \
4504 is.unsetf (std::ios::skipws); \
4506 int width = (elt->width ? elt->width : 1); \
4508 std::string tmp (width, '\0'); \
4510 int c = std::istream::traits_type::eof (); \
4513 while (is && n < width \
4514 && (c = is.get ()) != std::istream::traits_type::eof ()) \
4515 tmp[n++] = static_cast<char> (c); \
4517 if (n > 0 && c == std::istream::traits_type::eof ()) \
4524#define BEGIN_S_CONVERSION() \
4525 int width = elt->width; \
4533 tmp = std::string (width, '\0'); \
4535 int c = std::istream::traits_type::eof (); \
4539 while (is && (c = is.get ()) != std::istream::traits_type::eof ()) \
4541 if (! isspace (c)) \
4543 tmp[n++] = static_cast<char> (c); \
4548 while (is && n < width \
4549 && (c = is.get ()) != std::istream::traits_type::eof ()) \
4557 tmp[n++] = static_cast<char> (c); \
4560 if (n > 0 && c == std::istream::traits_type::eof ()) \
4567 is >> std::ws >> tmp; \
4573#define BEGIN_CHAR_CLASS_CONVERSION() \
4574 int width = elt->width; \
4581 width = std::numeric_limits<int>::max (); \
4583 std::ostringstream buf; \
4585 std::string char_class = elt->char_class; \
4587 int c = std::istream::traits_type::eof (); \
4589 if (elt->type == '[') \
4591 int chars_read = 0; \
4592 while (is && chars_read++ < width \
4593 && (c = is.get ()) != std::istream::traits_type::eof () \
4594 && char_class.find (c) != std::string::npos) \
4595 buf << static_cast<char> (c); \
4599 int chars_read = 0; \
4600 while (is && chars_read++ < width \
4601 && (c = is.get ()) != std::istream::traits_type::eof () \
4602 && char_class.find (c) == std::string::npos) \
4603 buf << static_cast<char> (c); \
4606 if (width == std::numeric_limits<int>::max () \
4607 && c != std::istream::traits_type::eof ()) \
4613 is.setstate (std::ios::failbit); \
4614 else if (c == std::istream::traits_type::eof ()) \
4620#define FINISH_CHARACTER_CONVERSION() \
4623 if (encoding ().compare ("utf-8")) \
4624 tmp = string::u8_from_encoding (who, tmp, encoding ()); \
4625 width = tmp.length (); \
4633 conversion_count++; \
4637 if (data_index == max_size) \
4641 if (all_char_conv) \
4643 if (one_elt_size_spec) \
4644 mval.resize (1, max_size, 0.0); \
4646 mval.resize (nr, max_size / nr, 0.0); \
4648 panic_impossible (); \
4651 mval.resize (nr, max_size / nr, 0.0); \
4653 mval.resize (max_size, 1, 0.0); \
4655 data = mval.fortran_vec (); \
4658 data[data_index++] = static_cast<unsigned char> \
4669 bool one_elt_size_spec,
4671 const std::string& who)
4676 ::error (
"%s: unable to read from stdin while running interactively",
4681 conversion_count = 0;
4687 if (nr == 0 || nc == 0)
4689 if (one_elt_size_spec)
4692 return Matrix (nr, nc, 0.0);
4710 if (one_elt_size_spec)
4713 mval.
resize (1, max_size, 0.0);
4722 mval.
resize (nr, nc, 0.0);
4723 max_size = max_conv = nr * nc;
4727 mval.
resize (nr, 32, 0.0);
4739 mval.
resize (nr, nc, 0.0);
4741 max_conv = max_size;
4746 mval.
resize (nr, 32, 0.0);
4753 mval.
resize (32, 1, 0.0);
4761 std::istream& is = *isp;
4765 std::ios::fmtflags flags = is.flags ();
4780 || elt->
type ==
'%')
4781 && max_conv > 0 && conversion_count == max_conv))
4788 if (all_char_conv && one_elt_size_spec)
4791 final_nc = data_index;
4796 final_nc = (data_index - 1) / nr + 1;
4801 else if (data_index == max_size)
4807 if (one_elt_size_spec)
4808 mval.
resize (1, max_size, 0.0);
4810 mval.
resize (nr, max_size / nr, 0.0);
4815 mval.
resize (nr, max_size / nr, 0.0);
4817 mval.
resize (max_size, 1, 0.0);
4822 std::string fmt = elt->
text;
4848 data_index, conversion_count,
4849 nr, max_size, discard);
4857 data_index, conversion_count,
4858 nr, max_size, discard);
4866 data_index, conversion_count,
4867 nr, max_size, discard);
4874 case 'o':
case 'u':
case 'x':
case 'X':
4882 data_index, conversion_count,
4883 nr, max_size, discard);
4891 data_index, conversion_count,
4892 nr, max_size, discard);
4900 data_index, conversion_count,
4901 nr, max_size, discard);
4908 case 'e':
case 'f':
case 'g':
4914 data_index, conversion_count,
4915 nr, max_size, discard);
4946 error (who,
"unsupported format specifier");
4950 error (who,
"internal format error");
4958 else if (is.eof () || ! is)
4962 if (one_elt_size_spec)
4965 final_nc = data_index;
4967 else if (data_index > nr)
4970 final_nc = (data_index - 1) / nr + 1;
4974 final_nr = data_index;
4980 if (data_index > nr)
4983 final_nc = (data_index - 1) / nr + 1;
4987 final_nr = data_index;
4993 final_nr = data_index;
4999 if (is.rdstate () & std::ios::failbit)
5001 error (who,
"format failed to match");
5002 is.clear (is.rdstate () & (~std::ios::failbit));
5008 &&
name () ==
"stdin")
5014 do_gets (-1, err,
false, who);
5022 error (who,
"internal format error");
5026 if (m_nconv == 0 && ++trips == num_fmt_elts)
5028 if (all_char_conv && one_elt_size_spec)
5031 final_nc = data_index;
5036 final_nc = (data_index - 1) / nr + 1;
5047 elt = fmt_list.
next (m_nconv > 0
5049 || conversion_count < max_conv));
5054 mval.
resize (final_nr, final_nc, 0.0);
5067 const std::string& who)
5071 conversion_count = 0;
5082 ::error (
"%s: invalid format specified", who.c_str ());
5087 bool one_elt_size_spec;
5089 get_size (size, nr, nc, one_elt_size_spec, who);
5091 retval =
do_scanf (fmt_list, nr, nc, one_elt_size_spec,
5092 conversion_count, who);
5109 std::istream& is = *isp;
5111 std::ios::fmtflags flags = is.flags ();
5115 std::string fmt = elt->
text;
5184 case 'o':
case 'u':
case 'x':
case 'X':
5230 case 'e':
case 'f':
case 'g':
5285 error (who,
"unsupported format specifier");
5289 error (who,
"internal format error");
5294 if (
ok () && is.fail ())
5296 error (
"%s: read error", who.c_str ());
5303 &&
name () ==
"stdin")
5307 do_gets (-1, err,
false, who);
5325 std::istream& is = *isp;
5332 ::error (
"%s: invalid format specified", who.c_str ());
5357 retval(num_values++) = tmp;
5362 elt = fmt_list.
next (m_nconv > 0);
5366 retval(m_nconv) = num_values;
5369 retval(m_nconv+1) =
error (
false, err_num);
5374 if (
ok () &&
len > m_nconv)
5378 elt = fmt_list.
next ();
5392 const std::string& who,
5398 ::error (
"%s: unable to read from stdin while running interactively",
5411 retval =
scanner.scan (*isp, fmt, ntimes, options, read_count);
5448 : m_values (args), m_val_idx (0), m_elt_idx (0),
5449 m_n_vals (m_values.length ()), m_n_elts (0), m_have_data (false),
5476 int int_value (
void);
5478 operator bool ()
const {
return (m_curr_state == ok); }
5544 double dval = val(idx);
5547 || dval < 0 || dval > 255)
5555 std::string sval (n,
'\0');
5570 if (type ==
'c' && ! retval.
is_string ())
5574 if (
math::x_nint (dval) == dval && dval >= 0 && dval < 256)
5575 retval =
static_cast<char> (dval);
5597 if (type ==
's' || type ==
'c')
5633 template <
typename T>
5636 const char *fmt,
int nsa,
int sa_1,
int sa_2, T arg,
5637 const std::string& who)
5644 retval =
format (os, encoding, fmt, sa_1, sa_2, arg);
5648 retval =
format (os, encoding, fmt, sa_1, arg);
5652 retval =
format (os, encoding, fmt, arg);
5656 ::error (
"%s: internal error handling format", who.c_str ());
5665 int nsa,
int sa_1,
int sa_2,
const std::string& arg,
5666 const std::string& encoding,
const std::string& who)
5669 ::error (
"%s: internal error handling format", who.c_str ());
5671 std::string flags = elt->
flags;
5673 bool left = flags.find (
'-') != std::string::npos;
5675 std::size_t
len = arg.length ();
5677 std::size_t prec = (nsa > 1 ? sa_2 : (elt->
prec == -1 ?
len : elt->
prec));
5679 std::string print_str = prec < arg.length () ? arg.substr (0, prec) : arg;
5680 if (encoding.compare (
"utf-8"))
5682 std::size_t src_len = print_str.length ();
5684 len -= src_len - print_str.length ();
5687 std::size_t fw = (nsa > 0 ? sa_1 : (elt->
fw == -1 ?
len : elt->
fw));
5689 os << std::setw (fw) << (
left ?
std::left : std::right) << print_str;
5691 return len > fw ?
len : fw;
5716 if (ival.
value () <= limit)
5726 if (dval ==
math::fix (dval) && dval <= limit)
5745 return ov_is_ge_zero.
is_true ();
5753 if (dval ==
math::fix (dval) && dval >= 0 && dval <= limit)
5763 std::string tfmt = elt->
text;
5765 tfmt.replace (tfmt.rfind (elt->
type), 1,
"g");
5773 int nsa,
int sa_1,
int sa_2,
5775 const std::string& who)
5779 std::string tfmt = elt->
text;
5785 std::string::size_type i1, i2;
5787 tfmt.replace ((i1 = tfmt.rfind (elt->
type)), 1, 1,
's');
5789 if ((i2 = tfmt.rfind (
'.')) != std::string::npos && i2 < i1)
5791 tfmt.erase (i2, i1-i2);
5792 if (elt->
prec == -2)
5799 if (elt->
flags.find (
'+') != std::string::npos)
5800 tval = (dval < 0 ?
"-Inf" :
"+Inf");
5802 tval = (dval < 0 ?
"-Inf" :
"Inf");
5806 if (elt->
flags.find (
'+') != std::string::npos)
5817 static std::string llmod
5818 = (
sizeof (long) ==
sizeof (int64_t) ?
"l" :
"ll");
5820 char type = elt->
type;
5824 case 'd':
case 'i':
case 'c':
5830 tfmt.replace (tfmt.rfind (type), 1, llmod + type);
5833 sa_1, sa_2, tval.
value (), who);
5842 sa_1, sa_2, dval, who);
5846 case 'o':
case 'x':
case 'X':
case 'u':
5852 tfmt.replace (tfmt.rfind (type), 1, llmod + type);
5855 sa_1, sa_2, tval.
value (), who);
5864 sa_1, sa_2, dval, who);
5868 case 'f':
case 'e':
case 'E':
5874 sa_1, sa_2, dval, who);
5881 error (who,
"invalid format specifier");
5893 ::error (
"%s: invalid field width, must be integer >= 0 and <= INT_MAX",
5900 const std::string& who)
5912 std::ostream& os = *osp;
5925 ::error (
"%s: internal error handling format", who.c_str ());
5928 int nsa = (elt->
fw == -2) + (elt->
prec == -2);
5957 if (elt->
type ==
'%')
5965 else if (elt->
args == 0 && ! elt->
text.empty ())
5971 retval += (elt->
text.length ());
5973 else if (elt->
type ==
's' || elt->
type ==
'c')
6010 error (who,
"write error");
6014 elt = fmt_list.
next (m_nconv > 0 && ! val_cache.
exhausted ());
6027 const std::string& who)
6032 ::error (
"%s: invalid format specified", who.c_str ());
6048 std::ostream& os = *osp;
6053 error (who,
"write error");
6067 error (who,
"write error");
6079 err_num = (
m_fail ? -1 : 0);
6093 error (who, std::string (
"stream not open for ") + rw);
6102 retval =
m_rep->flush ();
6113 retval =
m_rep->getl (max_len, err, who);
6120 const std::string& who)
6132 if (conv_err || max_len < 0)
6135 ::error (
"%s: invalid maximum length specified", who.c_str ());
6139 return getl (max_len, err, who);
6148 retval =
m_rep->gets (max_len, err, who);
6155 const std::string& who)
6167 if (conv_err || max_len < 0)
6170 ::error (
"%s: invalid maximum length specified", who.c_str ());
6174 return gets (max_len, err, who);
6183 retval =
m_rep->skipl (count, err, who);
6190 const std::string& who)
6207 if (conv_err || count < 0)
6210 ::error (
"%s: invalid number of lines specified",
6216 return skipl (count, err, who);
6229 off_t orig_pos =
m_rep->tell ();
6236 off_t eof_pos =
m_rep->tell ();
6248 status =
m_rep->seek (offset, origin);
6253 off_t desired_pos =
m_rep->tell ();
6257 if (desired_pos > eof_pos || desired_pos < 0)
6288 off_t xoffset = val.
value ();
6296 std::string xorigin = tc_origin.
xstring_value (
"fseek: invalid value for origin");
6298 if (xorigin ==
"bof")
6300 else if (xorigin ==
"cof")
6302 else if (xorigin ==
"eof")
6315 else if (xorigin == 0)
6317 else if (xorigin == 1)
6325 ::error (
"fseek: invalid value for origin");
6327 retval =
seek (xoffset, origin);
6331 error (
"fseek: failed to seek to requested position");
6342 retval =
m_rep->tell ();
6356 bool retval =
false;
6359 retval =
m_rep->is_open ();
6371 template <
typename SRC_T,
typename DST_T>
6377 bool do_float_fmt_conv,
bool do_NA_conv,
6380 typedef typename DST_T::element_type dst_elt_type;
6384 dst_elt_type *conv_data = conv.fortran_vec ();
6388 for (
auto it = input_buf_list.cbegin (); it != input_buf_list.cend (); it++)
6390 SRC_T *data =
static_cast<SRC_T *
> (*it);
6392 if (swap || do_float_fmt_conv)
6400 swap_bytes<sizeof (SRC_T)> (&data[i]);
6401 else if (do_float_fmt_conv)
6413 conv_data[j] = data[i];
6422 swap_bytes<sizeof (SRC_T)> (&data[i]);
6423 else if (do_float_fmt_conv)
6428 conv_data[j] = data[i];
6440 conv_data[j] = data[i];
6447 conv_data[j] = data[i];
6454 input_buf_list.clear ();
6457 conv_data[i] = dst_elt_type (0);
6465 bool swap,
bool do_float_fmt_conv,
bool do_NA_conv,
6468#define TABLE_ELT(T, U, V, W) \
6469 conv_fptr_table[oct_data_conv::T][oct_data_conv::U] = convert_and_copy<V, W>
6471#define FILL_TABLE_ROW(T, V) \
6472 TABLE_ELT (T, dt_int8, V, int8NDArray); \
6473 TABLE_ELT (T, dt_uint8, V, uint8NDArray); \
6474 TABLE_ELT (T, dt_int16, V, int16NDArray); \
6475 TABLE_ELT (T, dt_uint16, V, uint16NDArray); \
6476 TABLE_ELT (T, dt_int32, V, int32NDArray); \
6477 TABLE_ELT (T, dt_uint32, V, uint32NDArray); \
6478 TABLE_ELT (T, dt_int64, V, int64NDArray); \
6479 TABLE_ELT (T, dt_uint64, V, uint64NDArray); \
6480 TABLE_ELT (T, dt_single, V, FloatNDArray); \
6481 TABLE_ELT (T, dt_double, V, NDArray); \
6482 TABLE_ELT (T, dt_char, V, charNDArray); \
6483 TABLE_ELT (T, dt_schar, V, charNDArray); \
6484 TABLE_ELT (T, dt_uchar, V, charNDArray); \
6485 TABLE_ELT (T, dt_logical, V, boolNDArray);
6498 static bool initialized =
false;
6507 for (
int j = 0; j < 14; j++)
6508 conv_fptr_table[i][j] =
nullptr;
6544 switch (output_type)
6563 retval =
fptr (input_buf_list, input_buf_elts, elts_read,
6564 nr, nc, swap, do_float_fmt_conv, do_NA_conv, ffmt);
6569 ::error (
"read: invalid type specification");
6590 bool one_elt_size_spec =
false;
6599 std::size_t char_count = 0;
6601 std::ptrdiff_t tmp_count = 0;
6605 get_size (size, nr, nc, one_elt_size_spec,
"fread");
6614 if (one_elt_size_spec)
6637 if (nr == 0 || nc == 0)
6643 bool read_to_eof = elts_to_read < 0;
6650 input_buf_elts = 1024 * 1024;
6652 input_buf_elts = elts_to_read;
6655 input_buf_elts = block_size;
6660 std::ptrdiff_t input_buf_size
6661 =
static_cast<std::ptrdiff_t
> (input_buf_elts) * input_elt_size;
6663 assert (input_buf_size >= 0);
6669 error (
"fread: invalid input stream");
6672 std::istream& is = *isp;
6677 if (skip != 0 && is && ! is.eof ())
6679 cur_pos = is.tellg ();
6680 is.seekg (0, is.end);
6681 eof_pos = is.tellg ();
6682 is.seekg (cur_pos, is.beg);
6685 std::list<void *> input_buf_list;
6687 while (is && ! is.eof ()
6688 && (read_to_eof || tmp_count < elts_to_read))
6694 if (remaining_elts < input_buf_elts)
6695 input_buf_size = remaining_elts * input_elt_size;
6698 char *input_buf =
new char [input_buf_size];
6700 is.read (input_buf, input_buf_size);
6702 std::size_t gcount = is.gcount ();
6704 char_count += gcount;
6711 input_buf_list.push_back (input_buf);
6713 if (skip != 0 && nel == block_size && is)
6717 off_t remaining = eof_pos - cur_pos;
6719 if (remaining < skip)
6721 is.seekg (0, is.end);
6726 is.seekg (skip, is.cur);
6736 nc = tmp_count / nr;
6738 if (tmp_count % nr != 0)
6744 else if (tmp_count == 0)
6749 else if (tmp_count != nr * nc)
6751 if (tmp_count % nr != 0)
6752 nc = tmp_count / nr + 1;
6754 nc = tmp_count / nr;
6761 error (
"fread: number of elements read exceeds max index size");
6765 retval =
finalize_read (input_buf_list, input_buf_elts, count,
6766 nr, nc, input_type, output_type, ffmt);
6790 error (
"fwrite: write error");
6798 template <
typename T,
typename V>
6802 const T *tt_data =
static_cast<const T *
> (data);
6804 V *vt_data =
static_cast<V *
> (conv_data);
6807 vt_data[i] = tt_data[i];
6810 template <
typename T,
typename V>
6815 typedef typename V::val_type val_type;
6817 val_type *vt_data =
static_cast<val_type *
> (conv_data);
6824 vt_data[i] = val.value ();
6827 swap_bytes<sizeof (val_type)> (&vt_data[i]);
6831 template <
typename T>
6838 template <
typename T>
6845 template <
typename T>
6864 switch (output_type)
6867 convert_chars<ult_elt_type, char> (data, conv_data, n_elts);
6871 convert_chars<ult_elt_type, signed char> (data, conv_data, n_elts);
6875 convert_chars<ult_elt_type, unsigned char> (data, conv_data, n_elts);
6879 convert_ints<T, octave_int8> (data, conv_data, n_elts, swap);
6883 convert_ints<T, octave_uint8> (data, conv_data, n_elts, swap);
6887 convert_ints<T, octave_int16> (data, conv_data, n_elts, swap);
6891 convert_ints<T, octave_uint16> (data, conv_data, n_elts, swap);
6895 convert_ints<T, octave_int32> (data, conv_data, n_elts, swap);
6899 convert_ints<T, octave_uint32> (data, conv_data, n_elts, swap);
6903 convert_ints<T, octave_int64> (data, conv_data, n_elts, swap);
6907 convert_ints<T, octave_uint64> (data, conv_data, n_elts, swap);
6912 float *vt_data =
static_cast<float *
> (conv_data);
6916 vt_data[i] = data[i];
6918 if (do_float_conversion)
6926 double *vt_data =
static_cast<double *
> (conv_data);
6930 vt_data[i] = data[i];
6932 if (do_float_conversion)
6939 ::error (
"write: invalid type specification");
6948 bool status =
false;
6954 std::ostream& os = *osp;
6958 os.write (
static_cast<const char *
> (data), nbytes);
6971 bool status =
false;
6978 std::ostream& os = *osp;
6982 off_t orig_pos =
tell ();
6986 off_t eof_pos =
tell ();
6991 std::size_t remaining = eof_pos - orig_pos;
6993 if (remaining < skip)
6998 unsigned char zero = 0;
6999 for (std::size_t j = 0; j < skip - remaining; j++)
7000 os.write (
reinterpret_cast<const char *
> (&zero), 1);
7011 template <
typename T>
7025 bool do_data_conversion = (swap || ! is_equivalent_type<T> (output_type)
7033 chunk_size = block_size;
7034 else if (do_data_conversion)
7035 chunk_size = 1024 * 1024;
7041 const T *pdata = data.
data ();
7053 if (chunk_size > remaining_nel)
7054 chunk_size = remaining_nel;
7056 bool status =
false;
7058 if (do_data_conversion)
7060 std::size_t output_size
7065 status =
convert_data (&pdata[i], conv_data, chunk_size,
7066 output_type, flt_fmt);
7072 status =
write_bytes (pdata,
sizeof (T) * chunk_size);
7083#define INSTANTIATE_WRITE(T) \
7085 OCTINTERP_API octave_idx_type \
7086 stream::write (const Array<T>& data, octave_idx_type block_size, \
7087 oct_data_conv::data_type output_type, \
7088 octave_idx_type skip, \
7089 mach_info::float_format flt_fmt)
7108#if defined (OCTAVE_HAVE_OVERLOAD_CHAR_INT8_TYPES)
7121 retval =
m_rep->scanf (fmt, size, count, who);
7139 retval =
scanf (sfmt, size, count, who);
7144 error (who +
": format must be a string");
7156 retval =
m_rep->oscanf (fmt, who);
7173 retval =
oscanf (sfmt, who);
7178 error (who +
": format must be a string");
7190 ?
m_rep->do_textscan (fmt, ntimes, options, who, count)
7196 const std::string& who)
7201 retval =
m_rep->printf (fmt, args, who);
7208 const std::string& who)
7219 retval =
printf (sfmt, args, who);
7224 error (who +
": format must be a string");
7236 retval =
m_rep->puts (s, who);
7251 retval =
puts (s, who);
7256 error (who +
": argument must be a string");
7268 retval =
m_rep->eof ();
7276 std::string retval =
"invalid stream object";
7279 retval =
m_rep->error (clear, err_num);
7290 retval =
m_rep->name ();
7301 retval =
m_rep->mode ();
7312 retval =
m_rep->float_format ();
7320 std::string retval =
"???";
7321 std::ios::openmode in_mode =
static_cast<std::ios::openmode
> (
mode);
7323 if (in_mode == std::ios::in)
7325 else if (in_mode == std::ios::out
7328 else if (in_mode == (std::ios::out | std::ios::app))
7330 else if (in_mode == (std::ios::in | std::ios::out))
7334 else if (in_mode == (std::ios::in | std::ios::out | std::ios::ate))
7336 else if (in_mode == (std::ios::in | std::ios::binary))
7338 else if (in_mode == (std::ios::out | std::ios::binary)
7341 else if (in_mode == (std::ios::out | std::ios::app | std::ios::binary))
7343 else if (in_mode == (std::ios::in | std::ios::out | std::ios::binary))
7346 | std::ios::binary))
7348 else if (in_mode == (std::ios::in | std::ios::out | std::ios::ate
7349 | std::ios::binary))
7356 : m_list (), m_lookup_cache (m_list.end ()), m_stdin_file (-1),
7357 m_stdout_file (-1), m_stderr_file (-1)
7389 if (stream_number == -1)
7390 return stream_number;
7406 ::error (
"could not create file id");
7408 m_list[stream_number] = os;
7410 return stream_number;
7413 OCTAVE_NORETURN
static
7418 ::error (
"invalid stream number = %d", fid);
7420 ::error (
"%s: invalid stream number = %d", who.c_str (), fid);
7434 ostrl_map::const_iterator iter =
m_list.find (fid);
7436 if (iter ==
m_list.end ())
7439 retval = iter->second;
7447 const std::string& who)
const
7460 auto iter =
m_list.find (fid);
7462 if (iter ==
m_list.end ())
7465 stream os = iter->second;
7492 retval =
remove (i, who);
7507 for (
auto iter =
m_list.begin (); iter !=
m_list.end (); )
7509 int fid = iter->first;
7516 stream os = iter->second;
7522 if (
name.find (
"gnuplot") != std::string::npos)
7551 ostrl_map::const_iterator iter =
m_list.find (fid);
7553 if (iter ==
m_list.end ())
7563 retval(0) = os.
name ();
7576 ::error (
"file id must be a file object or integer value");
7581 ::error (
"file id must be a file object or integer value");
7588 std::ostringstream buf;
7591 <<
" number mode arch name\n"
7592 <<
" ------ ---- ---- ----\n";
7594 for (
const auto& fid_strm :
m_list)
7596 stream os = fid_strm.second;
7599 << std::setiosflags (std::ios::right)
7600 << std::setw (4) << fid_strm.first <<
" "
7602 << std::resetiosflags (std::ios::adjustfield)
7610 << os.
name () <<
"\n";
7624 for (
const auto& fid_strm :
m_list)
7627 if (fid_strm.first > 2 && fid_strm.second)
7628 retval(0, num_open++) = fid_strm.first;
7631 retval.
resize ((num_open > 0), num_open);
7644 for (
const auto& fid_strm :
m_list)
7647 if (fid_strm.first > 2)
7649 stream os = fid_strm.second;
7651 if (os && os.
name () == nm)
7653 retval = fid_strm.first;
7660 ::error (
"file id must be a file object, std::string, or integer value");
7668 ::error (
"file id must be a file object, std::string, or integer value");
static Matrix null(const Matrix &A, octave_idx_type &rank)
charNDArray max(char d, const charNDArray &m)
charNDArray min(char d, const charNDArray &m)
octave_idx_type numel(void) const
Number of elements in the array.
size_type size(const size_type d) const
Size of the specified dimension.
bool isempty(void) const
Size of the specified dimension.
const T * data(void) const
Size of the specified dimension.
OCTARRAY_API T * fortran_vec(void)
Size of the specified dimension.
void resize(octave_idx_type nr, octave_idx_type nc, double rfv=0)
static bool forced_interactive(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)
OCTINTERP_API int flush(void)
OCTINTERP_API std::string getl(octave_idx_type max_len, bool &err, const std::string &who)
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)
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)
virtual std::istream * input_stream(void)
virtual std::ostream * output_stream(void)
OCTINTERP_API off_t skipl(off_t count, bool &err, const std::string &who)
virtual std::string name(void) const =0
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)
virtual int file_number(void) const
const std::string m_delims
void clear(std::ios_base::iostate m=(std::ios_base::eofbit &~std::ios_base::eofbit))
std::istream & m_i_stream
std::ios_base::iostate rdstate(void)
std::streampos m_buf_in_file
delimited_stream(const delimited_stream &)=delete
void seekg(char *old_idx)
int getline(std::string &dest, char delim)
delimited_stream(std::istream &is, const std::string &delimiters, int longest_lookahead, octave_idx_type bsize=4096)
void setstate(std::ios_base::iostate m)
char * read(char *buffer, int size, char *&new_start)
void progress_benchmark(void)
std::ios_base::iostate m_flags
printf_value_cache(const printf_value_cache &)=delete
octave_value get_next_value(char type=0)
octave_idx_type m_val_idx
const octave_value_list m_values
~printf_value_cache(void)=default
octave_idx_type m_elt_idx
printf_value_cache(const octave_value_list &args, const std::string &who)
OCTINTERP_API int remove(int fid, const std::string &who="")
OCTINTERP_API std::string list_open_files(void) const
OCTINTERP_API octave_value stdin_file(void) const
OCTINTERP_API ~stream_list(void)
OCTINTERP_API int get_file_number(const octave_value &fid) const
ostrl_map::const_iterator m_lookup_cache
OCTINTERP_API void clear(bool flush=true)
OCTINTERP_API int insert(stream &os)
OCTINTERP_API octave_value stderr_file(void) const
OCTINTERP_API octave_value open_file_numbers(void) const
OCTINTERP_API stream lookup(int fid, const std::string &who="") const
OCTINTERP_API octave_value stdout_file(void) const
OCTINTERP_API stream_list(interpreter &interp)
OCTINTERP_API string_vector get_info(int fid) const
OCTINTERP_API void close(void)
OCTINTERP_API bool eof(void) const
void invalid_operation(const std::string &who, const char *rw)
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)
std::istream * input_stream(void)
OCTINTERP_API int puts(const std::string &s, const std::string &who)
OCTINTERP_API mach_info::float_format float_format(void) const
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)
OCTINTERP_API octave_value scanf(const std::string &fmt, const Array< double > &size, octave_idx_type &count, const std::string &who)
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 bool is_open(void) const
OCTINTERP_API int flush(void)
OCTINTERP_API std::string gets(octave_idx_type max_len, bool &err, const std::string &who)
std::ostream * output_stream(void)
OCTINTERP_API bool skip_bytes(std::size_t n_elts)
OCTINTERP_API std::string getl(octave_idx_type max_len, bool &err, const std::string &who)
OCTINTERP_API bool write_bytes(const void *data, std::size_t n_elts)
bool stream_ok(bool clear=true) const
OCTINTERP_API int seek(off_t offset, int origin)
OCTINTERP_API int rewind(void)
OCTINTERP_API octave_value_list oscanf(const std::string &fmt, const std::string &who)
static OCTINTERP_API std::string mode_as_string(int mode)
OCTINTERP_API int mode(void) const
OCTINTERP_API int printf(const std::string &fmt, const octave_value_list &args, const std::string &who)
std::shared_ptr< base_stream > m_rep
OCTINTERP_API std::string name(void) const
bool is_valid(void) const
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)
std::string encoding(void)
OCTINTERP_API off_t tell(void)
OCTINTERP_API std::string error(bool clear, int &err_num)
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())
textscan_format_elt(const textscan_format_elt &e)
std::string parse_char_class(const std::string &pattern) const
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 > m_output_container
std::list< octave_value > out_buf(void) const
void process_conversion(const std::string &s, std::size_t &i, std::size_t n)
const textscan_format_elt * current(void) const
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)
const textscan_format_elt * next(bool cycle=true)
textscan_format_list(const textscan_format_list &)=delete
const textscan_format_elt * first(void)
textscan_format_list(const std::string &fmt=std::string(), const std::string &who="textscan")
~textscan_format_list(void)
int read_first_row(delimited_stream &is, textscan &ts)
std::size_t numel(void) const
std::deque< textscan_format_elt * > m_fmt_elts
octave_idx_type num_conversions(void) const
textscan(const textscan &)=delete
void scan_one(delimited_stream &is, const textscan_format_elt &fmt, octave_value &ov, Array< octave_idx_type > row)
int scan_bracket(delimited_stream &is, const std::string &pattern, std::string &val) const
bool is_delim(unsigned char ch) const
bool multiple_delims_as_one
void scan_cstring(delimited_stream &is, const textscan_format_elt &fmt, std::string &val) const
textscan(const std::string &who_arg="textscan", const std::string &encoding="utf-8")
bool whitespace_delim(void) const
int skip_delim(delimited_stream &is)
bool isspace(unsigned int ch) const
void scan_complex(delimited_stream &is, const textscan_format_elt &fmt, Complex &val) const
double read_double(delimited_stream &is, const textscan_format_elt &fmt) const
bool match_literal(delimited_stream &isp, const textscan_format_elt &elem)
std::string m_delim_table
octave_value m_empty_value
void scan_qstring(delimited_stream &is, const textscan_format_elt &fmt, std::string &val)
octave_idx_type m_buffer_size
void scan_string(delimited_stream &is, const textscan_format_elt &fmt, std::string &val) const
int scan_caret(delimited_stream &is, const std::string &pattern, std::string &val) const
int lookahead(delimited_stream &is, const Cell &targets, int max_len, bool case_sensitive=true) const
std::string m_date_locale
octave_value scan(std::istream &isp, const std::string &fmt, octave_idx_type ntimes, const octave_value_list &options, octave_idx_type &read_count)
int skip_whitespace(delimited_stream &is, bool EOLstop=true)
void parse_options(const octave_value_list &args, textscan_format_list &fmt_list)
std::string m_whitespace_table
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)
octave_value do_scan(std::istream &isp, textscan_format_list &fmt_list, octave_idx_type ntimes)
std::string read_until(delimited_stream &is, const Cell &delimiters, const std::string &ends) const
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
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
octave_base_value * internal_rep(void) 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)
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)
OCTAVE_API int octave_strncasecmp(const char *s1, const char *s2, size_t n)
F77_RET_T const F77_INT const F77_INT const F77_INT const F77_DBLE const F77_DBLE F77_INT F77_DBLE * V
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
F77_RET_T const F77_DBLE * x
std::complex< double > w(std::complex< double > z, double relerr=0)
float_format native_float_format(void)
@ flt_fmt_ieee_big_endian
@ flt_fmt_ieee_little_endian
bool words_big_endian(void)
std::string float_format_as_string(float_format flt_fmt)
FloatComplex(* fptr)(const FloatComplex &, float, int, octave_idx_type &)
bool is_NaN_or_NA(const Complex &x)
octave_idx_type nint_big(double x)
std::complex< T > trunc(const std::complex< T > &x)
OCTAVE_API std::string u8_to_encoding(const std::string &who, const std::string &u8_string, const std::string &encoding)
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 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 Cell init_inf_nan(void)
static int convert_to_valid_int(const octave_value &tc, int &conv_err)
static uint32_t state[624]
static std::istream & octave_scan(std::istream &is, const scanf_format_elt &fmt, T *valptr)
static void convert_ints(const T *data, void *conv_data, octave_idx_type n_elts, bool swap)
static int do_printf_conv(std::ostream &os, const std::string &encoding, const char *fmt, int nsa, int sa_1, int sa_2, T arg, const std::string &who)
static double f(double k, double l_nu, double c_pm)
static std::istream & octave_scan_1(std::istream &is, const scanf_format_elt &fmt, T *valptr)
static OCTAVE_NORETURN void err_invalid_file_id(int fid, const std::string &who)
static bool ok_for_unsigned_int_conv(const octave_value &val)
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 std::string expand_char_class(const std::string &s)
static bool ok_for_signed_int_conv(const octave_value &val)
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 &encoding, const std::string &who)
static bool is_nan_or_inf(const octave_value &val)
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)
interpreter & __get_interpreter__(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)
static std::string switch_to_g_format(const printf_format_elt *elt)
static octave_idx_type get_size(double d, const std::string &who)
static double pown(double x, unsigned int n)
static void convert_chars(const void *data, void *conv_data, octave_idx_type n_elts)
std::complex< double > Complex
std::complex< float > FloatComplex
octave_int< T > mod(const octave_int< T > &x, const octave_int< T > &y)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
#define BEGIN_S_CONVERSION()
#define BEGIN_CHAR_CLASS_CONVERSION()
#define BEGIN_C_CONVERSION()
#define DO_WHITESPACE_CONVERSION()
#define DO_LITERAL_CONVERSION()
#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)
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 void parse_options(regexp::opts &options, const octave_value_list &args, const std::string &who, int skip, bool &extra_args)
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,...)