GNU Octave 7.1.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-2022 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
33namespace 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 OCTAVE_API bool
61 strcmp (const T& str_a, const T& str_b);
62
63 //! True if string is the same as character sequence.
64 //!
65 //! Compares a string to the null-terminated character sequence
66 //! beginning at the character pointed to by str_b.
67 //!
68 //! ## Specialization for Array<char>
69 //!
70 //! For purposes of comparison of dimensions, the character sequence
71 //! is considered to be a row vector.
72
73 template <typename T>
74 OCTAVE_API bool
75 strcmp (const T& str_a, const typename T::value_type *str_b);
76
77 //! True if strings are the same, ignoring case.
78 //!
79 //! ## Specialization for Array<char>
80 //!
81 //! When comparing whole Array of chars, the actual Array dimensions
82 //! are significant. A column vector and row vector with the same
83 //! char array, will still return false.
84
85 template <typename T>
86 OCTAVE_API bool
87 strcmpi (const T& str_a, const T& str_b);
88
89 //! True if string is the same as character sequence, ignoring case.
90 //!
91 //! ## Specialization for Array<char>
92 //!
93 //! For purposes of comparison of dimensions, the character sequence
94 //! is considered to be a row vector.
95
96 template <typename T>
97 OCTAVE_API bool
98 strcmpi (const T& str_a, const typename T::value_type *str_b);
99
100 //! True if the first N characters are the same.
101 //!
102 //! ## Specialization for Array<char>
103 //!
104 //! The comparison is done in the first N characters, the actual
105 //! dimensions of the Array are irrelevant. A row vector and
106 //! a column vector of the same still return true.
107
108 template <typename T>
109 OCTAVE_API bool
110 strncmp (const T& str_a, const T& str_b,
111 const typename T::size_type n);
112
113 //! True if the first N characters are the same.
114 template <typename T>
115 OCTAVE_API bool
116 strncmp (const T& str_a, const typename T::value_type *str_b,
117 const typename T::size_type n);
118
119 //! True if the first N characters are the same, ignoring case.
120 //!
121 //! ## Specialization for Array<char>
122 //!
123 //! The comparison is done in the first N characters, the actual
124 //! dimensions of the Array are irrelevant. A row vector and
125 //! a column vector of the same still return true.
126
127 template <typename T>
128 OCTAVE_API bool
129 strncmpi (const T& str_a, const T& str_b,
130 const typename T::size_type n);
131
132 //! True if the first N characters are the same, ignoring case.
133 template <typename T>
134 OCTAVE_API bool
135 strncmpi (const T& str_a, const typename T::value_type *str_b,
136 const typename T::size_type n);
137
138 extern OCTAVE_API Complex
139 str2double (const std::string& str_arg);
140
141 extern OCTAVE_API std::string
142 u8_to_encoding (const std::string& who, const std::string& u8_string,
143 const std::string& encoding);
144
145 extern OCTAVE_API std::string
146 u8_from_encoding (const std::string& who, const std::string& native_string,
147 const std::string& encoding);
148
150 {
153 };
154
155 extern OCTAVE_API unsigned int
156 u8_validate (const std::string& who, std::string& in_string,
158 }
159}
160
161template <typename T>
162extern OCTAVE_API std::string
163rational_approx (T val, int len);
164
165#endif
#define OCTAVE_API
Definition: main.in.cc:55
OCTAVE_API std::string u8_to_encoding(const std::string &who, const std::string &u8_string, const std::string &encoding)
Definition: oct-string.cc:497
OCTAVE_API std::string u8_from_encoding(const std::string &who, const std::string &native_string, const std::string &encoding)
Definition: oct-string.cc:529
OCTAVE_API Complex str2double(const std::string &str_arg)
Definition: oct-string.cc:462
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 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
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.
OCTAVE_API bool strcmp(const T &str_a, const T &str_b)
True if strings are the same.
OCTAVE_API bool strcmpi(const T &str_a, const T &str_b)
True if strings are the same, ignoring case.
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