26 #if defined (HAVE_CONFIG_H)
91 int nargin = args.
length ();
97 args(0).is_dq_string () ?
'"' :
'\'');
104 std::queue<string_vector> args_as_strings;
106 for (
int i = 0; i < nargin; i++)
108 string_vector s = args(i).xstring_vector_value (
"char: unable to convert some args to strings");
111 n_elts += s.
numel ();
117 if (s_max_len > max_len)
120 args_as_strings.push (s);
127 for (
int i = 0; i < nargin; i++)
130 args_as_strings.pop ();
136 for (
int j = 0; j <
n; j++)
138 std::string t = s[j];
139 int t_len = t.length ();
142 t += std::string (max_len - t_len,
' ');
148 result[k++] = std::string (max_len,
' ');
178 DEFUN (strvcat, args, ,
214 int nargin = args.length ();
216 std::size_t max_len = 0;
217 std::queue<string_vector> args_as_strings;
219 for (
int i = 0; i < nargin; i++)
221 string_vector s = args(i).xstring_vector_value (
"strvcat: unable to convert some args to strings");
223 std::size_t
n = s.
numel ();
228 for (std::size_t j = 0; j <
n; j++)
237 if (s_max_len > max_len)
240 args_as_strings.push (s);
247 for (
int i = 0; i < nargin; i++)
250 args_as_strings.pop ();
252 std::size_t
n = s.
numel ();
256 for (std::size_t j = 0; j <
n; j++)
258 std::string t = s[j];
261 std::size_t t_len = t.length ();
264 t += std::string (max_len - t_len,
' ');
291 DEFUN (ischar, args, ,
298 if (args.length () != 1)
301 return ovl (args(0).is_string ());
326 bool (*str_op) (
const std::string&,
const std::string&,
327 std::string::size_type))
333 bool s1_cell = arg0.
iscell ();
335 bool s2_cell = arg1.
iscell ();
337 if (s1_string && s2_string)
339 else if ((s1_string && s2_cell) || (s1_cell && s2_string))
358 if (
r == 0 ||
r == 1)
364 std::string s = (
r == 0 ?
"" : str[0]);
370 output(i) = str_op (cellstr(i), s,
n);
377 if (cell(i).is_string ())
378 output(i) = str_op (cell(i).string_value (), s,
n);
386 if (cell.
numel () == 1)
393 if (cell(0).is_string ())
395 const std::string str2 = cell(0).string_value ();
398 output(i) = str_op (str[i], str2,
n);
416 output(i) = str_op (str[i], cellstr(i),
n);
423 if (cell(i).is_string ())
424 output(i) = str_op (str[i],
425 cell(i).string_value (),
n);
436 else if (s1_cell && s2_cell)
468 if (cell2(0).is_string ())
470 const std::string str2 = cell2(0).string_value ();
476 output(i) = str_op (cellstr(i), str2,
n);
483 if (cell1(i).is_string ())
485 const std::string str1 = cell1(i).string_value ();
486 output(i) = str_op (str1, str2,
n);
495 error (
"%s: nonconformant cell arrays", fcn_name);
502 output (i) = str_op (cellstr1(i), cellstr2(i),
n);
509 if (cell1(i).is_string () && cell2(i).is_string ())
511 const std::string str1 = cell1(i).string_value ();
512 const std::string str2 = cell2(i).string_value ();
513 output(i) = str_op (str1, str2,
n);
531 template <
typename T,
typename T_
size_type>
536 template <
typename T,
typename T_
size_type>
560 if (args.length () != 2)
648 if (args.length () != 3)
658 error (
"strncmp: N must be greater than 0");
698 if (args.length () != 2)
729 if (args.length () != 3)
739 error (
"strncmpi: N must be greater than 0");
795 if (args.length () != 1)
800 if (args(0).is_string ())
802 if (args(0).rows () == 0 || args(0).columns () == 0)
804 else if (args(0).rows () == 1 && args(0).ndims () == 2)
813 else if (args(0).iscell ())
815 const Cell cell = args(0).cell_value ();
821 if (cell(i).is_string ())
879 DEFUN (__native2unicode__, args, ,
887 if (args(0).is_string ())
888 return ovl (args(0));
890 std::string tmp = args(1).string_value ();
894 charNDArray native_bytes = args(0).char_array_value ();
896 const char *src = native_bytes.
data ();
897 std::size_t srclen = native_bytes.
numel ();
900 uint8_t *utf8_str =
nullptr;
907 error (
"native2unicode: iconv() is not supported. Installing GNU "
908 "libiconv and then re-compiling Octave could fix this.");
910 error (
"native2unicode: converting from codepage '%s' to UTF-8: %s",
911 codepage, std::strerror (errno));
921 retval.
xelem (i) = utf8_str[i];
926 DEFUN (__unicode2native__, args, ,
935 std::string tmp = args(1).string_value ();
939 charNDArray utf8_str = args(0).char_array_value ();
941 const uint8_t *src =
reinterpret_cast<const uint8_t *
> (utf8_str.
data ());
942 std::size_t srclen = utf8_str.
numel ();
945 char *native_bytes =
nullptr;
952 error (
"unicode2native: iconv() is not supported. Installing GNU "
953 "libiconv and then re-compiling Octave could fix this.");
955 error (
"unicode2native: converting from UTF-8 to codepage '%s': %s",
956 codepage, std::strerror (errno));
966 retval.
xelem (i) = native_bytes[i];
971 DEFUN (__locale_charset__, , ,
979 std::string charset_str (charset);
980 return ovl (charset_str);
983 DEFUN (unicode_idx, args, ,
997 if (args.length () != 1)
1000 charNDArray str = args(0).xchar_array_value (
"STR must be a string");
1003 if (str.
ndims () > 1)
1012 const uint8_t *src =
reinterpret_cast<const uint8_t *
> (str_p.
data ());
1024 idx(i+j) = u8_char_num;
1035 DEFUN (__unicode_length__, args, ,
1053 if (args.length () != 1)
1056 bool arg_char = args(0).is_char_matrix ();
1058 if (! arg_char && ! args(0).iscellstr ())
1059 error (
"STR must be a character array or cell string.");
1067 if (str.
ndims () > 1)
1076 const uint8_t *src =
reinterpret_cast<const uint8_t *
> (str.
data ());
1079 retval =
ovl (mbsnlen);
1084 NDArray output (args(0).dims (),
false);
1088 =
reinterpret_cast<const uint8_t *
> (cellstr(i).c_str ());
1092 retval =
ovl (output);
1105 DEFUN (__u8_validate__, args, ,
1117 int nargin = args.length ();
1119 if (nargin < 1 || nargin > 2)
1123 std::string in_str =
1124 args(0).xstring_value (
"__u8_validate__: IN_STR must be a string");
1126 std::string mode =
"replace";
1128 mode = args(1).xstring_value (
"__u8_validate__: MODE must be a string");
1131 if (mode ==
"replace")
1133 else if (mode ==
"unicode")
1136 error (R
"(__u8_validate__: MODE must be either "replace" or "unicode")");
1140 return ovl (in_str);
1143 DEFUN (newline, args, ,
1164 if (args.length () != 0)
1181 DEFUN (list_in_columns, args, ,
1217 int nargin = args.length ();
1219 if (nargin < 1 || nargin > 3)
1223 0).xstring_vector_value (
"list_in_columns: ARG must be a cellstr or char array");
1227 if (nargin > 1 && ! args(1).isempty ())
1228 width = args(1).xint_value (
"list_in_columns: WIDTH must be an integer");
1233 prefix = args(2).xstring_value (
"list_in_columns: PREFIX must be a string");
1235 std::ostringstream buf;
1239 return ovl (buf.str ());
OCTARRAY_OVERRIDABLE_FUNC_API const T * data(void) const
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_OVERRIDABLE_FUNC_API const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
OCTARRAY_API Array< T, Alloc > permute(const Array< octave_idx_type > &vec, bool inv=false) const
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API int ndims(void) const
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API T & xelem(octave_idx_type n)
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.
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
octave_value convert_to_str(bool pad=false, bool force=false, char type='\'') const
OCTINTERP_API octave_idx_type length(void) 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
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
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)
std::complex< double > Complex
OCTAVE_API unsigned int u8_validate(const std::string &who, std::string &in_string, const u8_fallback_type type=U8_REPLACEMENT_CHAR)
OCTAVE_API bool strcmpi(const T &str_a, const T &str_b)
True if strings are the same, ignoring case.
OCTAVE_API bool strcmp(const T &str_a, const T &str_b)
Octave string utility functions.
OCTAVE_API Complex str2double(const std::string &str_arg)
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.
OCTAVE_API 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.
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
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)
static octave_value do_strcmp_fcn(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))
OCTAVE_EXPORT octave_value_list Fstrcmpi(const octave_value_list &args, int)
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)
size_t octave_u8_mbsnlen_wrapper(const uint8_t *src, size_t n)