JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
jkqtpstringtools.h
1/*
2 Copyright (c) 2008-2024 Jan W. Krieger (<jan@jkrieger.de>)
3
4
5
6 This software is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser 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 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20
21
22#ifndef JKQTPSTRINGTOOLS_H_INCLUDED
23#define JKQTPSTRINGTOOLS_H_INCLUDED
24#include "jkqtcommon/jkqtcommon_imexport.h"
25#include <QString>
26#include <QLocale>
27#include <string>
28#include <QtGlobal>
29#include <limits>
30
31class QGradient; // forward
32
33/** \brief converts a QT::PenStyle into a string
34 * \ingroup jkqtptools_string
35 */
37
38/** \brief converts a QString into a Qt::PenStyle
39 * \ingroup jkqtptools_string
40 */
41JKQTCOMMON_LIB_EXPORT Qt::PenStyle jkqtp_String2QPenStyle(const QString& style);
42
43/** \brief converts a Qt::BrushStyle into a string
44 * \ingroup jkqtptools_string
45 */
46JKQTCOMMON_LIB_EXPORT QString jkqtp_QBrushStyle2String(Qt::BrushStyle style);
47
48/** \brief converts a QString into a Qt::BrushStyle
49 * \ingroup jkqtptools_string
50 * \see jkqtp_String2QBrushStyleExt() for a more complex parser
51 */
52JKQTCOMMON_LIB_EXPORT Qt::BrushStyle jkqtp_String2QBrushStyle(const QString& style);
53
54/** \brief converts a QString into a Qt::BrushStyle. commpared to jkqtp_String2QBrushStyle(), this method can parse
55 * more complex pattern/brush descriptions, such as for colors, gradients or images, which are output in \a color, \a gradient and \a image
56 * \ingroup jkqtptools_string
57 *
58 * \param style the string to be parsed
59 * \param[out] gradient output parameter for a parsed gradient
60 * \param[out] image output parameter for a parsed image
61 *
62 * \see jkqtp_String2QBrushStyle()
63 */
64JKQTCOMMON_LIB_EXPORT Qt::BrushStyle jkqtp_String2QBrushStyleExt(const QString& style, QGradient* gradient=nullptr, QPixmap* image=nullptr);
65
66
67/** \brief converts a Unicode codepoint into a UTF8-sequence
68 * \ingroup jkqtptools_string
69 *
70 * \see https://stackoverflow.com/questions/19968705/unsigned-integer-as-utf-8-value
71 */
72JKQTCOMMON_LIB_EXPORT std::string jkqtp_UnicodeToUTF8(uint32_t codepoint);
73
74/** \copydoc jkqtp_UnicodeToUTF8() */
75inline QString jkqtp_UnicodeToUTF8Q(uint32_t codepoint) {
76 return QString::fromStdString(jkqtp_UnicodeToUTF8(codepoint));
77}
78
79/** \brief convert a double to a string, using the loacle "C"
80 * \ingroup jkqtptools_string
81 */
82inline QString JKQTPCDoubleToQString(double value) {
83 QLocale loc=QLocale::c();
84 loc.setNumberOptions(QLocale::OmitGroupSeparator);
85 return loc.toString(value, 'g', 18);
86}
87
88/** \brief convert a double to a string
89 * \ingroup jkqtptools_string
90 */
91inline QString JKQTPDoubleToQString(double value, int prec = 10, char f = 'g', QChar decimalSeparator='.') {
92 QLocale loc=QLocale::c();
93 loc.setNumberOptions(QLocale::OmitGroupSeparator);
94 QString res=loc.toString(value, f, prec);
95 if (loc.decimalPoint()!=decimalSeparator) {
96 res=res.replace(loc.decimalPoint(), decimalSeparator);
97 }
98 return res;
99}
100
101
102/** \brief convert a double to a string
103 * \ingroup jkqtptools_string
104 */
105inline QString& JKQTPExtendString(QString& s, const QString& separator, const QString& extension) {
106 if (s.size()>0) s+=separator;
107 s+=extension;
108 return s;
109}
110
111/** \brief convert a string to lower-case characters
112 * \ingroup jkqtptools_string
113 */
114JKQTCOMMON_LIB_EXPORT std::string jkqtp_tolower(const std::string& s);
115
116/** \brief convert a string to a boolean
117 * \ingroup jkqtptools_string
118 */
119JKQTCOMMON_LIB_EXPORT bool jkqtp_strtobool(const std::string& data);
120/** \brief convert a string to upper-case
121 * \ingroup jkqtptools_string
122 */
123JKQTCOMMON_LIB_EXPORT std::string jkqtp_toupper(const std::string& s);
124
125/** \brief std::string wrapper around sprintf()
126 * \ingroup jkqtptools_string
127 */
128template <class T1>
129inline std::string jkqtp_format(const std::string& templ, T1 d1) {
130 char buffer[4096];
131 snprintf(buffer, 4096, templ.c_str(), d1);
132 return std::string(buffer);
133};
134
135/** \brief std::string wrapper around sprintf()
136 * \ingroup jkqtptools_string
137 */
138template <class T1, class T2>
139inline std::string jkqtp_format(const std::string& templ, T1 d1, T2 d2) {
140 char buffer[4096];
141 snprintf(buffer, 4096, templ.c_str(), d1, d2);
142 return std::string(buffer);
143};
144
145/** \brief std::string wrapper around sprintf()
146 * \ingroup jkqtptools_string
147 */
148template <class T1, class T2, class T3>
149inline std::string jkqtp_format(const std::string& templ, T1 d1, T2 d2, T3 d3) {
150 char buffer[4096];
151 snprintf(buffer, 4096, templ.c_str(), d1, d2, d3);
152 return std::string(buffer);
153};
154
155/** \brief std::string wrapper around sprintf()
156 * \ingroup jkqtptools_string
157 */
158template <class T1, class T2, class T3, class T4>
159inline std::string jkqtp_format(const std::string& templ, T1 d1, T2 d2, T3 d3, T4 d4) {
160 char buffer[4096];
161 snprintf(buffer, 4096, templ.c_str(), d1, d2, d3, d4);
162 return std::string(buffer);
163};
164
165/** \brief convert a number of bytes to a string, formatting e.g. 1024 as 1kB, ...
166 * \ingroup jkqtptools_string
167 */
168JKQTCOMMON_LIB_EXPORT std::string jkqtp_bytestostr(double bytes);
169
170/** \brief convert an integer to a string
171 * \ingroup jkqtptools_string
172 */
174
175/** \brief convert an integer to a hex string
176 * \ingroup jkqtptools_string
177 */
179
180/** \brief convert an unsigned int to a string
181 * \ingroup jkqtptools_string
182 */
183JKQTCOMMON_LIB_EXPORT std::string jkqtp_uinttostr(unsigned long data);
184
185/** \brief convert a double to a string
186 * \ingroup jkqtptools_string
187 */
188JKQTCOMMON_LIB_EXPORT std::string jkqtp_floattostr(double data, int past_comma=-1, bool remove_trail0=false, double belowIsZero=1e-16);
189
190/** \brief convert a float to a string using \a format (\c f|e|E|g|G ) with given number of decimals after comma \a past_comma and optional removal of trailing zeros behind decimal separator \a remove_trail0. Uses given QLocal \a loc .
191 * \ingroup jkqtptools_string
192 */
193JKQTCOMMON_LIB_EXPORT QString jkqtp_floattoqstr(const QLocale & loc, double data, char format='f', int past_comma=-1, bool remove_trail0=false);
194
195/** \brief convert a float to a string using \a format (\c f|e|E|g|G ) with given number of decimals after comma \a past_comma and optional removal of trailing zeros behind decimal separator \a remove_trail0. Uses system local, disables not use Group-Separator
196 * \ingroup jkqtptools_string
197 */
198JKQTCOMMON_LIB_EXPORT QString jkqtp_floattoqstr(double data, char format='f', int past_comma=-1, bool remove_trail0=false);
199
200/** \brief convert a boolean to a string
201 * \ingroup jkqtptools_string
202 */
204/** \brief converts a RGBA color into a string
205 * \ingroup jkqtptools_string
206 *
207 * This returns a QString which contains the name of named colors and the RGBA values in a QT readable form othertwise.
208 *
209 * \param r red value of the color to convert
210 * \param g green value of the color to convert
211 * \param b blue value of the color to convert
212 * \param a alpha value of the color to convert
213 * \param useSpecialTransparencySyntax is set (\c true ), the function uses a special syntax to denote color and transparency: \c color,trans
214 */
215JKQTCOMMON_LIB_EXPORT QString jkqtp_rgbtostring(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255, bool useSpecialTransparencySyntax=true);
216
217/** \brief list the (machine-readable) names of all predefined colors
218 * \ingroup jkqtptools_string
219 *
220 */
222/** \brief converts a QColor into a string using the jkqtp_rgbtostring() method.
223 * \ingroup jkqtptools_string
224 *
225 * This returns a QString which contains the name of named colors and the RGBA values in a QT readable form othertwise.
226 */
227JKQTCOMMON_LIB_EXPORT QString jkqtp_QColor2String(QColor color, bool useSpecialTransparencySyntax=true);
228
229/** \brief converts a QString into a QColor, does not support the ,alpha%-notation, use jkqtp_String2QColor() for a full conversion!
230 * \ingroup jkqtptools_string
231 *
232 * This returns a QString which contains the name of named colors and the RGBA values in a QT readable form othertwise.
233 *
234 * \param color the color name to convert
235 * \param namesOnly if \c true , the function only compares against the list of CSS colors; otherwise it passes the string also on to QColor()-constructor, which interprets e.g. \c #AABBCC
236 * \param[out] nameFound optional return value that signifies whether a name was found
237 */
238JKQTCOMMON_LIB_EXPORT QColor jkqtp_lookupQColorName(const QString& color, bool namesOnly=false, bool* nameFound=nullptr);
239
240/** \brief converts a QString into a QColor, compatible with jkqtp_QColor2String(QColor color);
241 * \ingroup jkqtptools_string
242 *
243 * This function converts a color name to a QColor. It extends the names by the following optional synatxes (basically the CSS-syntax with even more options):
244 * - This function allows to add the alpha-value as \c "<color_name>,<alpha>" as integer betwee 0 and 255
245 * or as \c "<color_name>,<transparency_percent>%" in the range of 0..100 % (i.e. (1-transparency_percent/100)*255).
246 * - Also \c "<color_name>,a<alpha_percent>%" in the range of 0..100 % (i.e. alpha_percent/100*255).
247 * - \c "gray<percent>" in the range of 0..100 generates a gray value with 0%=black and 100%=white. Also works for "blue"|"green"|"red"|...
248 * - You can use full CSS-color syntax with functions \c "rgb(R,G,B)" , \c "rgba(...)" , \c "hsl(...)" , \c "hsv(...)" , \c "gray(...)" , \c "green(...)" , \c "red(...)" , \c "blue(...)".
249 * The function also support %-values as parameters and whitespace, comma or slash as value separatos!
250 * - Finally the default Qt color definitions are supported, i.e. \c #RGB , \c #RRGGBB , \c #AARRGGBB , \c #RRRGGGBBB , \c #RRRRGGGGBBBB
251 * .
252 *
253 *
254 */
256
257/** \brief clean a string to be usable as a variable name, e.g. in an expression parser, or a C++-expression
258 * \ingroup jkqtptools_string
259 */
260JKQTCOMMON_LIB_EXPORT std::string jkqtp_to_valid_variable_name(const std::string& input);
261
262/** \brief convert a double to a string, encoding powers of ten as characters, e.g. \c jkqtp_floattounitstr(1000) will result in "1k"
263 * \ingroup jkqtptools_string
264 */
265JKQTCOMMON_LIB_EXPORT std::string jkqtp_floattounitstr(double data, int past_comma=5, bool remove_trail0=false, double belowIsZero=std::numeric_limits<double>::min()*4);
266/** \brief convert a double to a LaTeX-encoded string, encoding powers of ten as characters, e.g. \c jkqtp_floattounitstr(1000) will result in "1k"
267 * \ingroup jkqtptools_string
268 */
269JKQTCOMMON_LIB_EXPORT std::string jkqtp_floattolatexunitstr(double data, int past_comma=5, bool remove_trail0=false, double belowIsZero=std::numeric_limits<double>::min()*4);
270/** \brief convert a double to a string, encoding powers of ten as exponent in LaTeX notation (e.g. <code>-1.23\\cdot 10^{-5}</code>)
271 * \ingroup jkqtptools_string
272 */
273JKQTCOMMON_LIB_EXPORT std::string jkqtp_floattolatexstr(double data, int past_comma=5, bool remove_trail0=false, double belowIsZero=1e-16, double minNoExponent=1e-3, double maxNoExponent=1e4, bool ensurePlusMinus=false, const std::string& multOperator="\\times");
274/** \brief convert a double to a string, encoding powers of ten as exponent with HTML tags
275 * \ingroup jkqtptools_string
276 */
277JKQTCOMMON_LIB_EXPORT std::string jkqtp_floattohtmlstr(double data, int past_comma=5, bool remove_trail0=false, double belowIsZero=1e-16, double minNoExponent=1e-3, double maxNoExponent=1e4);
278
279/** \brief convert a double to a string, encoding powers of ten as characters, e.g. \c jkqtp_floattounitstr(1000) will result in "1k"
280 * \ingroup jkqtptools_string
281 */
282JKQTCOMMON_LIB_EXPORT QString jkqtp_floattounitqstr(double data, int past_comma=5, bool remove_trail0=false);
283/** \brief convert a double to a string, encoding powers of ten as exponent in LaTeX notation (e.g. <code>-1.23\\cdot 10^{-5}</code>)
284 * \ingroup jkqtptools_string
285 */
286JKQTCOMMON_LIB_EXPORT QString jkqtp_floattolatexqstr(double data, int past_comma=5, bool remove_trail0=false, double belowIsZero=1e-16, double minNoExponent=1e-3, double maxNoExponent=1e4, bool ensurePlusMinus=false);
287/** \brief convert a double to a string, encoding powers of ten as exponent with HTML tags
288 * \ingroup jkqtptools_string
289 */
290JKQTCOMMON_LIB_EXPORT QString jkqtp_floattohtmlqstr(double data, int past_comma=5, bool remove_trail0=false, double belowIsZero=1e-16, double minNoExponent=1e-3, double maxNoExponent=1e4);
291/** \brief convert a double to a LaTeX-encoded string, encoding powers of ten as characters, e.g. \c jkqtp_floattounitqstr(1000) will result in "1k"
292 * \ingroup jkqtptools_string
293 */
294JKQTCOMMON_LIB_EXPORT QString jkqtp_floattolatexunitqstr(double data, int past_comma=5, bool remove_trail0=false, double belowIsZero=std::numeric_limits<double>::min()*4);
295
296/** \brief convert a character to a string
297 * \ingroup jkqtptools_string
298 */
300
301/** \brief replace all linebreaks by \c "\\n" , \c "\\r" ...
302 * \ingroup jkqtptools_string
303 */
305
306
307/*! \brief convert a QList<QVariant> to a string
308 \ingroup jkqtptools_string
309
310*/
311JKQTCOMMON_LIB_EXPORT QString jkVariantListToString(const QList<QVariant>& data, const QString& separator=QString(", "));
312
313
314/*! \brief filename-ize a string, i.e. replace every non-number and non-character (and also not <code> _ -</code>) character to \c _
315 \ingroup jkqtptools_string */
316JKQTCOMMON_LIB_EXPORT QString jkqtp_filenameize(const QString& data);
317
318/** \brief create a valid variable name from the string, i.e. a string with only characters and digits and \c '_'. ALso the first character has to be a charcter.
319 * \ingroup jkqtptools_string */
321
322/** \brief convert a <a href="http://doc.qt.io/qt-5/qt.html#KeyboardModifier-enum">Qt::KeyboardModifiers</a> to a <a href="http://doc.qt.io/qt-5/qstring.html">QString</a>
323 * \ingroup jkqtptools_string
324 *
325 * \param modifiers the object to convert
326 * \param useNONE if \c true the function will return \c "NONE" if \c modifiers==Qt::NoMofifiers. Otherwise the function will return an empty string ( jkqtp_String2KeyboardModifiers() can cope with both variants)
327 *
328 * \see jkqtp_String2KeyboardModifiers()
329 */
330JKQTCOMMON_LIB_EXPORT QString jkqtp_KeyboardModifiers2String(Qt::KeyboardModifiers modifiers, bool useNONE=true);
331
332/** \brief convert a <a href="http://doc.qt.io/qt-5/qstring.html">QString</a> (created by jkqtp_KeyboardModifiers2String() ) to <a href="http://doc.qt.io/qt-5/qt.html#KeyboardModifier-enum">Qt::KeyboardModifiers</a>
333 * \ingroup jkqtptools_string
334 *
335 * \see jkqtp_KeyboardModifiers2String()
336 */
337JKQTCOMMON_LIB_EXPORT Qt::KeyboardModifiers jkqtp_String2KeyboardModifiers(const QString& modifiers);
338/** \brief convert a <a href="http://doc.qt.io/qt-5/qt.html#MouseButton-enum">Qt::MouseButton</a> to a <a href="http://doc.qt.io/qt-5/qstring.html">QString</a>
339 * \ingroup jkqtptools_string
340 *
341 * \param button the object to convert
342 * \param useNONE if \c true the function will return \c "NONE" if \c button==Qt::NoButton. Otherwise the function will return an empty string ( jkqtp_String2MouseButton() can cope with both variants)
343 *
344 * \see jkqtp_MouseButton2String()
345 */
346JKQTCOMMON_LIB_EXPORT QString jkqtp_MouseButton2String(Qt::MouseButton button, bool useNONE=true);
347/** \brief convert a <a href="http://doc.qt.io/qt-5/qstring.html">QString</a> (created by jkqtp_MouseButton2String() ) to <a href="http://doc.qt.io/qt-5/qt.html#MouseButton-enum">Qt::MouseButton</a>
348 * \ingroup jkqtptools_string
349 *
350 * \see jkqtp_MouseButton2String()
351 */
352JKQTCOMMON_LIB_EXPORT Qt::MouseButton jkqtp_String2MouseButton(const QString &button);
353
354/** \brief returns \c true, if \a text contains a match to the given regular expression \a regex,
355 * starts from \a offset and optionally returns the match in \a caps \c =[fullmatch, cap1,cap2,...]
356 * \ingroup jkqtptools_string
357 *
358 * \note this function uses an internal cache, so the \a regex does not have
359 * to be compiled every time this is called (with the same \a regex ).
360 *
361 * \see jkqtp_rxExactlyMatches(), jkqtp_rxIndexIn(), jkqtp_rxContains(), jkqtp_rxPartiallyMatchesAt()
362 */
363JKQTCOMMON_LIB_EXPORT bool jkqtp_rxContains(const QString& text, const QString &regex, size_t offset=0, QStringList* caps=nullptr);
364
365/** \brief returns the next match (i.e. its index) of the given regular expression \a regex within \a text,
366 * starts from \a offset and optionally returns the match in \a caps \c =[fullmatch, cap1,cap2,...]
367 * \ingroup jkqtptools_string
368 *
369 * \note this function uses an internal cache, so the \a regex does not have
370 * to be compiled every time this is called (with the same \a regex ).
371 *
372 * \see jkqtp_rxExactlyMatches(), jkqtp_rxIndexIn(), jkqtp_rxContains(), jkqtp_rxPartiallyMatchesAt()
373 */
374JKQTCOMMON_LIB_EXPORT size_t jkqtp_rxIndexIn(const QString& text, const QString &regex, size_t offset=0, QStringList* caps=nullptr);
375
376/** \brief returns \c true, if \a text exactly matches the given regular expression \a regex,
377 * starts from \a offset and optionally returns the match in \a caps \c =[fullmatch, cap1,cap2,...]
378 * \ingroup jkqtptools_string
379 *
380 * \note this function uses an internal cache, so the \a regex does not have
381 * to be compiled every time this is called (with the same \a regex ).
382 *
383 * \see jkqtp_rxExactlyMatches(), jkqtp_rxIndexIn(), jkqtp_rxContains(), jkqtp_rxPartiallyMatchesAt()
384 */
385JKQTCOMMON_LIB_EXPORT bool jkqtp_rxExactlyMatches(const QString& text, const QString &regex, QStringList* caps=nullptr);
386
387
388/** \brief returns \c true, if \a text partially matches the given regular expression \a regex,
389 * starting from \a offset (and the match starts at \a offset !!!)
390 * and optionally returns the match in \a caps \c =[fullmatch, cap1,cap2,...]
391 * \ingroup jkqtptools_string
392 *
393 * \note this function uses an internal cache, so the \a regex does not have
394 * to be compiled every time this is called (with the same \a regex ).
395 *
396 * \see jkqtp_rxExactlyMatches(), jkqtp_rxIndexIn(), jkqtp_rxContains(), jkqtp_rxPartiallyMatchesAt()
397 */
398JKQTCOMMON_LIB_EXPORT bool jkqtp_rxPartiallyMatchesAt(const QString& text, const QString &regex, size_t offset=0, QStringList* caps=nullptr);
399
400
401#endif // JKQTPSTRINGTOOLS_H_INCLUDED
#define JKQTCOMMON_LIB_EXPORT
Definition jkqtcommon_imexport.h:87
JKQTCOMMON_LIB_EXPORT std::string jkqtp_toupper(const std::string &s)
convert a string to upper-case
JKQTCOMMON_LIB_EXPORT QString jkqtp_floattoqstr(const QLocale &loc, double data, char format='f', int past_comma=-1, bool remove_trail0=false)
convert a float to a string using format (f|e|E|g|G ) with given number of decimals after comma past_...
JKQTCOMMON_LIB_EXPORT std::string jkqtp_floattolatexstr(double data, int past_comma=5, bool remove_trail0=false, double belowIsZero=1e-16, double minNoExponent=1e-3, double maxNoExponent=1e4, bool ensurePlusMinus=false, const std::string &multOperator="\\times")
convert a double to a string, encoding powers of ten as exponent in LaTeX notation (e....
JKQTCOMMON_LIB_EXPORT std::string jkqtp_inttostr(long data)
convert an integer to a string
JKQTCOMMON_LIB_EXPORT QString jkqtp_backslashEscape(const QString &txt)
replace all linebreaks by "\\n" , "\\r" ...
JKQTCOMMON_LIB_EXPORT QString jkqtp_rgbtostring(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255, bool useSpecialTransparencySyntax=true)
converts a RGBA color into a string
JKQTCOMMON_LIB_EXPORT QString jkqtp_floattohtmlqstr(double data, int past_comma=5, bool remove_trail0=false, double belowIsZero=1e-16, double minNoExponent=1e-3, double maxNoExponent=1e4)
convert a double to a string, encoding powers of ten as exponent with HTML tags
JKQTCOMMON_LIB_EXPORT std::string jkqtp_chartostr(char data)
convert a character to a string
JKQTCOMMON_LIB_EXPORT std::string jkqtp_floattolatexunitstr(double data, int past_comma=5, bool remove_trail0=false, double belowIsZero=std::numeric_limits< double >::min() *4)
convert a double to a LaTeX-encoded string, encoding powers of ten as characters, e....
JKQTCOMMON_LIB_EXPORT QString jkqtp_floattolatexqstr(double data, int past_comma=5, bool remove_trail0=false, double belowIsZero=1e-16, double minNoExponent=1e-3, double maxNoExponent=1e4, bool ensurePlusMinus=false)
convert a double to a string, encoding powers of ten as exponent in LaTeX notation (e....
JKQTCOMMON_LIB_EXPORT QString jkqtp_toValidVariableName(const QString &input)
create a valid variable name from the string, i.e. a string with only characters and digits and '_'....
JKQTCOMMON_LIB_EXPORT std::string jkqtp_uinttostr(unsigned long data)
convert an unsigned int to a string
JKQTCOMMON_LIB_EXPORT QString jkqtp_QPenStyle2String(Qt::PenStyle style)
converts a QT::PenStyle into a string
QString & JKQTPExtendString(QString &s, const QString &separator, const QString &extension)
convert a double to a string
Definition jkqtpstringtools.h:105
JKQTCOMMON_LIB_EXPORT std::string jkqtp_to_valid_variable_name(const std::string &input)
clean a string to be usable as a variable name, e.g. in an expression parser, or a C++-expression
JKQTCOMMON_LIB_EXPORT QString jkqtp_floattounitqstr(double data, int past_comma=5, bool remove_trail0=false)
convert a double to a string, encoding powers of ten as characters, e.g. jkqtp_floattounitstr(1000) w...
JKQTCOMMON_LIB_EXPORT const QStringList & jkqtp_listNamedColors()
list the (machine-readable) names of all predefined colors
JKQTCOMMON_LIB_EXPORT QString jkqtp_floattolatexunitqstr(double data, int past_comma=5, bool remove_trail0=false, double belowIsZero=std::numeric_limits< double >::min() *4)
convert a double to a LaTeX-encoded string, encoding powers of ten as characters, e....
JKQTCOMMON_LIB_EXPORT QString jkqtp_MouseButton2String(Qt::MouseButton button, bool useNONE=true)
convert a Qt::MouseButton to a QString
QString JKQTPCDoubleToQString(double value)
convert a double to a string, using the loacle "C"
Definition jkqtpstringtools.h:82
JKQTCOMMON_LIB_EXPORT Qt::KeyboardModifiers jkqtp_String2KeyboardModifiers(const QString &modifiers)
convert a QString (created by jkqtp_KeyboardModifiers2String() ) to Qt::KeyboardModifiers
JKQTCOMMON_LIB_EXPORT QString jkqtp_filenameize(const QString &data)
filename-ize a string, i.e. replace every non-number and non-character (and also not _ -) character ...
std::string jkqtp_format(const std::string &templ, T1 d1)
std::string wrapper around sprintf()
Definition jkqtpstringtools.h:129
JKQTCOMMON_LIB_EXPORT std::string jkqtp_UnicodeToUTF8(uint32_t codepoint)
converts a Unicode codepoint into a UTF8-sequence
JKQTCOMMON_LIB_EXPORT std::string jkqtp_floattostr(double data, int past_comma=-1, bool remove_trail0=false, double belowIsZero=1e-16)
convert a double to a string
JKQTCOMMON_LIB_EXPORT std::string jkqtp_floattohtmlstr(double data, int past_comma=5, bool remove_trail0=false, double belowIsZero=1e-16, double minNoExponent=1e-3, double maxNoExponent=1e4)
convert a double to a string, encoding powers of ten as exponent with HTML tags
JKQTCOMMON_LIB_EXPORT Qt::PenStyle jkqtp_String2QPenStyle(const QString &style)
converts a QString into a Qt::PenStyle
JKQTCOMMON_LIB_EXPORT bool jkqtp_rxPartiallyMatchesAt(const QString &text, const QString &regex, size_t offset=0, QStringList *caps=nullptr)
returns true, if text partially matches the given regular expression regex, starting from offset (and...
JKQTCOMMON_LIB_EXPORT std::string jkqtp_booltostr(bool data)
convert a boolean to a string
JKQTCOMMON_LIB_EXPORT bool jkqtp_rxExactlyMatches(const QString &text, const QString &regex, QStringList *caps=nullptr)
returns true, if text exactly matches the given regular expression regex, starts from offset and opti...
JKQTCOMMON_LIB_EXPORT size_t jkqtp_rxIndexIn(const QString &text, const QString &regex, size_t offset=0, QStringList *caps=nullptr)
returns the next match (i.e. its index) of the given regular expression regex within text,...
JKQTCOMMON_LIB_EXPORT Qt::BrushStyle jkqtp_String2QBrushStyle(const QString &style)
converts a QString into a Qt::BrushStyle
JKQTCOMMON_LIB_EXPORT std::string jkqtp_floattounitstr(double data, int past_comma=5, bool remove_trail0=false, double belowIsZero=std::numeric_limits< double >::min() *4)
convert a double to a string, encoding powers of ten as characters, e.g. jkqtp_floattounitstr(1000) w...
JKQTCOMMON_LIB_EXPORT Qt::MouseButton jkqtp_String2MouseButton(const QString &button)
convert a QString (created by jkqtp_MouseButton2String() ) to Qt::MouseButton
JKQTCOMMON_LIB_EXPORT bool jkqtp_strtobool(const std::string &data)
convert a string to a boolean
JKQTCOMMON_LIB_EXPORT QColor jkqtp_lookupQColorName(const QString &color, bool namesOnly=false, bool *nameFound=nullptr)
converts a QString into a QColor, does not support the ,alpha%-notation, use jkqtp_String2QColor() fo...
JKQTCOMMON_LIB_EXPORT QString jkqtp_QBrushStyle2String(Qt::BrushStyle style)
converts a Qt::BrushStyle into a string
JKQTCOMMON_LIB_EXPORT std::string jkqtp_bytestostr(double bytes)
convert a number of bytes to a string, formatting e.g. 1024 as 1kB, ...
JKQTCOMMON_LIB_EXPORT std::string jkqtp_tolower(const std::string &s)
convert a string to lower-case characters
JKQTCOMMON_LIB_EXPORT QString jkqtp_KeyboardModifiers2String(Qt::KeyboardModifiers modifiers, bool useNONE=true)
convert a Qt::KeyboardModifiers to a QString
JKQTCOMMON_LIB_EXPORT QString jkqtp_QColor2String(QColor color, bool useSpecialTransparencySyntax=true)
converts a QColor into a string using the jkqtp_rgbtostring() method.
QString JKQTPDoubleToQString(double value, int prec=10, char f='g', QChar decimalSeparator='.')
convert a double to a string
Definition jkqtpstringtools.h:91
JKQTCOMMON_LIB_EXPORT std::string jkqtp_inttohex(long data)
convert an integer to a hex string
JKQTCOMMON_LIB_EXPORT bool jkqtp_rxContains(const QString &text, const QString &regex, size_t offset=0, QStringList *caps=nullptr)
returns true, if text contains a match to the given regular expression regex, starts from offset and ...
JKQTCOMMON_LIB_EXPORT Qt::BrushStyle jkqtp_String2QBrushStyleExt(const QString &style, QGradient *gradient=nullptr, QPixmap *image=nullptr)
converts a QString into a Qt::BrushStyle. commpared to jkqtp_String2QBrushStyle(),...
JKQTCOMMON_LIB_EXPORT QColor jkqtp_String2QColor(QString color)
converts a QString into a QColor, compatible with jkqtp_QColor2String(QColor color);
JKQTCOMMON_LIB_EXPORT QString jkVariantListToString(const QList< QVariant > &data, const QString &separator=QString(", "))
convert a QList<QVariant> to a string