GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
oct-string.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2016-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_oct_string_h)
27 #define octave_oct_string_h 1
28 
29 #include "octave-config.h"
30 
31 #include "oct-cmplx.h"
32 
33 namespace octave
34 {
35  //! Octave string utility functions.
36  //!
37  //! This functions provide a C++ interface to most string functions
38  //! available in the Octave interpreter.
39  //!
40  //! Specializations for Array may consider its dimensions in addition
41  //! to the actual string contents.
42  //!
43  //! @attention
44  //! Octave's string comparison functions return true when strings are
45  //! are equal, just the opposite of the corresponding C library functions.
46  //! In addition, Octave's function only return bool and do not check
47  //! lexicographical order.
48 
49  namespace string
50  {
51  //! True if strings are the same.
52  //!
53  //! ## Specialization for Array<char>
54  //!
55  //! When comparing whole Array of chars, the actual Array dimensions
56  //! are significant. A column vector and row vector with the same
57  //! char array, will still return false.
58 
59  template <typename T>
60  bool strcmp (const T& str_a, const T& str_b);
61 
62  //! True if string is the same as character sequence.
63  //!
64  //! Compares a string to the null-terminated character sequence
65  //! beginning at the character pointed to by str_b.
66  //!
67  //! ## Specialization for Array<char>
68  //!
69  //! For purposes of comparison of dimensions, the character sequence
70  //! is considered to be a row vector.
71 
72  template <typename T>
73  bool strcmp (const T& str_a, const typename T::value_type *str_b);
74 
75  //! True if strings are the same, ignoring case.
76  //!
77  //! ## Specialization for Array<char>
78  //!
79  //! When comparing whole Array of chars, the actual Array dimensions
80  //! are significant. A column vector and row vector with the same
81  //! char array, will still return false.
82 
83  template <typename T>
84  bool strcmpi (const T& str_a, const T& str_b);
85 
86  //! True if string is the same as character sequence, ignoring case.
87  //!
88  //! ## Specialization for Array<char>
89  //!
90  //! For purposes of comparison of dimensions, the character sequence
91  //! is considered to be a row vector.
92 
93  template <typename T>
94  bool strcmpi (const T& str_a, const typename T::value_type *str_b);
95 
96  //! True if the first N characters are the same.
97  //!
98  //! ## Specialization for Array<char>
99  //!
100  //! The comparison is done in the first N characters, the actual
101  //! dimensions of the Array are irrelevant. A row vector and
102  //! a column vector of the same still return true.
103 
104  template <typename T>
105  bool strncmp (const T& str_a, const T& str_b,
106  const typename T::size_type n);
107 
108  //! True if the first N characters are the same.
109  template <typename T>
110  bool strncmp (const T& str_a, const typename T::value_type *str_b,
111  const typename T::size_type n);
112 
113  //! True if the first N characters are the same, ignoring case.
114  //!
115  //! ## Specialization for Array<char>
116  //!
117  //! The comparison is done in the first N characters, the actual
118  //! dimensions of the Array are irrelevant. A row vector and
119  //! a column vector of the same still return true.
120 
121  template <typename T>
122  bool strncmpi (const T& str_a, const T& str_b,
123  const typename T::size_type n);
124 
125  //! True if the first N characters are the same, ignoring case.
126  template <typename T>
127  bool strncmpi (const T& str_a, const typename T::value_type *str_b,
128  const typename T::size_type n);
129 
130  extern OCTAVE_API Complex
131  str2double (const std::string& str_arg);
132 
133  extern OCTAVE_API std::string
134  u8_to_encoding (const std::string& who, const std::string& u8_string,
135  const std::string& encoding);
136 
137  extern OCTAVE_API std::string
138  u8_from_encoding (const std::string& who, const std::string& native_string,
139  const std::string& encoding);
140 
142  {
145  };
146 
147  extern OCTAVE_API unsigned int
148  u8_validate (const std::string& who, std::string& in_string,
150  }
151 }
152 
153 template <typename T>
154 extern OCTAVE_API std::string
155 rational_approx (T val, int len);
156 
157 #endif
octave_idx_type n
Definition: mx-inlines.cc:753
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.
Definition: oct-string.cc:156
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.
Definition: oct-string.cc:185
OCTAVE_API std::string u8_to_encoding(const std::string &who, const std::string &u8_string, const std::string &encoding)
Definition: oct-string.cc:495
bool strcmp(const T &str_a, const T &str_b)
True if strings are the same.
Definition: oct-string.cc:122
bool strcmpi(const T &str_a, const T &str_b)
True if strings are the same, ignoring case.
Definition: oct-string.cc:139
OCTAVE_API std::string u8_from_encoding(const std::string &who, const std::string &native_string, const std::string &encoding)
Definition: oct-string.cc:528
OCTAVE_API Complex str2double(const std::string &str_arg)
Definition: oct-string.cc:460
OCTAVE_API unsigned int u8_validate(const std::string &who, std::string &in_string, const u8_fallback_type type=U8_REPLACEMENT_CHAR)
Definition: oct-string.cc:559
std::complex< double > Complex
Definition: oct-cmplx.h:33
OCTAVE_API std::string rational_approx(T val, int len)
Definition: oct-string.cc:612
F77_RET_T len
Definition: xerbla.cc:61