GNU Octave  4.4.1
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 Copyright (C) 2016-2018 CarnĂ« Draug
3 
4 This file is part of Octave.
5 
6 Octave is free software: you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10 
11 Octave is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with Octave; see the file COPYING. If not, see
18 <https://www.gnu.org/licenses/>.
19 
20 */
21 
22 #if ! defined (octave_oct_string_h)
23 #define octave_oct_string_h 1
24 
25 #include "octave-config.h"
26 
27 namespace octave
28 {
29  //! Octave string utility functions.
30  //!
31  //! This functions provide a C++ interface to most string functions
32  //! available in the Octave interpreter.
33  //!
34  //! Specializations for Array may consider its dimensions in addition
35  //! to the actual string contents.
36  //!
37  //! @attention
38  //! Octave's string comparison functions return true when strings are
39  //! are equal, just the opposite of the corresponding C library functions.
40  //! In addition, Octave's function only return bool and do not check
41  //! lexicographical order.
42 
43  namespace string
44  {
45  //! True if strings are the same.
46  //!
47  //! ## Specialization for Array<char>
48  //!
49  //! When comparing whole Array of chars, the actual Array dimensions
50  //! are significant. A column vector and row vector with the same
51  //! char array, will still return false.
52 
53  template <typename T>
54  bool strcmp (const T& str_a, const T& str_b);
55 
56  //! True if string is the same as character sequence.
57  //!
58  //! Compares a string to the null-terminated character sequence
59  //! beginning at the character pointed to by str_b.
60  //!
61  //! ## Specialization for Array<char>
62  //!
63  //! For purposes of comparison of dimensions, the character sequence
64  //! is considered to be a row vector.
65 
66  template <typename T>
67  bool strcmp (const T& str_a, const typename T::value_type *str_b);
68 
69  //! True if strings are the same, ignoring case.
70  //!
71  //! ## Specialization for Array<char>
72  //!
73  //! When comparing whole Array of chars, the actual Array dimensions
74  //! are significant. A column vector and row vector with the same
75  //! char array, will still return false.
76 
77  template <typename T>
78  bool strcmpi (const T& str_a, const T& str_b);
79 
80  //! True if string is the same as character sequence, ignoring case.
81  //!
82  //! ## Specialization for Array<char>
83  //!
84  //! For purposes of comparison of dimensions, the character sequence
85  //! is considered to be a row vector.
86 
87  template <typename T>
88  bool strcmpi (const T& str_a, const typename T::value_type *str_b);
89 
90  //! True if the first N characters are the same.
91  //!
92  //! ## Specialization for Array<char>
93  //!
94  //! The comparison is done in the first N characters, the actual
95  //! dimensions of the Array are irrelevant. A row vector and
96  //! a column vector of the same still return true.
97 
98  template <typename T>
99  bool strncmp (const T& str_a, const T& str_b,
100  const typename T::size_type n);
101 
102  //! True if the first N characters are the same.
103  template <typename T>
104  bool strncmp (const T& str_a, const typename T::value_type *str_b,
105  const typename T::size_type n);
106 
107  //! True if the first N characters are the same, ignoring case.
108  //!
109  //! ## Specialization for Array<char>
110  //!
111  //! The comparison is done in the first N characters, the actual
112  //! dimensions of the Array are irrelevant. A row vector and
113  //! a column vector of the same still return true.
114 
115  template <typename T>
116  bool strncmpi (const T& str_a, const T& str_b,
117  const typename T::size_type n);
118 
119  //! True if the first N characters are the same, ignoring case.
120  template <typename T>
121  bool strncmpi (const T& str_a, const typename T::value_type *str_b,
122  const typename T::size_type n);
123  }
124 }
125 
126 #endif
bool strcmp(const T &str_a, const T &str_b)
True if strings are the same.
Definition: oct-string.cc:112
bool strcmpi(const T &str_a, const T &str_b)
True if strings are the same, ignoring case.
Definition: oct-string.cc:129
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:146
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:165
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
Definition: utils.cc:888