23 #if defined (HAVE_CONFIG_H) 98 std::queue<string_vector> args_as_strings;
102 string_vector s = args(
i).xstring_vector_value (
"char: unable to convert some args to strings");
105 n_elts +=
s.numel ();
109 int s_max_len =
s.max_length ();
111 if (s_max_len > max_len)
114 args_as_strings.push (
s);
124 args_as_strings.pop ();
130 for (
int j = 0; j < n; j++)
172 DEFUN (strvcat, args, ,
208 int nargin = args.length ();
211 std::queue<string_vector> args_as_strings;
215 string_vector s = args(
i).xstring_vector_value (
"strvcat: unable to convert some args to strings");
217 size_t n =
s.numel ();
222 for (
size_t j = 0; j < n; j++)
229 size_t s_max_len =
s.max_length ();
231 if (s_max_len > max_len)
234 args_as_strings.push (
s);
244 args_as_strings.pop ();
246 size_t n =
s.numel ();
250 for (
size_t j = 0; j < n; j++)
292 if (args.length () != 1)
321 std::string::size_type))
327 bool s1_cell = arg0.
iscell ();
329 bool s2_cell = arg1.
iscell ();
331 if (s1_string && s2_string)
333 else if ((s1_string && s2_cell) || (s1_cell && s2_string))
352 if (r == 0 || r == 1)
364 output(
i) = str_op (cellstr(
i),
s, n);
371 if (cell(
i).is_string ())
380 if (cell.
numel () == 1)
392 output(
i) = str_op (
str[
i], str2, n);
403 if (cell.
numel () == r)
410 output(
i) = str_op (
str[
i], cellstr(
i), n);
418 output(
i) = str_op (
str[
i],
430 else if (s1_cell && s2_cell)
470 output(
i) = str_op (cellstr(
i), str2, n);
480 output(
i) = str_op (str1, str2, n);
489 error (
"%s: nonconformant cell arrays", fcn_name);
496 output (
i) = str_op (cellstr1(
i), cellstr2(
i), n);
507 output(
i) = str_op (str1, str2, n);
525 template <
typename T,
typename T_
size_type>
527 strcmp_ignore_n (
const T& s1,
const T&
s2, T_size_type)
530 template <
typename T,
typename T_
size_type>
532 strcmpi_ignore_n (
const T& s1,
const T&
s2, T_size_type)
554 if (args.length () != 2)
557 return ovl (do_strcmp_fun (args(0), args(1), 0,
"strcmp",
558 strcmp_ignore_n, strcmp_ignore_n));
642 if (args.length () != 3)
648 return ovl (do_strcmp_fun (args(0), args(1), n,
"strncmp",
652 error (
"strncmp: N must be greater than 0");
669 DEFUNX (
"strcmpi", Fstrcmpi, args, ,
689 if (args.length () != 2)
692 return ovl (do_strcmp_fun (args(0), args(1), 0,
"strcmpi",
693 strcmpi_ignore_n, strcmpi_ignore_n));
700 DEFUNX (
"strncmpi", Fstrncmpi, args, ,
720 if (args.length () != 3)
726 return ovl (do_strcmp_fun (args(0), args(1), n,
"strncmpi",
730 error (
"strncmpi: N must be greater than 0");
737 DEFUN (__native2unicode__, args, ,
745 int nargin = args.length ();
751 return ovl (args(0));
753 std::string tmp = args(1).xstring_value (
"CODEPAGE must be a string");
757 charNDArray native_bytes = args(0).char_array_value ();
759 const char *src = native_bytes.
data ();
760 size_t srclen = native_bytes.
numel ();
763 uint8_t *utf8_str =
nullptr;
772 error (
"native2unicode: iconv() is not supported. Installing GNU " 773 "libiconv and then re-compiling Octave could fix this.");
775 error (
"native2unicode: converting from codepage '%s' to UTF-8: %s",
776 codepage, std::strerror (errno));
791 DEFUN (__unicode2native__, args, ,
800 int nargin = args.length ();
805 std::string tmp = args(1).xstring_value (
"CODEPAGE must be a string");
809 charNDArray utf8_str = args(0).xchar_array_value (
"UTF8_STR must be a string");
811 const uint8_t *src =
reinterpret_cast<const uint8_t *
> (utf8_str.
data ());
812 size_t srclen = utf8_str.
numel ();
815 char *native_bytes =
nullptr;
824 error (
"unicode2native: iconv() is not supported. Installing GNU " 825 "libiconv and then re-compiling Octave could fix this.");
827 error (
"unicode2native: converting from UTF-8 to codepage '%s': %s",
828 codepage, std::strerror (errno));
831 frame.
add_fcn (::free, static_cast<void *> (native_bytes));
843 DEFUN (list_in_columns, args, ,
879 int nargin = args.length ();
884 string_vector s = args(0).xstring_vector_value (
"list_in_columns: ARG must be a cellstr or char array");
889 width = args(1).xint_value (
"list_in_columns: WIDTH must be an integer");
894 prefix = args(2).xstring_value (
"list_in_columns: PREFIX must be a string");
896 std::ostringstream buf;
898 s.list_in_columns (buf, width, prefix);
900 return ovl (buf.str ());
OCTAVE_EXPORT octave_value_list ischar
std::string string_value(bool force=false) const
const T * data(void) const
uint8_t * octave_u8_conv_from_encoding(const char *fromcode, const char *src, size_t srclen, size_t *lengthp)
OCTINTERP_API void print_usage(void)
char * octave_u8_conv_to_encoding(const char *tocode, const uint8_t *src, size_t srclen, size_t *lengthp)
void add_fcn(void(*fcn)(void))
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void error(const char *fmt,...)
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
bool is_dq_string(void) const
charNDArray char_array_value(bool frc_str_conv=false) const
bool iscellstr(void) const
create a structure array and initialize its values The dimensions of each cell array of values must match Singleton cells and non cell values are repeated so that they fill the entire array If the cells are empty
bool iscellstr(void) const
octave_idx_type numel(const octave_value_list &idx)
bool strcmp(const T &str_a, const T &str_b)
True if strings are the same.
dim_vector dims(void) const
#define DEFUNX(name, fname, args_name, nargout_name, doc)
Macro to define a builtin function with certain internal name.
octave_value convert_to_str(bool pad=false, bool force=false, char type='\'') const
With real return the complex result
octave::unwind_protect frame
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
bool strcmpi(const T &str_a, const T &str_b)
True if strings are the same, ignoring case.
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).isinteger())
octave_idx_type length(void) const
const char * octave_locale_charset_wrapper(void)
string_vector string_vector_value(bool pad=false) const
bool is_string(void) const
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_idx_type numel(void) const
Number of elements in the array.
octave_idx_type length(void) const
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.
Vector representing the dimensions (size) of an Array.
Array< std::string > cellstr_value(void) const
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Cell cell_value(void) const