Easy3D 2.5.3
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 <iomanip>
17#include <vector>
18
19
20namespace easy3d {
21
26 namespace string {
27
39 void split(const std::string &in, char separator, std::vector<std::string> &out, bool skip_empty_fields = true);
40
54 bool split(const std::string &in, char separator, std::string &left, std::string &right);
55
65 std::string join(const std::vector<std::string> &in, char separator);
66
76 std::string join(const std::vector<std::string> &in, const std::string &separator);
77
81 void replace(std::string &in, const std::string &old_substr, const std::string &new_substr);
82
89 std::string to_lowercase(const std::string &s);
90
97 std::string to_uppercase(const std::string &s);
98
104 inline std::string to_string(char c) {
105 const char s[2] = { c, '\0' };
106 return std::string(s);
107 }
108
117 std::string quote(const std::string &s, char quotes = '\"');
118
126 bool starts_with(const std::string &haystack, const std::string &needle);
127
135 bool ends_with(const std::string &haystack, const std::string &needle);
136
142 std::string to_string(int value, int width, char fill = '0');
143
147 std::string printf(const char *format, ...);
148
152 void appendf(std::string &dst, const char *format, ...);
153
157 std::string date_time();
158
163 std::string time(double time, int num_digits = 1);
164
168 std::wstring to_wstring(const std::string &str);
169
173 std::string from_wstring(const std::wstring &wstr);
174
175 }
176
177}
178
179
180#endif // EASY3D_UTIL_STRING_H
181
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:72
bool ends_with(const std::string &haystack, const std::string &needle)
Checks if a string ends with a substring.
Definition: string.cpp:119
std::string printf(const char *format,...)
Definition: string.cpp:183
std::string from_wstring(const std::wstring &wstr)
Converts from std::wstring to std::string.
Definition: string.cpp:257
std::string quote(const std::string &s, char quotes)
Adds quotes to a string.
Definition: string.cpp:111
std::string date_time()
Gets the time string, e.g., "Fri Jan 09 11:39:32 2015".
Definition: string.cpp:201
std::string to_uppercase(const std::string &str)
Converts a string to uppercase.
Definition: string.cpp:87
void appendf(std::string &dst, const char *format,...)
Appends the resulting string to a supplied string.
Definition: string.cpp:192
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:24
std::string to_string(int v, int width, char fill)
Converts an integer value to a string of a desired length.
Definition: string.cpp:125
std::string to_lowercase(const std::string &str)
Converts a string to lowercase.
Definition: string.cpp:81
std::wstring to_wstring(const std::string &str)
Converts from std::string to std::wstring.
Definition: string.cpp:252
std::string join(const std::vector< std::string > &in, char separator)
Join multiple strings.
Definition: string.cpp:51
bool starts_with(const std::string &haystack, const std::string &needle)
Checks if a string starts with a substring.
Definition: string.cpp:115
std::string time(double time, int num_digits)
Converts time (in millisecond) into a string with the most suitable/readable unit....
Definition: string.cpp:223
Definition: collider.cpp:182