HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
strutil.h
Go to the documentation of this file.
1 // Copyright 2008-present Contributors to the OpenImageIO project.
2 // SPDX-License-Identifier: BSD-3-Clause
3 // https://github.com/OpenImageIO/oiio
4 
5 // clang-format off
6 
7 /////////////////////////////////////////////////////////////////////////
8 /// @file strutil.h
9 ///
10 /// @brief String-related utilities, all in namespace Strutil.
11 /////////////////////////////////////////////////////////////////////////
12 
13 
14 
15 #pragma once
16 
17 #include <cstdio>
18 #include <map>
19 #include <sstream>
20 #include <string>
21 #include <vector>
22 
23 #include <OpenImageIO/export.h>
24 #include <OpenImageIO/hash.h>
26 #include <OpenImageIO/platform.h>
28 
29 #include <OpenImageIO/detail/fmt.h>
31 
32 // Allow client software to know if this version of OIIO has Strutil::sprintf
33 #define OIIO_HAS_SPRINTF 1
34 
35 // Allow client software to know (and to determine, by setting this value
36 // before including this header) if this version of OIIO has Strutil::format
37 // behave like sprintf (OIIO_FORMAT_IS_FMT==0) or like python / {fmt} /
38 // C++20ish std::format (OIIO_FORMAT_IS_FMT==1).
39 #ifndef OIIO_FORMAT_IS_FMT
40 # define OIIO_FORMAT_IS_FMT 0
41 #endif
42 
43 // If OIIO_HIDE_FORMAT is defined, mark the old-style format functions as
44 // deprecated. (This is a debugging aid for downstream projects who want to
45 // root out any places where they might be using the old one).
46 #ifdef OIIO_HIDE_FORMAT
47 # define OIIO_FORMAT_DEPRECATED OIIO_DEPRECATED("old style (printf-like) formatting version of this function is deprecated")
48 #else
49 # define OIIO_FORMAT_DEPRECATED
50 #endif
51 
52 // Allow client software to know that at this moment, the fmt-based string
53 // formatting is locale-independent. This was 0 in older versions when fmt
54 // was locale dependent.
55 #define OIIO_FMT_LOCALE_INDEPENDENT 1
56 
57 
58 
60 /// @namespace Strutil
61 ///
62 /// @brief String-related utilities.
63 namespace Strutil {
64 
65 /// Output the string to the file/stream in a synchronized fashion, so that
66 /// buffers are flushed and internal mutex is used to prevent threads from
67 /// clobbering each other -- output strings coming from concurrent threads
68 /// may be interleaved, but each string is "atomic" and will never splice
69 /// each other character-by-character.
70 void OIIO_UTIL_API sync_output (FILE *file, string_view str);
71 void OIIO_UTIL_API sync_output (std::ostream &file, string_view str);
72 
73 
74 /// Construct a std::string in a printf-like fashion. For example:
75 ///
76 /// std::string s = Strutil::sprintf ("blah %d %g", (int)foo, (float)bar);
77 ///
78 /// Uses the fmt library underneath, so it's fully type-safe, and
79 /// works with any types that understand stream output via '<<'.
80 /// The formatting of the string will always use the classic "C" locale
81 /// conventions (in particular, '.' as decimal separator for float values).
82 #ifdef OIIO_DOXYGEN
83 template<typename Str, typename... Args>
84 inline std::string sprintf(const Str& fmt, Args&&... args)
85 {
86  return ::fmt::sprintf(fmt, args...);
87 }
88 #else
90 #endif
91 
92 
93 
94 /// format() constructs formatted strings. Note that this is in transition!
95 ///
96 /// Strutil::old::format() uses printf conventions and matches format() used
97 /// in OIIO 1.x. It is equivalent to Strutil::sprintf().
98 ///
99 /// std::string s = Strutil::old::sprintf ("blah %d %g", (int)foo, (float)bar);
100 ///
101 /// Strutil::fmt::format() uses "Python" conventions, in the style of string
102 /// formatting used by C++20 std::format and implemented today in the {fmt}
103 /// package (https://github.com/fmtlib/fmt). For example:
104 ///
105 /// std::string s = Strutil::format ("blah {} {}", (int)foo, (float)bar);
106 ///
107 /// Straight-up Strutil::format is today aliased to old::format for the sake
108 /// of back-compatibility, but will someday be switched to fmt::format.
109 ///
110 /// Recommended strategy for users:
111 /// * If you want printf conventions, switch to Strutil::sprintf().
112 /// * If you want to use the python conventions prior to the big switch,
113 /// use Strutil::fmt::format() explicitly (but see the caveat below).
114 /// * Use of unspecified Strutil::format() is, for back compatibility,
115 /// currently equivalent to sprintf, but beware that some point it will
116 /// switch to the future-standard formatting rules.
117 ///
118 
119 namespace fmt {
120 template<typename Str, typename... Args>
121 inline std::string format(const Str& fmt, Args&&... args)
122 {
123 #if FMT_VERSION >= 70000
125 #else
126  return ::fmt::format(fmt, args...);
127 #endif
128 }
129 } // namespace fmt
130 
131 namespace old {
132 template<typename... Args>
134 inline std::string format (const char* fmt, const Args&... args)
135 {
136  return Strutil::sprintf (fmt, args...);
137 }
138 
139 // DEPRECATED(2.0) string_view version. Phasing this out because
140 // std::string_view won't have a c_str() method.
141 template<typename... Args>
143 inline std::string format (string_view fmt, const Args&... args)
144 {
145  return format ({ fmt.data(), fmt.size() }, args...);
146 }
147 } // namespace old
148 
149 
150 // Choose whether Strutil::format is the old or new kind based on
151 // OIIO_FORMAT_IS_FMT.
152 #if OIIO_FORMAT_IS_FMT
153 using fmt::format;
154 #else
155 using old::format;
156 #endif
157 
158 
159 
160 /// Strutil::printf (fmt, ...)
161 /// Strutil::fprintf (FILE*, fmt, ...)
162 /// Strutil::fprintf (ostream& fmt, ...)
163 ///
164 /// Output formatted strings to stdout, a FILE*, or a stream, respectively.
165 /// All use printf-like formatting rules, are type-safe, are thread-safe
166 /// (the outputs are "atomic", at least versus other calls to
167 /// Strutil::*printf), and automatically flush their outputs. They are all
168 /// locale-independent (forcing classic "C" locale).
169 
170 template<typename... Args>
171 inline void printf (const char* fmt, const Args&... args)
172 {
173  sync_output (stdout, Strutil::sprintf(fmt, args...));
174 }
175 
176 template<typename... Args>
177 inline void fprintf (FILE *file, const char* fmt, const Args&... args)
178 {
179  sync_output (file, Strutil::sprintf(fmt, args...));
180 }
181 
182 template<typename... Args>
183 inline void fprintf (std::ostream &file, const char* fmt, const Args&... args)
184 {
185  sync_output (file, Strutil::sprintf(fmt, args...));
186 }
187 
188 
189 
190 /// Strutil::print (fmt, ...)
191 /// Strutil::print (FILE*, fmt, ...)
192 /// Strutil::print (ostream& fmt, ...)
193 ///
194 /// Output formatted strings to stdout, a FILE*, or a stream, respectively.
195 /// All use "Python-like" formatting description (as {fmt} does, and some
196 /// day, std::format), are type-safe, are thread-safe (the outputs are
197 /// "atomic", at least versus other calls to Strutil::*printf), and
198 /// automatically flush their outputs. They are all locale-independent by
199 /// default (use {:n} for locale-aware formatting).
200 
201 template<typename... Args>
202 inline void print (const char* fmt, const Args&... args)
203 {
204  sync_output (stdout, Strutil::fmt::format(fmt, args...));
205 }
206 
207 template<typename... Args>
208 inline void print (FILE *file, const char* fmt, const Args&... args)
209 {
210  sync_output (file, Strutil::fmt::format(fmt, args...));
211 }
212 
213 template<typename... Args>
214 inline void print (std::ostream &file, const char* fmt, const Args&... args)
215 {
216  sync_output (file, Strutil::fmt::format(fmt, args...));
217 }
218 
219 
220 
221 
222 /// Return a std::string formatted from printf-like arguments -- passed
223 /// already as a va_list. This is not guaranteed type-safe and is not
224 /// extensible like format(). Use with caution!
225 std::string OIIO_UTIL_API vsprintf (const char *fmt, va_list ap)
226 #if defined(__GNUC__) && !defined(__CUDACC__)
227  __attribute__ ((format (printf, 1, 0) ))
228 #endif
229  ;
230 
231 /// Return a std::string formatted like Strutil::format, but passed
232 /// already as a va_list. This is not guaranteed type-safe and is not
233 /// extensible like format(). Use with caution!
234 OIIO_DEPRECATED("use `vsprintf` instead")
235 std::string OIIO_UTIL_API vformat (const char *fmt, va_list ap)
236 #if defined(__GNUC__) && !defined(__CUDACC__)
237  __attribute__ ((format (printf, 1, 0) ))
238 #endif
239  ;
240 
241 /// Return a string expressing a number of bytes, in human readable form.
242 /// - memformat(153) -> "153 B"
243 /// - memformat(15300) -> "14.9 KB"
244 /// - memformat(15300000) -> "14.6 MB"
245 /// - memformat(15300000000LL) -> "14.2 GB"
246 std::string OIIO_UTIL_API memformat (long long bytes, int digits=1);
247 
248 /// Return a string expressing an elapsed time, in human readable form.
249 /// e.g. "0:35.2"
250 std::string OIIO_UTIL_API timeintervalformat (double secs, int digits=1);
251 
252 
253 /// Get a map with RESTful arguments extracted from the given string 'str'.
254 /// Add it into the 'result' argument (Warning: the 'result' argument may
255 /// be changed even if 'get_rest_arguments ()' return an error!).
256 /// Return true on success, false on error.
257 /// Acceptable forms:
258 /// - text?arg1=val1&arg2=val2...
259 /// - ?arg1=val1&arg2=val2...
260 /// Everything before question mark will be saved into the 'base' argument.
262  std::map<std::string, std::string> &result);
263 
264 /// Take a string that may have embedded newlines, tabs, etc., and turn
265 /// those characters into escape sequences like `\n`, `\t`, `\v`, `\b`,
266 /// `\r`, `\f`, `\a`, `\\`, `\"`.
268 
269 /// Take a string that has embedded escape sequences (`\\`, `\"`, `\n`,
270 /// etc.) and collapse them into the 'real' characters.
272 
273 /// Word-wrap string `src` to no more than `columns` width, starting with an
274 /// assumed position of `prefix` on the first line and intending by `prefix`
275 /// blanks before all lines other than the first.
276 ///
277 /// Words may be split AT any characters in `sep` or immediately AFTER any
278 /// characters in `presep`. After the break, any extra `sep` characters will
279 /// be deleted.
280 ///
281 /// By illustration,
282 /// wordwrap("0 1 2 3 4 5 6 7 8", 10, 4)
283 /// should return:
284 /// "0 1 2\n 3 4 5\n 6 7 8"
286  int prefix = 0, string_view sep = " ",
287  string_view presep = "");
288 
289 
290 /// Our favorite "string" hash of a length of bytes. Currently, it is just
291 /// a wrapper for an inlined, constexpr (if C++ >= 14), Cuda-safe farmhash.
292 inline OIIO_CONSTEXPR14 size_t
293 strhash (size_t len, const char *s)
294 {
295  return OIIO::farmhash::inlined::Hash(s, len);
296 }
297 
298 
299 /// Hash a string_view. This is OIIO's default favorite string hasher.
300 /// Currently, it uses farmhash, is constexpr (for C++14), and works in
301 /// Cuda. This is rigged, though, so that empty strings hash always hash to
302 /// 0 (that isn't would a raw farmhash would give you, but it's a useful
303 /// property, especially for trivial initialization).
304 inline OIIO_CONSTEXPR14 size_t
306 {
307  return s.length() ? strhash(s.length(), s.data()) : 0;
308 }
309 
310 
311 
312 /// Case-insensitive comparison of strings. For speed, this always uses a
313 /// static locale that doesn't require a mutex. Caveat: the case-sensivive
314 /// `==` of string_view's is about 20x faster than this case-insensitive
315 /// function.
317 
318 /// Case-insensitive ordered comparison of strings. For speed, this always
319 /// uses a static locale that doesn't require a mutex.
321 
322 /// Does 'a' start with the string 'b', with a case-sensitive comparison?
324 
325 /// Does 'a' start with the string 'b', with a case-insensitive comparison?
326 /// For speed, this always uses a static locale that doesn't require a
327 /// mutex. Caveat: the case-sensivive starts_with() is about 20x faster than
328 /// this case-insensitive function.
330 
331 /// Does 'a' end with the string 'b', with a case-sensitive comparison?
333 
334 /// Does 'a' end with the string 'b', with a case-insensitive comparison?
335 /// For speed, this always uses a static locale that doesn't require a
336 /// mutex. Caveat: the case-sensivive ends_with() is about 20x faster than
337 /// this case-insensitive function.
339 
340 /// Return the position of the first occurrence of `b` within `a`, or
341 /// std::npos if not found.
343 
344 /// Return the position of the first occurrence of `b` within `a`, with a
345 /// case-insensitive comparison, or std::npos if not found. Caveat: the
346 /// case-sensivive find() is about 20x faster than this case-insensitive
347 /// function.
349 
350 /// Return the position of the last occurrence of `b` within `a`, or npos if
351 /// not found.
353 
354 /// Return the position of the last occurrence of `b` within `a`, with a
355 /// case-insensitive comparison, or npos if not found. Caveat: the
356 /// case-sensivive rfind() is about 20x faster than this case-insensitive
357 /// function.
359 
360 /// Does 'a' contain the string 'b' within it?
362 
363 /// Does 'a' contain the string 'b' within it, using a case-insensitive
364 /// comparison? Caveat: the case-sensivive contains() is about 20x faster
365 /// than this case-insensitive function.
367 
368 /// Does 'a' contain the string 'b' within it? But start looking at the end!
369 /// This can be a bit faster than contains() if you think that the substring
370 /// `b` will tend to be close to the end of `a`.
372  return rfind(a, b) != string_view::npos;
373 }
374 
375 /// Does 'a' contain the string 'b' within it? But start looking at the end!
376 /// This can be a bit faster than contains() if you think that the substring
377 /// `b` will tend to be close to the end of `a`. Caveat: the case-sensivive
378 /// rcontains() is about 20x faster than this case-insensitive function.
380  return irfind(a, b) != string_view::npos;
381 }
382 
383 /// Does 'a' contain any of the characters within `set`?
385 
386 /// Convert to upper case in place, faster than std::toupper because we use
387 /// a static locale that doesn't require a mutex lock.
389 
390 /// Convert to upper case in place, faster than std::toupper because we use
391 /// a static locale that doesn't require a mutex lock.
393 
394 /// Return an all-upper case version of `a` (locale-independent).
396  std::string result(a);
397  to_lower(result);
398  return result;
399 }
400 
401 /// Return an all-upper case version of `a` (locale-independent).
403  std::string result(a);
404  to_upper(result);
405  return result;
406 }
407 
408 
409 
410 /// Return a reference to the section of str that has all consecutive
411 /// characters in chars removed from the beginning and ending. If chars is
412 /// empty, it will be interpreted as " \t\n\r\f\v" (whitespace).
414 
415 /// Return a reference to the section of str that has all consecutive
416 /// characters in chars removed from the beginning (left side). If chars is
417 /// empty, it will be interpreted as " \t\n\r\f\v" (whitespace).
419 
420 /// Return a reference to the section of str that has all consecutive
421 /// characters in chars removed from the ending (right side). If chars is
422 /// empty, it will be interpreted as " \t\n\r\f\v" (whitespace).
424 
425 
426 /// Fills the "result" list with the words in the string, using sep as
427 /// the delimiter string. If `maxsplit` is > -1, the string will be split
428 /// into at most `maxsplit` pieces (a negative value will impose no
429 /// maximum). If sep is "", any whitespace string is a separator. If the
430 /// source `str` is empty, there will be zero pieces.
431 void OIIO_UTIL_API split (string_view str, std::vector<string_view> &result,
432  string_view sep = string_view(), int maxsplit = -1);
433 void OIIO_UTIL_API split (string_view str, std::vector<std::string> &result,
434  string_view sep = string_view(), int maxsplit = -1);
435 
436 /// Split the contents of `str` using `sep` as the delimiter string. If
437 /// `sep` is "", any whitespace string is a separator. If `maxsplit > -1`,
438 /// at most `maxsplit` split fragments will be produced (for example,
439 /// maxsplit=2 will split at only the first separator, yielding at most two
440 /// fragments). The result is returned as a vector of std::string (for
441 /// `splits()`) or a vector of string_view (for `splitsv()`). If the source
442 /// `str` is empty, there will be zero pieces.
443 OIIO_UTIL_API std::vector<std::string>
444 splits (string_view str, string_view sep = "", int maxsplit = -1);
445 OIIO_UTIL_API std::vector<string_view>
446 splitsv (string_view str, string_view sep = "", int maxsplit = -1);
447 
448 /// Join all the strings in 'seq' into one big string, separated by the
449 /// 'sep' string. The Sequence can be any iterable collection of items that
450 /// are able to convert to string via stream output. Examples include:
451 /// std::vector<string_view>, std::vector<std::string>, std::set<ustring>,
452 /// std::vector<int>, etc.
453 template<class Sequence>
454 std::string join (const Sequence& seq, string_view sep="")
455 {
456  std::ostringstream out;
457  out.imbue(std::locale::classic()); // Force "C" locale
458  bool first = true;
459  for (auto&& s : seq) {
460  if (! first && sep.size())
461  out << sep;
462  out << s;
463  first = false;
464  }
465  return out.str();
466 }
467 
468 /// Join all the strings in 'seq' into one big string, separated by the
469 /// 'sep' string. The Sequence can be any iterable collection of items that
470 /// are able to convert to string via stream output. Examples include:
471 /// std::vector<string_view>, std::vector<std::string>, std::set<ustring>,
472 /// std::vector<int>, etc. Values will be rendered into the string in a
473 /// locale-independent manner (i.e., '.' for decimal in floats). If the
474 /// optional `len` is nonzero, exactly that number of elements will be
475 /// output (truncating or default-value-padding the sequence).
476 template<class Sequence>
477 std::string join (const Sequence& seq, string_view sep /*= ""*/, size_t len)
478 {
480  std::ostringstream out;
481  out.imbue(std::locale::classic()); // Force "C" locale
482  bool first = true;
483  for (auto&& s : seq) {
484  if (! first)
485  out << sep;
486  out << s;
487  first = false;
488  if (len && (--len == 0))
489  break;
490  }
491  while (len--) {
492  if (! first)
493  out << sep;
494  out << E();
495  first = false;
496  }
497  return out.str();
498 }
499 
500 /// Concatenate two strings, returning a std::string, implemented carefully
501 /// to not perform any redundant copies or allocations. This is
502 /// semantically equivalent to `Strutil::sprintf("%s%s", s, t)`, but is
503 /// more efficient.
505 
506 /// Repeat a string formed by concatenating str n times.
508 
509 /// Replace a pattern inside a string and return the result. If global is
510 /// true, replace all instances of the pattern, otherwise just the first.
512  string_view replacement, bool global=false);
513 
514 
515 /// strtod/strtof equivalents that are "locale-independent", always using
516 /// '.' as the decimal separator. This should be preferred for I/O and other
517 /// situations where you want the same standard formatting regardless of
518 /// locale.
519 float OIIO_UTIL_API strtof (const char *nptr, char **endptr = nullptr) noexcept;
520 double OIIO_UTIL_API strtod (const char *nptr, char **endptr = nullptr) noexcept;
521 
522 
523 // stoi() returns the int conversion of text from a string.
524 // No exceptions or errors -- parsing errors just return 0, over/underflow
525 // gets clamped to int range. No locale consideration.
526 OIIO_UTIL_API int stoi (string_view s, size_t* pos=0, int base=10);
527 
528 // stoui() returns the unsigned int conversion of text from a string.
529 // No exceptions or errors -- parsing errors just return 0. Negative
530 // values are cast, overflow is clamped. No locale considerations.
531 OIIO_UTIL_API unsigned int stoui (string_view s, size_t* pos=0, int base=10);
532 
533 /// stof() returns the float conversion of text from several string types.
534 /// No exceptions or errors -- parsing errors just return 0.0. These always
535 /// use '.' for the decimal mark (versus atof and std::strtof, which are
536 /// locale-dependent).
537 OIIO_UTIL_API float stof (string_view s, size_t* pos=0);
538 #define OIIO_STRUTIL_HAS_STOF 1 /* be able to test this */
539 
540 // Temporary fix: allow separate std::string and char* versions, to avoid
541 // string_view allocation on some platforms. This will be deprecated once
542 // we can count on all supported compilers using short string optimization.
543 OIIO_UTIL_API float stof (const std::string& s, size_t* pos=0);
544 OIIO_UTIL_API float stof (const char* s, size_t* pos=0);
545 // N.B. For users of ustring, there's a stof(ustring) defined in ustring.h.
546 
547 OIIO_UTIL_API double stod (string_view s, size_t* pos=0);
548 OIIO_UTIL_API double stod (const std::string& s, size_t* pos=0);
549 OIIO_UTIL_API double stod (const char* s, size_t* pos=0);
550 
551 
552 
553 /// Return true if the string is exactly (other than leading and trailing
554 /// whitespace) a valid int.
556 
557 /// Return true if the string is exactly (other than leading or trailing
558 /// whitespace) a valid float. This operations in a locale-independent
559 /// manner, i.e., it assumes '.' as the decimal mark.
561 
562 
563 
564 // Helper template to convert from generic type to string. Used when you
565 // want stoX but you're in a template. Rigged to use "C" locale.
566 template<typename T>
568  return T(s); // Generic: assume there is an explicit converter
569 }
570 
571 #ifndef OIIO_DOXYGEN
572 // Special case for int
573 template<> inline int from_string<int> (string_view s) {
574  return Strutil::stoi(s);
575 }
576 // Special case for uint
577 template<> inline unsigned int from_string<unsigned int> (string_view s) {
578  return Strutil::stoui(s);
579 }
580 // Special case for float -- note that by using Strutil::strtof, this
581 // always treats '.' as the decimal mark.
582 template<> inline float from_string<float> (string_view s) {
583  return Strutil::stof(s);
584 }
585 // Special case for double -- note that by using Strutil::strtof, this
586 // always treats '.' as the decimal mark.
587 template<> inline double from_string<double> (string_view s) {
588  return Strutil::stod(s);
589 }
590 
591 template<> inline int64_t from_string<int64_t>(string_view s) {
592  // For conversion of string_view to unsigned int, fall back on strtoll.
593  auto r = strtoll(std::string(s).c_str(), nullptr, 10);
594  return static_cast<int64_t>(r);
595 }
596 
597 template<> inline uint64_t from_string<uint64_t>(string_view s) {
598  // For conversion of string_view to unsigned int, fall back on strtoull.
599  auto r = strtoull(std::string(s).c_str(), nullptr, 10);
600  return static_cast<uint64_t>(r);
601 }
602 #endif
603 
604 
605 
606 /// Template function to convert any type to a string. The default
607 /// implementation is just to use sprintf or fmt::to_string. The template
608 /// can be overloaded if there is a better method for particular types.
609 template<typename T>
610 inline std::string to_string (const T& value) {
612 }
613 
614 // Some special pass-through cases
615 inline std::string to_string (const std::string& value) { return value; }
617 inline std::string to_string (const char* value) { return value; }
618 
619 
620 
621 // Helper template to test if a string is a generic type. Used instead of
622 // string_is_X, but when you're inside templated code.
623 template<typename T>
624 inline bool string_is (string_view /*s*/) {
625  return false; // Generic: assume there is an explicit specialization
626 }
627 // Special case for int
628 template <> inline bool string_is<int> (string_view s) {
629  return string_is_int (s);
630 }
631 // Special case for float. Note that by using Strutil::stof, this always
632 // treats '.' as the decimal character.
633 template <> inline bool string_is<float> (string_view s) {
634  return string_is_float (s);
635 }
636 
637 
638 
639 
640 /// Given a string containing values separated by a comma (or optionally
641 /// another separator), extract the individual values, placing them into
642 /// vals[] which is presumed to already contain defaults. If only a single
643 /// value was in the list, replace all elements of vals[] with the value.
644 /// Otherwise, replace them in the same order. A missing value will simply
645 /// not be replaced. Return the number of values found in the list
646 /// (including blank or malformed ones). If the vals vector was empty
647 /// initially, grow it as necessary.
648 ///
649 /// For example, if T=float, suppose initially, vals[] = {0, 1, 2}, then
650 /// "3.14" results in vals[] = {3.14, 3.14, 3.14}
651 /// "3.14,,-2.0" results in vals[] = {3.14, 1, -2.0}
652 ///
653 /// This can work for type T = int, float, or any type for that has
654 /// an explicit constructor from a std::string.
655 template<class T, class Allocator>
656 int extract_from_list_string (std::vector<T, Allocator> &vals,
657  string_view list,
658  string_view sep = ",")
659 {
660  size_t nvals = vals.size();
661  std::vector<string_view> valuestrings;
662  Strutil::split (list, valuestrings, sep);
663  for (size_t i = 0, e = valuestrings.size(); i < e; ++i) {
664  T v = from_string<T> (valuestrings[i]);
665  if (nvals == 0)
666  vals.push_back (v);
667  else if (valuestrings[i].size()) {
668  if (vals.size() > i) // don't replace non-existant entries
669  vals[i] = from_string<T> (valuestrings[i]);
670  }
671  /* Otherwise, empty space between commas, so leave default alone */
672  }
673  if (valuestrings.size() == 1 && nvals > 0) {
674  vals.resize (1);
675  vals.resize (nvals, vals[0]);
676  }
677  return list.size() ? (int) valuestrings.size() : 0;
678 }
679 
680 
681 /// Given a string containing values separated by a comma (or optionally
682 /// another separator), extract the individual values, returning them as a
683 /// std::vector<T>. The vector will be initialized with `nvals` elements
684 /// with default value `val`. If only a single value was in the list,
685 /// replace all elements of vals[] with the value. Otherwise, replace them
686 /// in the same order. A missing value will simply not be replaced and
687 /// will retain the initialized default value. If the string contains more
688 /// then `nvals` values, they will append to grow the vector.
689 ///
690 /// For example, if T=float,
691 /// extract_from_list_string ("", 3, 42.0f)
692 /// --> {42.0, 42.0, 42.0}
693 /// extract_from_list_string ("3.14", 3, 42.0f)
694 /// --> {3.14, 3.14, 3.14}
695 /// extract_from_list_string ("3.14,,-2.0", 3, 42.0f)
696 /// --> {3.14, 42.0, -2.0}
697 /// extract_from_list_string ("1,2,3,4", 3, 42.0f)
698 /// --> {1.0, 2.0, 3.0, 4.0}
699 ///
700 /// This can work for type T = int, float, or any type for that has
701 /// an explicit constructor from a std::string.
702 template<class T>
703 std::vector<T>
704 extract_from_list_string (string_view list, size_t nvals=0, T val=T(),
705  string_view sep = ",")
706 {
707  std::vector<T> vals (nvals, val);
708  extract_from_list_string (vals, list, sep);
709  return vals;
710 }
711 
712 
713 
714 /// Scan a string for date and time information. Return true upon success,
715 /// false if the string did not appear to contain a valid date/time. If, after
716 /// parsing a valid date/time (including out of range values), `str` contains
717 /// more characters after that, it is not considered a failure.
718 ///
719 /// Valid date/time formats include:
720 /// * YYYY-MM-DD HH:MM:SS
721 /// * YYYY:MM:DD HH:MM:SS
722 /// * YYYY/MM/DD HH:MM:SS
723 OIIO_UTIL_API bool
724 scan_datetime(string_view str, int& year, int& month, int& day,
725  int& hour, int& min, int& sec);
726 
727 
728 
729 /// C++ functor wrapper class for using strhash for unordered_map or
730 /// unordered_set. The way this is used, in conjunction with
731 /// StringEqual, to build an efficient hash map for char*'s or
732 /// std::string's is as follows:
733 /// \code
734 /// unordered_map <const char *, Key, Strutil::StringHash, Strutil::StringEqual>
735 /// \endcode
736 class StringHash {
737 public:
738  size_t operator() (string_view s) const {
739  return (size_t)Strutil::strhash(s);
740  }
741 };
742 
743 
744 
745 /// C++ functor for comparing two strings for equality of their characters.
747  bool operator() (const char *a, const char *b) const noexcept { return strcmp (a, b) == 0; }
748  bool operator() (string_view a, string_view b) const noexcept { return a == b; }
749 };
750 
751 
752 /// C++ functor for comparing two strings for equality of their characters
753 /// in a case-insensitive and locale-insensitive way.
755  bool operator() (const char *a, const char *b) const noexcept;
756  bool operator() (string_view a, string_view b) const noexcept { return iequals (a, b); }
757 };
758 
759 
760 /// C++ functor for comparing the ordering of two strings.
762  bool operator() (const char *a, const char *b) const noexcept { return strcmp (a, b) < 0; }
763  bool operator() (string_view a, string_view b) const noexcept { return a < b; }
764 };
765 
766 
767 /// C++ functor for comparing the ordering of two strings in a
768 /// case-insensitive and locale-insensitive way.
770  bool operator() (const char *a, const char *b) const noexcept;
771  bool operator() (string_view a, string_view b) const noexcept { return a < b; }
772 };
773 
774 
775 
776 /// Conversion of normal char-based strings (presumed to be UTF-8 encoding)
777 /// to wide char string, wstring.
778 std::wstring OIIO_UTIL_API utf8_to_utf16 (string_view utf8str) noexcept;
779 
780 /// Conversion from wstring UTF-16 to a UTF-8 std::string. This is the
781 /// standard way to convert from Windows wide character strings used for
782 /// filenames into the UTF-8 strings OIIO expects for filenames when passed to
783 /// functions like ImageInput::open().
784 std::string OIIO_UTIL_API utf16_to_utf8(const std::wstring& utf16str) noexcept;
785 
786 
787 
788 /// Copy at most size characters (including terminating 0 character) from
789 /// src into dst[], filling any remaining characters with 0 values. Returns
790 /// dst. Note that this behavior is identical to strncpy, except that it
791 /// guarantees that there will be a termining 0 character.
792 OIIO_UTIL_API char * safe_strcpy (char *dst, string_view src, size_t size) noexcept;
793 
794 
795 /// Is the character a whitespace character (space, linefeed, tab, carrage
796 /// return)? Note: this is safer than C isspace(), which has undefined
797 /// behavior for negative char values. Also note that it differs from C
798 /// isspace by not detecting form feed or vertical tab, because who cares.
799 inline bool isspace(char c) {
800  return c == ' ' || c == '\n' || c == '\t' || c == '\r';
801 }
802 
803 /// Modify str to trim any leading whitespace (space, tab, linefeed, cr)
804 /// from the front.
805 void OIIO_UTIL_API skip_whitespace (string_view &str) noexcept;
806 
807 /// Modify str to trim any trailing whitespace (space, tab, linefeed, cr)
808 /// from the back.
810 
811 /// Modify str to trim any whitespace (space, tab, linefeed, cr) from both
812 /// the front and back.
813 inline void trim_whitespace (string_view &str) noexcept {
814  skip_whitespace(str);
816 }
817 
818 /// If str's first character is c (or first non-whitespace char is c, if
819 /// skip_whitespace is true), return true and additionally modify str to
820 /// skip over that first character if eat is also true. Otherwise, if str
821 /// does not begin with character c, return false and don't modify str.
822 bool OIIO_UTIL_API parse_char (string_view &str, char c,
823  bool skip_whitespace = true, bool eat=true) noexcept;
824 
825 /// Modify str to trim all characters up to (but not including) the first
826 /// occurrence of c, and return true if c was found or false if the whole
827 /// string was trimmed without ever finding c. But if eat is false, then
828 /// don't modify str, just return true if any c is found, false if no c
829 /// is found.
830 bool OIIO_UTIL_API parse_until_char (string_view &str, char c, bool eat=true) noexcept;
831 
832 /// If str's first non-whitespace characters are the prefix, return true and
833 /// additionally modify str to skip over that prefix if eat is also true.
834 /// Otherwise, if str doesn't start with optional whitespace and the prefix,
835 /// return false and don't modify str.
836 bool OIIO_UTIL_API parse_prefix (string_view &str, string_view prefix, bool eat=true) noexcept;
837 
838 /// If str's first non-whitespace characters form a valid integer, return
839 /// true, place the integer's value in val, and additionally modify str to
840 /// skip over the parsed integer if eat is also true. Otherwise, if no
841 /// integer is found at the beginning of str, return false and don't modify
842 /// val or str.
843 bool OIIO_UTIL_API parse_int (string_view &str, int &val, bool eat=true) noexcept;
844 
845 /// If str's first non-whitespace characters form a valid float, return
846 /// true, place the float's value in val, and additionally modify str to
847 /// skip over the parsed float if eat is also true. Otherwise, if no float
848 /// is found at the beginning of str, return false and don't modify val or
849 /// str.
850 bool OIIO_UTIL_API parse_float (string_view &str, float &val, bool eat=true) noexcept;
851 
852 /// Synonym for parse_int
853 inline bool parse_value(string_view &str, float &val, bool eat=true) noexcept
854 {
855  return parse_float(str, val, eat);
856 }
857 
858 /// Synonym for parse_float
859 inline bool parse_value(string_view &str, int &val, bool eat=true) noexcept
860 {
861  return parse_int(str, val, eat);
862 }
863 
864 /// Parse from `str`: a `prefix`, a series of int values separated by the
865 /// `sep` string, and a `postfix`, placing the values in the elements of
866 /// mutable span `values`, where the span length indicates the number of
867 /// values to read. Any of the prefix, separator, or postfix may be empty
868 /// strings. If `eat` is true and the parse was successful, `str` will be
869 /// updated in place to trim everything that was parsed, but if any part of
870 /// the parse failed, `str` will not be altered from its original state.
871 bool OIIO_UTIL_API
873  string_view sep = "", string_view postfix = "",
874  bool eat = true) noexcept;
875 /// parse_values for int.
876 bool OIIO_UTIL_API
877 parse_values(string_view& str, string_view prefix, span<float> values,
878  string_view sep = "", string_view postfix = "",
879  bool eat = true) noexcept;
880 
881 /// Similar to parse_values, but with no option to "eat" from
882 /// or modify the source string.
883 inline bool
884 scan_values(string_view str, string_view prefix, span<int> values,
885  string_view sep = "", string_view postfix = "") noexcept
886 {
887  string_view sv(str);
888  return parse_values(sv, prefix, values, sep, postfix);
889 }
890 
891 inline bool
893  string_view sep = "", string_view postfix = "") noexcept
894 {
895  string_view sv(str);
896  return parse_values(sv, prefix, values, sep, postfix);
897 }
898 
900 /// If str's first non-whitespace characters form a valid string (either a
901 /// single word separated by whitespace or anything inside a double-quoted
902 /// ("") or single-quoted ('') string, return true, place the string's value
903 /// (not including surrounding double quotes) in val, and additionally
904 /// modify str to skip over the parsed string if eat is also true.
905 /// Otherwise, if no string is found at the beginning of str, return false
906 /// and don't modify val or str. If keep_quotes is true, the surrounding
907 /// double quotes (if present) will be kept in val.
908 bool OIIO_UTIL_API parse_string (string_view &str, string_view &val, bool eat=true,
909  QuoteBehavior keep_quotes=DeleteQuotes) noexcept;
910 
911 /// Return the first "word" (set of contiguous alphabetical characters) in
912 /// str, and additionally modify str to skip over the parsed word if eat is
913 /// also true. Otherwise, if no word is found at the beginning of str,
914 /// return an empty string_view and don't modify str.
915 string_view OIIO_UTIL_API parse_word (string_view &str, bool eat=true) noexcept;
916 
917 /// If str's first non-whitespace characters form a valid C-like identifier,
918 /// return the identifier, and additionally modify str to skip over the
919 /// parsed identifier if eat is also true. Otherwise, if no identifier is
920 /// found at the beginning of str, return an empty string_view and don't
921 /// modify str.
922 string_view OIIO_UTIL_API parse_identifier (string_view &str, bool eat=true) noexcept;
923 
924 /// If str's first non-whitespace characters form a valid C-like identifier,
925 /// return the identifier, and additionally modify str to skip over the
926 /// parsed identifier if eat is also true. Otherwise, if no identifier is
927 /// found at the beginning of str, return an empty string_view and don't
928 /// modify str. The 'allowed' parameter may specify a additional characters
929 /// accepted that would not ordinarily be allowed in C identifiers, for
930 /// example, parse_identifier (blah, "$:") would allow "identifiers"
931 /// containing dollar signs and colons as well as the usual alphanumeric and
932 /// underscore characters.
934  string_view allowed, bool eat = true) noexcept;
935 
936 /// If the C-like identifier at the head of str exactly matches id,
937 /// return true, and also advance str if eat is true. If it is not a match
938 /// for id, return false and do not alter str.
940  bool eat=true) noexcept;
941 
942 /// Return the longest prefix of `str` that does not contain any characters
943 /// found in `set` (which defaults to the set of common whitespace
944 /// characters). If `eat` is true, then `str` will be modified to trim off
945 /// this returned prefix (but not the separator character).
947  string_view set=" \t\r\n", bool eat=true) noexcept;
948 
949 /// Return the longest prefix of `str` that contain only characters found in
950 /// `set`. If `eat` is true, then `str` will be modified to trim off this
951 /// returned prefix.
953  string_view set, bool eat=true) noexcept;
954 
955 /// Return the prefix of str up to and including the first newline ('\n')
956 /// character, or all of str if no newline is found within it. If `eat` is
957 /// true, then `str` will be modified to trim off this returned prefix
958 /// (including the newline character).
959 string_view OIIO_UTIL_API parse_line(string_view& str, bool eat = true) noexcept;
960 
961 
962 /// Assuming the string str starts with either '(', '[', or '{', return the
963 /// head, up to and including the corresponding closing character (')', ']',
964 /// or '}', respectively), recognizing nesting structures. For example,
965 /// parse_nested("(a(b)c)d") should return "(a(b)c)", NOT "(a(b)". Return an
966 /// empty string if str doesn't start with one of those characters, or
967 /// doesn't contain a correctly matching nested pair. If eat==true, str will
968 /// be modified to trim off the part of the string that is returned as the
969 /// match.
970 string_view OIIO_UTIL_API parse_nested (string_view &str, bool eat=true) noexcept;
971 
972 
973 /// Look within `str` for the pattern:
974 /// head nonwhitespace_chars whitespace
975 /// Remove that full pattern from `str` and return the nonwhitespace
976 /// part that followed the head (or return the empty string and leave `str`
977 /// unmodified, if the head was never found).
978 OIIO_UTIL_API std::string
979 excise_string_after_head (std::string& str, string_view head);
980 
981 
982 /// Converts utf-8 string to vector of unicode codepoints. This function
983 /// will not stop on invalid sequences. It will let through some invalid
984 /// utf-8 sequences like: 0xfdd0-0xfdef, 0x??fffe/0x??ffff. It does not
985 /// support 5-6 bytes long utf-8 sequences. Will skip trailing character if
986 /// there are not enough bytes for decoding a codepoint.
987 ///
988 /// N.B. Following should probably return u32string instead of taking
989 /// vector, but C++11 support is not yet stabilized across compilers.
990 /// We will eventually add that and deprecate this one, after everybody
991 /// is caught up to C++11.
992 void OIIO_UTIL_API utf8_to_unicode (string_view str, std::vector<uint32_t> &uvec);
993 
994 /// Encode the string in base64.
995 /// https://en.wikipedia.org/wiki/Base64
996 std::string OIIO_UTIL_API base64_encode (string_view str);
997 
998 
1000 
1001 /// Compute an edit distance metric between strings `a` and `b`, roughly
1002 /// speaking, the number of changes that would be made to transform one string
1003 /// into the other. Identical strings have a distance of 0. The `method`
1004 /// selects among possible algorithms, which may have different distance
1005 /// metrics or allow different types of edits. (Currently, the only method
1006 /// supported is Levenshtein; this parameter is for future expansion.)
1007 OIIO_UTIL_API size_t
1010 
1011 } // namespace Strutil
1012 
uint64_t from_string< uint64_t >(string_view s)
Definition: strutil.h:597
void print(const char *fmt, const Args &...args)
Definition: strutil.h:202
#define OIIO_CONSTEXPR14
Definition: platform.h:101
GLint first
Definition: glcorearb.h:405
bool OIIO_UTIL_API parse_int(string_view &str, int &val, bool eat=true) noexcept
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
OIIO_FORMAT_DEPRECATED std::string format(const char *fmt, const Args &...args)
Definition: strutil.h:134
void printf(const char *fmt, const Args &...args)
Definition: strutil.h:171
std::string upper(string_view a)
Return an all-upper case version of a (locale-independent).
Definition: strutil.h:402
bool OIIO_UTIL_API iequals(string_view a, string_view b)
size_t operator()(string_view s) const
Definition: strutil.h:738
unsigned int from_string< unsigned int >(string_view s)
Definition: strutil.h:577
OIIO_UTIL_API bool scan_datetime(string_view str, int &year, int &month, int &day, int &hour, int &min, int &sec)
OIIO_UTIL_API std::vector< string_view > splitsv(string_view str, string_view sep="", int maxsplit=-1)
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:623
STATIC_INLINE size_t Hash(const char *s, size_t len)
Definition: farmhash.h:2038
bool OIIO_UTIL_API parse_char(string_view &str, char c, bool skip_whitespace=true, bool eat=true) noexcept
OIIO_UTIL_API bool string_is_int(string_view s)
const GLdouble * v
Definition: glcorearb.h:837
UT_StringArray JOINTS head
std::string format(const Str &fmt, Args &&...args)
Definition: strutil.h:121
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
GLsizei const GLfloat * value
Definition: glcorearb.h:824
void fprintf(FILE *file, const char *fmt, const Args &...args)
Definition: strutil.h:177
Definition: span.h:73
OIIO_UTIL_API unsigned int stoui(string_view s, size_t *pos=0, int base=10)
std::string to_string(const T &value)
Definition: strutil.h:610
size_t OIIO_UTIL_API irfind(string_view a, string_view b)
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLdouble s
Definition: glad.h:3009
bool OIIO_UTIL_API istarts_with(string_view a, string_view b)
string_view OIIO_UTIL_API rstrip(string_view str, string_view chars=string_view())
OIIO_FORMAT_DEPRECATED std::string format(string_view fmt, const Args &...args)
Definition: strutil.h:143
bool OIIO_UTIL_API ends_with(string_view a, string_view b)
Does 'a' end with the string 'b', with a case-sensitive comparison?
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
#define OIIO_DEPRECATED(msg)
Definition: platform.h:458
**But if you need a result
Definition: thread.h:613
bool OIIO_UTIL_API iends_with(string_view a, string_view b)
bool OIIO_UTIL_API icontains(string_view a, string_view b)
#define OIIO_UTIL_API
Definition: export.h:71
std::string OIIO_UTIL_API escape_chars(string_view unescaped)
string_view OIIO_UTIL_API lstrip(string_view str, string_view chars=string_view())
constexpr const_pointer data() const noexcept
Definition: string_view.h:170
string_view OIIO_UTIL_API parse_nested(string_view &str, bool eat=true) noexcept
bool OIIO_UTIL_API parse_string(string_view &str, string_view &val, bool eat=true, QuoteBehavior keep_quotes=DeleteQuotes) noexcept
OIIO_UTIL_API float stof(string_view s, size_t *pos=0)
basic_string_view< char > string_view
Definition: core.h:522
string_view OIIO_UTIL_API parse_line(string_view &str, bool eat=true) noexcept
constexpr size_type size() const noexcept
Definition: string_view.h:150
__attribute__((visibility("default")))
void OIIO_UTIL_API sync_output(FILE *file, string_view str)
OIIO_UTIL_API char * safe_strcpy(char *dst, string_view src, size_t size) noexcept
bool OIIO_UTIL_API iless(string_view a, string_view b)
GLdouble n
Definition: glcorearb.h:2008
static const size_type npos
Definition: string_view.h:81
int64_t from_string< int64_t >(string_view s)
Definition: strutil.h:591
OIIO_UTIL_API bool string_is_float(string_view s)
string_view OIIO_UTIL_API parse_while(string_view &str, string_view set, bool eat=true) noexcept
void OIIO_UTIL_API remove_trailing_whitespace(string_view &str) noexcept
std::string OIIO_UTIL_API vformat(const char *fmt, va_list ap)
std::string to_string(const char *value)
Definition: strutil.h:617
size_t OIIO_UTIL_API ifind(string_view a, string_view b)
void OIIO_UTIL_API to_lower(std::string &a)
Definition: Name.h:96
bool OIIO_UTIL_API parse_values(string_view &str, string_view prefix, span< int > values, string_view sep="", string_view postfix="", bool eat=true) noexcept
float from_string< float >(string_view s)
Definition: strutil.h:582
size_t OIIO_UTIL_API rfind(string_view a, string_view b)
std::string OIIO_UTIL_API replace(string_view str, string_view pattern, string_view replacement, bool global=false)
bool OIIO_UTIL_API parse_float(string_view &str, float &val, bool eat=true) noexcept
float OIIO_UTIL_API strtof(const char *nptr, char **endptr=nullptr) noexcept
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
std::string OIIO_UTIL_API wordwrap(string_view src, int columns=80, int prefix=0, string_view sep=" ", string_view presep="")
OIIO_CONSTEXPR14 size_t strhash(size_t len, const char *s)
Definition: strutil.h:293
double from_string< double >(string_view s)
Definition: strutil.h:587
OIIO_UTIL_API double stod(string_view s, size_t *pos=0)
OIIO_UTIL_API int stoi(string_view s, size_t *pos=0, int base=10)
QuoteBehavior
Definition: strutil.h:899
std::string OIIO_UTIL_API memformat(long long bytes, int digits=1)
OIIO_UTIL_API std::string excise_string_after_head(std::string &str, string_view head)
std::wstring OIIO_UTIL_API utf8_to_utf16(string_view utf8str) noexcept
GLushort pattern
Definition: glad.h:2583
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
constexpr auto make_format_args(const Args &...args) -> format_arg_store< Context, Args...>
Definition: core.h:1719
bool OIIO_UTIL_API contains_any_char(string_view a, string_view set)
Does 'a' contain any of the characters within set?
T from_string(string_view s)
Definition: strutil.h:567
bool isspace(char c)
Definition: strutil.h:799
GLdouble t
Definition: glad.h:2397
void trim_whitespace(string_view &str) noexcept
Definition: strutil.h:813
size_t OIIO_UTIL_API find(string_view a, string_view b)
bool OIIO_UTIL_API parse_until_char(string_view &str, char c, bool eat=true) noexcept
bool string_is(string_view)
Definition: strutil.h:624
std::string OIIO_UTIL_API repeat(string_view str, int n)
Repeat a string formed by concatenating str n times.
GLsizeiptr size
Definition: glcorearb.h:664
GLenum GLenum dst
Definition: glcorearb.h:1793
std::string OIIO_UTIL_API unescape_chars(string_view escaped)
std::string OIIO_UTIL_API base64_encode(string_view str)
std::string join(const Sequence &seq, string_view sep="")
Definition: strutil.h:454
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
OIIO_UTIL_API size_t edit_distance(string_view a, string_view b, EditDistMetric metric=EditDistMetric::Levenshtein)
std::string lower(string_view a)
Return an all-upper case version of a (locale-independent).
Definition: strutil.h:395
int extract_from_list_string(std::vector< T, Allocator > &vals, string_view list, string_view sep=",")
Definition: strutil.h:656
bool OIIO_UTIL_API starts_with(string_view a, string_view b)
Does 'a' start with the string 'b', with a case-sensitive comparison?
bool ircontains(string_view a, string_view b)
Definition: strutil.h:379
constexpr size_type length() const noexcept
Definition: string_view.h:151
OIIO_UTIL_API std::vector< std::string > splits(string_view str, string_view sep="", int maxsplit=-1)
GLuint GLfloat * val
Definition: glcorearb.h:1608
bool string_is< int >(string_view s)
Definition: strutil.h:628
bool string_is< float >(string_view s)
Definition: strutil.h:633
void OIIO_UTIL_API skip_whitespace(string_view &str) noexcept
**If you just want to fire and args
Definition: thread.h:609
int from_string< int >(string_view s)
Definition: strutil.h:573
EditDistMetric
Definition: strutil.h:999
#define OIIO_FORMAT_DEPRECATED
Definition: strutil.h:49
Definition: core.h:1131
std::string OIIO_UTIL_API vsprintf(const char *fmt, va_list ap)
string_view OIIO_UTIL_API parse_identifier(string_view &str, bool eat=true) noexcept
GLboolean r
Definition: glcorearb.h:1222
#define OIIO_NAMESPACE_END
Definition: oiioversion.h:94
auto sprintf(const S &fmt, const T &...args) -> std::basic_string< Char >
Definition: printf.h:574
string_view OIIO_UTIL_API strip(string_view str, string_view chars=string_view())
void OIIO_UTIL_API split(string_view str, std::vector< string_view > &result, string_view sep=string_view(), int maxsplit=-1)
C++ functor for comparing two strings for equality of their characters.
Definition: strutil.h:746
bool OIIO_UTIL_API get_rest_arguments(const std::string &str, std::string &base, std::map< std::string, std::string > &result)
bool scan_values(string_view str, string_view prefix, span< int > values, string_view sep="", string_view postfix="") noexcept
Definition: strutil.h:884
std::string OIIO_UTIL_API utf16_to_utf8(const std::wstring &utf16str) noexcept
bool OIIO_UTIL_API contains(string_view a, string_view b)
Does 'a' contain the string 'b' within it?
type
Definition: core.h:1059
void OIIO_UTIL_API utf8_to_unicode(string_view str, std::vector< uint32_t > &uvec)
void OIIO_UTIL_API to_upper(std::string &a)
std::string OIIO_UTIL_API concat(string_view s, string_view t)
string_view OIIO_UTIL_API parse_word(string_view &str, bool eat=true) noexcept
std::string OIIO_UTIL_API timeintervalformat(double secs, int digits=1)
C++ functor for comparing the ordering of two strings.
Definition: strutil.h:761
Definition: format.h:2459
bool OIIO_UTIL_API parse_prefix(string_view &str, string_view prefix, bool eat=true) noexcept
bool rcontains(string_view a, string_view b)
Definition: strutil.h:371
string_view OIIO_UTIL_API parse_until(string_view &str, string_view set=" \t\r\n", bool eat=true) noexcept
#define OIIO_NAMESPACE_BEGIN
Definition: oiioversion.h:93
bool OIIO_UTIL_API parse_identifier_if(string_view &str, string_view id, bool eat=true) noexcept
GLenum src
Definition: glcorearb.h:1793
bool parse_value(string_view &str, float &val, bool eat=true) noexcept
Synonym for parse_int.
Definition: strutil.h:853
double OIIO_UTIL_API strtod(const char *nptr, char **endptr=nullptr) noexcept