Blender V5.3
string.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include <cstring>
8#include <string>
9
10/* Use string view implementation from OIIO.
11 * Ideally, need to switch to `std::string_view`, but this first requires getting rid of using
12 * namespace OIIO as it causes symbol collision. */
13#include <OpenImageIO/string_view.h>
14
15#include "util/vector.h"
16
18
19struct float2;
20struct float4;
21
22using std::string;
23using std::to_string;
24
25using OIIO::string_view;
26
27#ifdef __GNUC__
28# define PRINTF_ATTRIBUTE __attribute__((format(printf, 1, 2)))
29#else
30# define PRINTF_ATTRIBUTE
31#endif
32
33string string_printf(const char *format, ...) PRINTF_ATTRIBUTE;
34
35bool string_iequals(const string &a, const string &b);
36void string_split(vector<string> &tokens,
37 const string &str,
38 const string &separators = "\t ",
39 bool skip_empty_tokens = true);
40void string_replace(string &haystack, const string &needle, const string &other);
41void string_replace_same_length(string &haystack, const string &needle, const string &other);
42bool string_startswith(string_view s, string_view start);
43bool string_endswith(string_view s, string_view end);
44string string_strip(const string &s);
45string string_remove_trademark(const string &s);
46string string_from_bool(const bool var);
47string string_hex(const uint8_t *data, const size_t size);
48string to_string(const char *str);
49string to_string(const float2 &v);
50string to_string(const float4 &v);
51string string_to_lower(const string &s);
52string string_remove_gpu_from_cpu_name(const string &s);
53
54/* Wide char strings are only used on Windows to deal with non-ASCII
55 * characters in file names and such. No reason to use such strings
56 * for something else at this moment.
57 *
58 * Please note that strings are expected to be in UTF8 code-page, and
59 * if ANSI is needed then explicit conversion required.
60 */
61using std::wstring;
62wstring string_to_wstring(const string &str);
63string string_from_wstring(const wstring &str);
64#ifdef _WIN32
65string string_to_ansi(const string &str);
66#endif
67
68/* Make a string from a size in bytes in human readable form. */
69string string_human_readable_size(const size_t size);
70/* Make a string from a unit-less quantity in human readable form. */
71string string_human_readable_number(const size_t num);
72
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
#define CCL_NAMESPACE_END
#define str(s)
string string_from_wstring(const wstring &str)
Definition string.cpp:286
string string_remove_trademark(const string &s)
Definition string.cpp:170
wstring string_to_wstring(const string &str)
Definition string.cpp:261
string string_from_bool(bool var)
Definition string.cpp:185
string string_human_readable_size(size_t size)
Definition string.cpp:333
bool string_iequals(const string &a, const string &b)
Definition string.cpp:57
string string_strip(const string &s)
Definition string.cpp:139
string to_string(const char *str)
Definition string.cpp:202
string string_hex(const uint8_t *data, const size_t size)
Definition string.cpp:193
string string_human_readable_number(size_t num)
Definition string.cpp:352
bool string_startswith(const string_view s, const string_view start)
Definition string.cpp:106
CCL_NAMESPACE_BEGIN string string_printf(const char *format,...)
Definition string.cpp:25
void string_replace_same_length(string &haystack, const string &needle, const string &other)
Definition string.cpp:157
void string_split(vector< string > &tokens, const string &str, const string &separators, bool skip_empty_tokens)
Definition string.cpp:72
void string_replace(string &haystack, const string &needle, const string &other)
Definition string.cpp:147
string string_remove_gpu_from_cpu_name(const string &s)
Definition string.cpp:224
bool string_endswith(const string_view s, const string_view end)
Definition string.cpp:122
string string_to_lower(const string &s)
Definition string.cpp:217
#define PRINTF_ATTRIBUTE
Definition string.h:30