Blender V4.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 <string.h>
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
19using std::string;
20using std::to_string;
21
22using OIIO::string_view;
23
24#ifdef __GNUC__
25# define PRINTF_ATTRIBUTE __attribute__((format(printf, 1, 2)))
26#else
27# define PRINTF_ATTRIBUTE
28#endif
29
30string string_printf(const char *format, ...) PRINTF_ATTRIBUTE;
31
32bool string_iequals(const string &a, const string &b);
33void string_split(vector<string> &tokens,
34 const string &str,
35 const string &separators = "\t ",
36 bool skip_empty_tokens = true);
37void string_replace(string &haystack, const string &needle, const string &other);
38void string_replace_same_length(string &haystack, const string &needle, const string &other);
39bool string_startswith(string_view s, string_view start);
40bool string_endswith(string_view s, string_view end);
41string string_strip(const string &s);
42string string_remove_trademark(const string &s);
43string string_from_bool(const bool var);
44string to_string(const char *str);
45string to_string(const float4 &v);
46string string_to_lower(const string &s);
47
48/* Wide char strings are only used on Windows to deal with non-ASCII
49 * characters in file names and such. No reason to use such strings
50 * for something else at this moment.
51 *
52 * Please note that strings are expected to be in UTF-8 codepage, and
53 * if ANSI is needed then explicit conversion required.
54 */
55#ifdef _WIN32
56using std::wstring;
57wstring string_to_wstring(const string &path);
58string string_from_wstring(const wstring &path);
59string string_to_ansi(const string &str);
60#endif
61
62/* Make a string from a size in bytes in human readable form. */
63string string_human_readable_size(size_t size);
64/* Make a string from a unit-less quantity in human readable form. */
65string string_human_readable_number(size_t num);
66
ATTR_WARN_UNUSED_RESULT const BMVert * v
local_group_size(16, 16) .push_constant(Type b
#define CCL_NAMESPACE_END
#define str(s)
format
string string_remove_trademark(const string &s)
Definition string.cpp:155
string string_printf(const char *format,...) PRINTF_ATTRIBUTE
Definition string.cpp:23
string string_from_bool(const bool var)
Definition string.cpp:170
string string_human_readable_size(size_t size)
Definition string.cpp:234
bool string_iequals(const string &a, const string &b)
Definition string.cpp:55
void string_split(vector< string > &tokens, const string &str, const string &separators="\t ", bool skip_empty_tokens=true)
Definition string.cpp:70
bool string_endswith(string_view s, string_view end)
Definition string.cpp:114
string string_strip(const string &s)
Definition string.cpp:125
bool string_startswith(string_view s, string_view start)
Definition string.cpp:103
string string_human_readable_number(size_t num)
Definition string.cpp:255
void string_replace_same_length(string &haystack, const string &needle, const string &other)
Definition string.cpp:142
void string_replace(string &haystack, const string &needle, const string &other)
Definition string.cpp:133
#define PRINTF_ATTRIBUTE
Definition string.h:27
string string_to_lower(const string &s)
Definition string.cpp:190