Easy3D 2.6.1
Loading...
Searching...
No Matches
string.h
1/********************************************************************
2 * Copyright (C) 2015-2021 by Liangliang Nan <liangliang.nan@gmail.com>
3 * Copyright (C) 2000-2005 INRIA - Project ALICE
4 *
5 * The code in this file is partly from OGF/Graphite (2.0 alpha-4) with
6 * modifications and enhancement:
7 * https://gforge.inria.fr/forum/forum.php?forum_id=11459
8 * The original code was distributed under the GNU GPL license.
9 ********************************************************************/
10
11#ifndef EASY3D_UTIL_STRING_H
12#define EASY3D_UTIL_STRING_H
13
14#include <string>
15#include <sstream>
16#include <vector>
17
18
19namespace easy3d {
20
25 namespace string {
26
38 void split(const std::string &in, char separator, std::vector<std::string> &out, bool skip_empty_fields = true);
39
53 bool split(const std::string &in, char separator, std::string &left, std::string &right);
54
64 std::string join(const std::vector<std::string> &in, char separator);
65
75 std::string join(const std::vector<std::string> &in, const std::string &separator);
76
80 void replace(std::string &in, const std::string &old_substr, const std::string &new_substr);
81
88 std::string to_lowercase(const std::string &s);
89
96 std::string to_uppercase(const std::string &s);
97
103 inline std::string to_string(char c) {
104 const char s[2] = { c, '\0' };
105 return std::string(s);
106 }
107
116 std::string quote(const std::string &s, char quotes = '\"');
117
125 bool starts_with(const std::string &haystack, const std::string &needle);
126
134 bool ends_with(const std::string &haystack, const std::string &needle);
135
141 std::string to_string(int value, int width, char fill = '0');
142
146 std::string printf(const char *format, ...);
147
151 void appendf(std::string &dst, const char *format, ...);
152
156 std::string current_time();
161 std::string current_time_detailed();
162
167 std::string time(double time, int num_digits = 1);
168
172 std::wstring to_wstring(const std::string &str);
173
177 std::string from_wstring(const std::wstring &wstr);
178
179 }
180
181}
182
183
184#endif // EASY3D_UTIL_STRING_H
185
String manipulation utilities.
Definition string.cpp:24
void replace(std::string &in, const std::string &old_substr, const std::string &new_substr)
Replaces the old sub-string by a new sub-string.
Definition string.cpp:74
bool ends_with(const std::string &haystack, const std::string &needle)
Checks if a string ends with a substring.
Definition string.cpp:121
std::string printf(const char *format,...)
Definition string.cpp:185
std::string current_time_detailed()
Gets the detailed current time as a string, e.g., "2024-10-24-17-41-16-753".
Definition string.cpp:214
std::string from_wstring(const std::wstring &wstr)
Converts from std::wstring to std::string.
Definition string.cpp:261
std::string quote(const std::string &s, char quotes)
Adds quotes to a string.
Definition string.cpp:113
std::string to_uppercase(const std::string &str)
Converts a string to uppercase.
Definition string.cpp:89
void appendf(std::string &dst, const char *format,...)
Appends the resulting string to a supplied string.
Definition string.cpp:194
void split(const std::string &in, char separator, std::vector< std::string > &out, bool skip_empty_fields)
Splits a string into parts.
Definition string.cpp:26
std::string to_string(int v, int width, char fill)
Converts an integer value to a string of a desired length.
Definition string.cpp:127
std::string to_lowercase(const std::string &str)
Converts a string to lowercase.
Definition string.cpp:83
std::wstring to_wstring(const std::string &str)
Converts from std::string to std::wstring.
Definition string.cpp:256
std::string join(const std::vector< std::string > &in, char separator)
Join multiple strings.
Definition string.cpp:53
bool starts_with(const std::string &haystack, const std::string &needle)
Checks if a string starts with a substring.
Definition string.cpp:117
std::string time(double time, int num_digits)
Converts time (in millisecond) into a string with the most suitable/readable unit....
Definition string.cpp:227
std::string current_time()
Gets the time string, e.g., "Fri Jan 09 11:39:32 2015".
Definition string.cpp:202
Definition collider.cpp:182