Blender V5.0
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 float4;
20
21using std::string;
22using std::to_string;
23
24using OIIO::string_view;
25
26#ifdef __GNUC__
27# define PRINTF_ATTRIBUTE __attribute__((format(printf, 1, 2)))
28#else
29# define PRINTF_ATTRIBUTE
30#endif
31
32string string_printf(const char *format, ...) PRINTF_ATTRIBUTE;
33
34bool string_iequals(const string &a, const string &b);
35void string_split(vector<string> &tokens,
36 const string &str,
37 const string &separators = "\t ",
38 bool skip_empty_tokens = true);
39void string_replace(string &haystack, const string &needle, const string &other);
40void string_replace_same_length(string &haystack, const string &needle, const string &other);
41bool string_startswith(string_view s, string_view start);
42bool string_endswith(string_view s, string_view end);
43string string_strip(const string &s);
44string string_remove_trademark(const string &s);
45string string_from_bool(const bool var);
46string string_hex(const uint8_t *data, const size_t size);
47string to_string(const char *str);
48string to_string(const float4 &v);
49string string_to_lower(const string &s);
50
51/* Wide char strings are only used on Windows to deal with non-ASCII
52 * characters in file names and such. No reason to use such strings
53 * for something else at this moment.
54 *
55 * Please note that strings are expected to be in UTF8 code-page, and
56 * if ANSI is needed then explicit conversion required.
57 */
58#ifdef _WIN32
59using std::wstring;
60wstring string_to_wstring(const string &path);
61string string_from_wstring(const wstring &path);
62string string_to_ansi(const string &str);
63#endif
64
65/* Make a string from a size in bytes in human readable form. */
66string string_human_readable_size(const size_t size);
67/* Make a string from a unit-less quantity in human readable form. */
68string string_human_readable_number(const size_t num);
69
ATTR_WARN_UNUSED_RESULT const size_t num
BMesh const char void * data
return true
ATTR_WARN_UNUSED_RESULT const BMVert * v
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
#define CCL_NAMESPACE_END
#define str(s)
static const char * to_string(const Interpolation &interp)
Definition gl_shader.cc:103
format
string string_remove_trademark(const string &s)
Definition string.cpp:168
string string_from_bool(bool var)
Definition string.cpp:183
bool string_iequals(const string &a, const string &b)
Definition string.cpp:55
string string_strip(const string &s)
Definition string.cpp:137
string string_hex(const uint8_t *data, const size_t size)
Definition string.cpp:191
bool string_startswith(const string_view s, const string_view start)
Definition string.cpp:104
void string_replace_same_length(string &haystack, const string &needle, const string &other)
Definition string.cpp:155
void string_split(vector< string > &tokens, const string &str, const string &separators, bool skip_empty_tokens)
Definition string.cpp:70
void string_replace(string &haystack, const string &needle, const string &other)
Definition string.cpp:145
bool string_endswith(const string_view s, const string_view end)
Definition string.cpp:120
string string_to_lower(const string &s)
Definition string.cpp:210
string string_printf(const char *format,...) PRINTF_ATTRIBUTE
Definition string.cpp:23
string string_human_readable_size(const size_t size)
Definition string.cpp:257
string string_human_readable_number(const size_t num)
Definition string.cpp:276
#define PRINTF_ATTRIBUTE
Definition string.h:29