GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1993-2025 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_utils_h)
27#define octave_utils_h 1
28
29#include "octave-config.h"
30
31#include <cstdarg>
32
33#include <iosfwd>
34#include <string>
35#include <list>
36
37#include "dMatrix.h"
38#include "lo-utils.h"
39
40class octave_value;
42class string_vector;
43
45
46extern OCTINTERP_API bool valid_identifier (const char *s);
47extern OCTINTERP_API bool valid_identifier (const std::string& s);
48
49//! Helper class for `make_valid_name` function calls.
50//!
51//! Extracting options separately for multiple (e.g. 1000+) function calls
52//! avoids expensive repetitive parsing of the very same options.
53
54class OCTINTERP_API make_valid_name_options
55{
56public:
57
58 //! Default options for `make_valid_name` function calls.
59 //!
60 //! Calling the constructor without arguments is equivalent to:
61 //!
62 //! @code{.cc}
63 //! make_valid_name_options (ovl ("ReplacementStyle", "underscore",
64 //! "Prefix", "x"));
65 //! @endcode
66
68
69 OCTAVE_DEFAULT_COPY_MOVE_DELETE (make_valid_name_options)
70
71 //! Extract attribute-value-pairs from an octave_value_list of strings.
72 //!
73 //! If attributes occur multiple times, the rightmost pair is chosen.
74 //!
75 //! @code{.cc}
76 //! make_valid_name_options (ovl ("ReplacementStyle", "hex", ...));
77 //! @endcode
78
80
81 //! @return ReplacementStyle, see `help matlab.lang.makeValidName`.
82
83 const std::string&
84 get_replacement_style () const { return m_replacement_style; }
85
86 //! @return Prefix, see `help matlab.lang.makeValidName`.
87
88 const std::string& get_prefix () const { return m_prefix; }
89
90private:
91
92 std::string m_replacement_style{"underscore"};
93 std::string m_prefix{"x"};
94};
95
96//! Modify @p str to be a valid variable name.
97//!
98//! @param str input string
99//! @param options see also `help matlab.lang.makeValidName`.
100//!
101//! @return true, if @p str was modified.
102
103extern OCTINTERP_API bool
104make_valid_name (std::string& str, const make_valid_name_options& options);
105
106OCTAVE_DEPRECATED (9, "octave::same_file is obsolete, use octave::sys::same_file")
107extern OCTINTERP_API bool
108same_file (const std::string& f, const std::string& g);
109
110extern OCTINTERP_API int almost_match (const std::string& std,
111 const std::string& s,
112 int min_match_len = 1,
113 int case_sens = 1);
114
115extern OCTINTERP_API int
116keyword_almost_match (const char *const *std, int *min_len,
117 const std::string& s, int min_toks_to_match,
118 int max_toks);
119
120extern OCTINTERP_API std::string
121search_path_for_file (const std::string&, const string_vector&);
122
123extern OCTINTERP_API string_vector
124search_path_for_all_files (const std::string&, const string_vector&);
125
126extern OCTINTERP_API std::string
127file_in_path (const std::string&, const std::string&);
128
129extern OCTINTERP_API std::string
130find_data_file_in_load_path (const std::string& fcn,
131 const std::string& file,
132 bool require_regular_file = false);
133
134extern OCTINTERP_API std::string contents_file_in_path (const std::string&);
135
136extern OCTINTERP_API std::string fcn_file_in_path (const std::string&);
137
138extern OCTINTERP_API void
139display_file_lines (std::ostream& os, const std::string& file_name, int start, int end, int target_line, const std::string& marker, const std::string& who);
140
141extern OCTINTERP_API std::string do_string_escapes (const std::string& s);
142
143extern OCTINTERP_API const char * undo_string_escape (char c);
144
145extern OCTINTERP_API std::string undo_string_escapes (const std::string& s);
146
147extern OCTINTERP_API void
148check_dimensions (dim_vector& dim, const char *warnfor);
149
150extern OCTINTERP_API void
151get_dimensions (const octave_value& a, const char *warn_for,
152 dim_vector& dim);
153
154extern OCTINTERP_API void
155get_dimensions (const octave_value& a, const octave_value& b,
156 const char *warn_for, octave_idx_type& nr,
157 octave_idx_type& nc);
158
159extern OCTINTERP_API void
160get_dimensions (const octave_value& a, const char *warn_for,
162
163extern OCTINTERP_API octave_idx_type
164dims_to_numel (const dim_vector& dims, const octave_value_list& idx);
165
166extern OCTINTERP_API Matrix
168
169extern OCTINTERP_API FloatMatrix
171
172extern OCTINTERP_API std::size_t
173format (std::ostream& os, const char *fmt, ...);
174
175extern OCTINTERP_API std::size_t
176vformat (std::ostream& os, const char *fmt, va_list args);
177
178extern OCTINTERP_API std::string
179vasprintf (const char *fmt, va_list args);
180
181extern OCTINTERP_API std::string asprintf (const char *fmt, ...);
182
183extern OCTINTERP_API void sleep (double seconds,
184 bool do_graphics_events = false);
185
186extern OCTINTERP_API
189 const char *fcn_name, const octave_value_list& args,
190 int nargout);
191
192extern OCTINTERP_API
195 const char *fcn_name, const octave_value_list& args);
196
197OCTAVE_END_NAMESPACE(octave)
198
199#endif
Vector representing the dimensions (size) of an Array.
Definition dim-vector.h:90
Helper class for make_valid_name function calls.
Definition utils.h:55
const std::string & get_replacement_style() const
Definition utils.h:84
make_valid_name_options()=default
Default options for make_valid_name function calls.
const std::string & get_prefix() const
Definition utils.h:88
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
F77_RET_T const F77_DBLE const F77_DBLE * f
std::size_t vformat(std::ostream &os, const char *fmt, va_list args)
Definition utils.cc:1529
std::string find_data_file_in_load_path(const std::string &fcn, const std::string &file, bool require_regular_file=false)
Definition utils.cc:711
std::string asprintf(const char *fmt,...)
Definition utils.cc:1557
std::string do_string_escapes(const std::string &s)
Definition utils.cc:838
octave_idx_type dims_to_numel(const dim_vector &dims, const octave_value_list &idx)
Definition utils.cc:1442
std::string undo_string_escapes(const std::string &s)
Definition utils.cc:1065
int almost_match(const std::string &std, const std::string &s, int min_match_len=1, int case_sens=1)
Definition utils.cc:412
std::string file_in_path(const std::string &, const std::string &)
Definition utils.cc:698
string_vector search_path_for_all_files(const std::string &, const string_vector &)
Definition utils.cc:528
std::string contents_file_in_path(const std::string &)
Definition utils.cc:788
int keyword_almost_match(const char *const *std, int *min_len, const std::string &s, int min_toks_to_match, int max_toks)
Definition utils.cc:428
std::string search_path_for_file(const std::string &, const string_vector &)
Definition utils.cc:517
Matrix identity_matrix(octave_idx_type nr, octave_idx_type nc)
Definition utils.cc:1482
std::string vasprintf(const char *fmt, va_list args)
Definition utils.cc:1539
void get_dimensions(const octave_value &a, const char *warn_for, dim_vector &dim)
Definition utils.cc:1377
bool valid_identifier(const char *s)
Definition utils.cc:79
FloatMatrix float_identity_matrix(octave_idx_type nr, octave_idx_type nc)
Definition utils.cc:1498
std::size_t format(std::ostream &os, const char *fmt,...)
Definition utils.cc:1514
const char * undo_string_escape(char c)
Definition utils.cc:1020
void display_file_lines(std::ostream &os, const std::string &file_name, int start, int end, int target_line, const std::string &marker, const std::string &who)
Definition utils.cc:807
bool make_valid_name(std::string &str, const make_valid_name_options &options)
Modify str to be a valid variable name.
Definition utils.cc:137
std::string fcn_file_in_path(const std::string &)
Definition utils.cc:749
void sleep(double seconds, bool do_graphics_events=false)
Definition utils.cc:1577
void check_dimensions(dim_vector &dim, const char *warnfor)
Definition utils.cc:1358
octave_value_list do_simple_cellfun(octave_value_list(*fcn)(const octave_value_list &, int), const char *fcn_name, const octave_value_list &args, int nargout)
Definition utils.cc:1708
bool same_file(const std::string &f, const std::string &g)
Definition lo-sysdep.cc:437