26 #if defined (HAVE_CONFIG_H)
47 str_data_cmp (
const typename T::value_type *a,
const typename T::value_type *b,
48 const typename T::size_type
n)
50 for (
typename T::size_type i = 0; i <
n; ++i)
58 str_data_cmpi (
const typename T::value_type *a,
const typename T::value_type *b,
59 const typename T::size_type
n)
61 for (
typename T::size_type i = 0; i <
n; ++i)
62 if (std::tolower (a[i]) != std::tolower (b[i]))
85 strlen (
const typename T::value_type *str)
94 return str_a.size () == str_b.size ();
101 return str_a.
dims () == str_b.
dims ();
104 template <
typename T>
106 sizes_cmp (
const T& str_a,
const typename T::value_type *str_b)
108 return str_a.size () == strlen<T> (str_b);
125 && str_data_cmp<T> (str_a.data (), str_b.data (),
numel (str_a)));
133 && str_data_cmp<T> (str_a.data (), str_b,
numel (str_a)));
142 && str_data_cmpi<T> (str_a.data (), str_b.data (),
numel (str_a)));
150 && str_data_cmpi<T> (str_a.data (), str_b,
numel (str_a)));
157 const typename T::size_type
n)
159 typename T::size_type neff;
160 auto len_a =
numel (str_a);
161 auto len_b =
numel (str_b);
164 return (len_a >= neff && len_b >= neff
165 && str_data_cmp<T> (str_a.data (), str_b.data (), neff));
171 const typename T::size_type
n)
173 typename T::size_type neff;
174 auto len_a =
numel (str_a);
175 auto len_b = strlen<T> (str_b);
178 return (len_a >= neff && len_b >= neff
179 && str_data_cmp<T> (str_a.data (), str_b, neff));
186 const typename T::size_type
n)
188 typename T::size_type neff;
189 auto len_a =
numel (str_a);
190 auto len_b =
numel (str_b);
193 return (len_a >= neff && len_b >= neff
194 && str_data_cmpi<T> (str_a.data (), str_b.data (), neff));
200 const typename T::size_type
n)
202 typename T::size_type neff;
203 auto len_a =
numel (str_a);
204 auto len_b = strlen<T> (str_b);
207 return (len_a >= neff && len_b >= neff
208 && str_data_cmpi<T> (str_a.data (), str_b, neff));
213 #define INSTANTIATE_OCTAVE_STRING(T) \
214 template bool octave::string::strcmp<T> (const T&, const T&); \
215 template bool octave::string::strcmp<T> (const T&, \
216 const typename T::value_type*); \
217 template bool octave::string::strcmpi<T> (const T&, const T&); \
218 template bool octave::string::strcmpi<T> (const T&, \
219 const typename T::value_type*); \
220 template bool octave::string::strncmp<T> (const T&, const T&, \
221 const typename T::size_type); \
222 template bool octave::string::strncmp<T> (const T&, \
223 const typename T::value_type*, \
224 const typename T::size_type); \
225 template bool octave::string::strncmpi<T> (const T&, const T&, \
226 const typename T::size_type n); \
227 template bool octave::string::strncmpi<T> (const T&, \
228 const typename T::value_type*, \
229 const typename T::size_type);
236 #undef INSTANTIATE_OCTAVE_STRING
240 {
return c ==
'i' || c ==
'j'; }
256 if (std::toupper (c) ==
'I')
262 if (std::tolower (c1) ==
'n' && std::tolower (c2) ==
'f')
268 is.setstate (std::ios::failbit);
283 if (c1 ==
'a' && c2 ==
'N')
289 is.setstate (std::ios::failbit);
298 static std::istringstream&
301 have_sign =
imag =
false;
312 bool negative =
false;
315 if (c ==
'+' || c ==
'-')
341 num = (negative ? -1.0 : 1.0);
346 if (std::tolower (c) !=
'n')
411 is.setstate (std::ios::failbit);
441 #if defined (HAVE_CXX_COMPLEX_SETTERS)
446 #elif defined (HAVE_CXX_COMPLEX_REFERENCE_ACCESSORS)
464 std::string str = str_arg;
468 str.erase (std::remove (str.begin (), str.end(),
','), str.end ());
469 std::istringstream is (str);
484 if (!
extract_num (is, num, i2, s2) || i1 == i2 || ! s2)
496 const std::string& u8_string,
497 const std::string& encoding)
499 const uint8_t *src =
reinterpret_cast<const uint8_t *
>
500 (u8_string.c_str ());
501 size_t srclen = u8_string.length ();
510 (*current_liboctave_error_handler)
511 (
"%s: iconv() is not supported. Installing GNU libiconv and then "
512 "re-compiling Octave could fix this.", who.c_str ());
515 (
"%s: converting from UTF-8 to codepage '%s' failed: %s",
516 who.c_str (), encoding.c_str (), std::strerror (errno));
520 frame.
add_fcn (::
free,
static_cast<void *
> (native_str));
529 const std::string& native_string,
530 const std::string& encoding)
532 const char *src = native_string.c_str ();
533 size_t srclen = native_string.length ();
541 (*current_liboctave_error_handler)
542 (
"%s: iconv() is not supported. Installing GNU libiconv and then "
543 "re-compiling Octave could fix this.", who.c_str ());
546 (
"%s: converting from codepage '%s' to UTF-8 failed: %s",
547 who.c_str (), encoding.c_str (), std::strerror (errno));
551 frame.
add_fcn (::
free,
static_cast<void *
> (utf8_str));
553 std::string
retval = std::string (
reinterpret_cast<char *
> (utf8_str),
length);
565 unsigned int num_replacements = 0;
566 const char *in_chr = in_str.c_str ();
567 const char *inv_utf8 = in_chr;
568 const char *
const in_end = in_chr + in_str.length ();
569 while (inv_utf8 && in_chr < in_end)
571 inv_utf8 =
reinterpret_cast<const char *
>
575 if (inv_utf8 ==
nullptr)
576 out_str.append (in_chr, in_end - in_chr);
580 out_str.append (in_chr, inv_utf8 - in_chr);
581 in_chr = inv_utf8 + 1;
584 out_str.append (
"\xef\xbf\xbd");
587 std::string fallback =
"iso-8859-1";
590 (fallback.c_str (), inv_utf8, 1, &lengthp);
593 (*current_liboctave_error_handler)
594 (
"%s: converting from codepage '%s' to UTF-8 failed: %s",
595 who.c_str (), fallback.c_str (), std::strerror (errno));
598 frame.
add_fcn (::
free,
static_cast<void *
> (val_utf8));
600 out_str.append (
reinterpret_cast<const char *
> (val_utf8),
607 return num_replacements;
610 template <
typename T>
632 std::ostringstream buf;
633 buf.flags (std::ios::fixed);
646 std::ostringstream init_buf;
647 init_buf.flags (std::ios::fixed);
648 init_buf << std::setprecision (0) << static_cast<int> (
n);
667 n = step *
n + lastn;
668 d = step *
d + lastd;
672 std::ostringstream buf;
673 buf.flags (std::ios::fixed);
674 buf << std::setprecision (0) << static_cast<int> (
n)
675 <<
'/' <<
static_cast<int> (
d);
681 if (buf.str ().length () >
static_cast<unsigned int> (
len + 2))
686 if (buf.str ().length () >
static_cast<unsigned int> (
len))
702 std::ostringstream buf;
703 buf.flags (std::ios::fixed);
704 buf << std::setprecision (0) << static_cast<int> (lastn)
705 <<
'/' <<
static_cast<int> (lastd);
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.
bool isvector(void) const
Size of the specified dimension.
octave_idx_type rows(void) const
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
void add_fcn(void(*fcn)(Params...), Args &&... args)
ColumnVector imag(const ComplexColumnVector &a)
OCTAVE_NORETURN liboctave_error_handler current_liboctave_error_handler
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
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.
bool strncmpi(const T &str_a, const T &str_b, const typename T::size_type n)
True if the first N characters are the same, ignoring case.
OCTAVE_API std::string u8_to_encoding(const std::string &who, const std::string &u8_string, const std::string &encoding)
bool strcmp(const T &str_a, const T &str_b)
True if strings are the same.
bool strcmpi(const T &str_a, const T &str_b)
True if strings are the same, ignoring case.
OCTAVE_API std::string u8_from_encoding(const std::string &who, const std::string &native_string, const std::string &encoding)
OCTAVE_API Complex str2double(const std::string &str_arg)
OCTAVE_API unsigned int u8_validate(const std::string &who, std::string &in_string, const u8_fallback_type type=U8_REPLACEMENT_CHAR)
std::complex< double > Complex
template std::string rational_approx< double >(double val, int len)
template std::string rational_approx< float >(float val, int len)
static void set_component(Complex &c, double num, bool imag)
static double single_num(std::istringstream &is)
static bool str_data_cmp(const typename T::value_type *a, const typename T::value_type *b, const typename T::size_type n)
static bool is_imag_unit(int c)
static std::istringstream & extract_num(std::istringstream &is, double &num, bool &imag, bool &have_sign)
static bool str_data_cmpi(const typename T::value_type *a, const typename T::value_type *b, const typename T::size_type n)
#define INSTANTIATE_OCTAVE_STRING(T)
T::size_type numel(const T &str)
bool sizes_cmp(const T &str_a, const T &str_b)
T::size_type strlen(const typename T::value_type *str)
std::string rational_approx(T val, int len)
octave_value::octave_value(const Array< char > &chm, char type) return retval
uint8_t * octave_u8_conv_from_encoding(const char *fromcode, const char *src, size_t srclen, size_t *lengthp)
char * octave_u8_conv_to_encoding(const char *tocode, const uint8_t *src, size_t srclen, size_t *lengthp)
const uint8_t * octave_u8_check_wrapper(const uint8_t *src, size_t n)