26 #if defined (HAVE_CONFIG_H)
89 int nargin = args.length ();
94 retval = args(0).convert_to_str (
true,
true,
95 args(0).is_dq_string () ?
'"' :
'\'');
102 std::queue<string_vector> args_as_strings;
104 for (
int i = 0; i < nargin; i++)
106 string_vector s = args(i).xstring_vector_value (
"char: unable to convert some args to strings");
109 n_elts += s.
numel ();
115 if (s_max_len > max_len)
118 args_as_strings.push (s);
125 for (
int i = 0; i < nargin; i++)
128 args_as_strings.pop ();
134 for (
int j = 0; j <
n; j++)
136 std::string t = s[j];
137 int t_len = t.length ();
140 t += std::string (max_len - t_len,
' ');
146 result[k++] = std::string (max_len,
' ');
176 DEFUN (strvcat, args, ,
212 int nargin = args.length ();
215 std::queue<string_vector> args_as_strings;
217 for (
int i = 0; i < nargin; i++)
219 string_vector s = args(i).xstring_vector_value (
"strvcat: unable to convert some args to strings");
226 for (
size_t j = 0; j <
n; j++)
235 if (s_max_len > max_len)
238 args_as_strings.push (s);
245 for (
int i = 0; i < nargin; i++)
248 args_as_strings.pop ();
254 for (
size_t j = 0; j <
n; j++)
256 std::string t = s[j];
259 size_t t_len = t.length ();
262 t += std::string (max_len - t_len,
' ');
289 DEFUN (ischar, args, ,
296 if (args.length () != 1)
299 return ovl (args(0).is_string ());
324 bool (*str_op) (
const std::string&,
const std::string&,
325 std::string::size_type))
331 bool s1_cell = arg0.
iscell ();
333 bool s2_cell = arg1.
iscell ();
335 if (s1_string && s2_string)
337 else if ((s1_string && s2_cell) || (s1_cell && s2_string))
356 if (
r == 0 ||
r == 1)
362 std::string s = (
r == 0 ?
"" : str[0]);
368 output(i) = str_op (cellstr(i), s,
n);
375 if (cell(i).is_string ())
376 output(i) = str_op (cell(i).string_value (), s,
n);
384 if (cell.
numel () == 1)
391 if (cell(0).is_string ())
393 const std::string str2 = cell(0).string_value ();
396 output(i) = str_op (str[i], str2,
n);
414 output(i) = str_op (str[i], cellstr(i),
n);
421 if (cell(i).is_string ())
422 output(i) = str_op (str[i],
423 cell(i).string_value (),
n);
434 else if (s1_cell && s2_cell)
466 if (cell2(0).is_string ())
468 const std::string str2 = cell2(0).string_value ();
474 output(i) = str_op (cellstr(i), str2,
n);
481 if (cell1(i).is_string ())
483 const std::string str1 = cell1(i).string_value ();
484 output(i) = str_op (str1, str2,
n);
493 error (
"%s: nonconformant cell arrays", fcn_name);
500 output (i) = str_op (cellstr1(i), cellstr2(i),
n);
507 if (cell1(i).is_string () && cell2(i).is_string ())
509 const std::string str1 = cell1(i).string_value ();
510 const std::string str2 = cell2(i).string_value ();
511 output(i) = str_op (str1, str2,
n);
529 template <
typename T,
typename T_
size_type>
534 template <
typename T,
typename T_
size_type>
558 if (args.length () != 2)
646 if (args.length () != 3)
656 error (
"strncmp: N must be greater than 0");
695 if (args.length () != 2)
726 if (args.length () != 3)
736 error (
"strncmpi: N must be greater than 0");
792 if (args.length () != 1)
797 if (args(0).is_string ())
799 if (args(0).rows () == 0 || args(0).columns () == 0)
801 else if (args(0).rows () == 1 && args(0).ndims () == 2)
810 else if (args(0).iscell ())
812 const Cell cell = args(0).cell_value ();
818 if (cell(i).is_string ())
876 DEFUN (__native2unicode__, args, ,
884 int nargin = args.length ();
889 if (args(0).is_string ())
890 return ovl (args(0));
892 std::string tmp = args(1).string_value ();
896 charNDArray native_bytes = args(0).char_array_value ();
898 const char *src = native_bytes.
data ();
899 size_t srclen = native_bytes.
numel ();
902 uint8_t *utf8_str =
nullptr;
911 error (
"native2unicode: iconv() is not supported. Installing GNU "
912 "libiconv and then re-compiling Octave could fix this.");
914 error (
"native2unicode: converting from codepage '%s' to UTF-8: %s",
915 codepage, std::strerror (errno));
918 frame.
add_fcn (::
free,
static_cast<void *
> (utf8_str));
930 DEFUN (__unicode2native__, args, ,
939 int nargin = args.length ();
944 std::string tmp = args(1).string_value ();
948 charNDArray utf8_str = args(0).char_array_value ();
950 const uint8_t *src =
reinterpret_cast<const uint8_t *
> (utf8_str.
data ());
951 size_t srclen = utf8_str.
numel ();
954 char *native_bytes =
nullptr;
963 error (
"unicode2native: iconv() is not supported. Installing GNU "
964 "libiconv and then re-compiling Octave could fix this.");
966 error (
"unicode2native: converting from UTF-8 to codepage '%s': %s",
967 codepage, std::strerror (errno));
970 frame.
add_fcn (::
free,
static_cast<void *
> (native_bytes));
982 DEFUN (__locale_charset__, , ,
990 std::string charset_str (charset);
991 return ovl (charset_str);
994 DEFUN (unicode_idx, args, ,
1008 int nargin = args.length ();
1013 charNDArray str = args(0).xchar_array_value (
"STR must be a string");
1016 if (str.
ndims () > 1)
1025 const uint8_t *src =
reinterpret_cast<const uint8_t *
> (str_p.
data ());
1037 idx (i+j) = u8_char_num;
1048 DEFUN (__u8_validate__, args, ,
1061 if (args.length () < 1 || args.length () > 2)
1065 std::string in_str =
1066 args(0).xstring_value (
"__u8_validate__: IN_STR must be a string.");
1068 std::string mode =
"replace";
1069 if (args.length () > 1)
1070 mode = args(1).xstring_value (
"__u8_validate__: MODE must be a string.");
1073 if (mode ==
"replace")
1075 else if (mode ==
"unicode")
1078 error (
"__u8_validate__: MODE must either be \"replace\" or \"unicode\".");
1082 return ovl (in_str);
1085 DEFUN (newline, args, ,
1106 if (args.length () != 0)
1121 DEFUN (list_in_columns, args, ,
1157 int nargin = args.length ();
1159 if (nargin < 1 || nargin > 3)
1162 string_vector s = args(0).xstring_vector_value (
"list_in_columns: ARG must be a cellstr or char array");
1166 if (nargin > 1 && ! args(1).isempty ())
1167 width = args(1).xint_value (
"list_in_columns: WIDTH must be an integer");
1172 prefix = args(2).xstring_value (
"list_in_columns: PREFIX must be a string");
1174 std::ostringstream buf;
1178 return ovl (buf.str ());
T & xelem(octave_idx_type n)
Size of the specified dimension.
octave_idx_type numel(void) const
Number of elements in the array.
const T * data(void) const
Size of the specified dimension.
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
int ndims(void) const
Size of the specified dimension.
Array< T > permute(const Array< octave_idx_type > &vec, bool inv=false) const
Size of the specified dimension.
bool iscellstr(void) const
MArray< T > permute(const Array< octave_idx_type > &vec, bool inv=false) const
Vector representing the dimensions (size) of an Array.
void add_fcn(void(*fcn)(Params...), Args &&... args)
bool iscellstr(void) const
octave_idx_type numel(void) const
bool is_string(void) const
charNDArray char_array_value(bool frc_str_conv=false) const
Cell cell_value(void) const
string_vector string_vector_value(bool pad=false) const
Array< std::string > cellstr_value(void) const
dim_vector dims(void) const
std::ostream & list_in_columns(std::ostream &, int width=0, const std::string &prefix="") const
octave_idx_type max_length(void) const
octave_idx_type numel(void) const
Array< U > map(F fcn) const
OCTINTERP_API void print_usage(void)
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
#define DEFUNX(name, fname, args_name, nargout_name, doc)
Macro to define a builtin function with certain internal name.
void error(const char *fmt,...)
const char * octave_locale_charset_wrapper(void)
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.
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 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
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_value::octave_value(const Array< char > &chm, char type) return retval
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
OCTAVE_EXPORT octave_value_list Fstrncmpi(const octave_value_list &args, int)
static bool strcmpi_ignore_n(const T &s1, const T &s2, T_size_type)
OCTAVE_EXPORT octave_value_list Fstrcmpi(const octave_value_list &args, int)
static octave_value do_strcmp_fun(const octave_value &arg0, const octave_value &arg1, octave_idx_type n, const char *fcn_name, bool(*array_op)(const Array< char > &, const Array< char > &, octave_idx_type), bool(*str_op)(const std::string &, const std::string &, std::string::size_type))
static bool strcmp_ignore_n(const T &s1, const T &s2, T_size_type)
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)
int octave_u8_strmblen_wrapper(const uint8_t *src)