Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
StringHelper.h
Go to the documentation of this file.
1/*
2Copyright (c) 2018 DIVIDE-Studio
3Copyright (c) 2009 Ionut Cava
4
5This file is part of DIVIDE Framework.
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software
9and associated documentation files (the "Software"), to deal in the Software
10without restriction,
11including without limitation the rights to use, copy, modify, merge, publish,
12distribute, sublicense,
13and/or sell copies of the Software, and to permit persons to whom the
14Software is furnished to do so,
15subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in
18all copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED,
22INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23PARTICULAR PURPOSE AND NONINFRINGEMENT.
24IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25DAMAGES OR OTHER LIABILITY,
26WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27IN CONNECTION WITH THE SOFTWARE
28OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30*/
31
32#pragma once
33#ifndef DVD_CORE_STRING_HELPER_H_
34#define DVD_CORE_STRING_HELPER_H_
35
36namespace Divide {
37 namespace Util {
38 template<typename T>
39 concept valid_replace_string = is_string<T> || std::is_same_v<T, ResourcePath>;
40
41 bool FindCommandLineArgument(int argc, char** argv, const char* target_arg, const char* arg_prefix = "--");
42 bool ExtractStartupProject(int argc, char** argv, string& projectOut, const char* arg_prefix = "--");
43
44 template< typename T_str = string> requires valid_replace_string<T_str>
45 bool ReplaceStringInPlace(T_str& subject, std::span<const std::string_view> search, std::string_view replace, bool recursive = false);
46
47 template<typename T_str = string> requires valid_replace_string<T_str>
48 [[nodiscard]] T_str ReplaceString(std::string_view subject, std::span<const std::string_view> search, std::string_view replace, bool recursive = false);
49
50 template<typename T_str = string> requires valid_replace_string<T_str>
51 bool ReplaceStringInPlace(T_str& subject, std::string_view search, std::string_view replace, bool recursive = false);
52
53 template<typename T_str = string> requires valid_replace_string<T_str>
54 [[nodiscard]] T_str ReplaceString(std::string_view subject, std::string_view search, std::string_view replace, bool recursive = false);
55
56 [[nodiscard]] string MakeXMLSafe(std::string_view subject);
57 [[nodiscard]] ResourcePath MakeXMLSafe(const ResourcePath& subject);
58
59 template<typename T_str = string> requires valid_replace_string<T_str>
60 void GetPermutations(std::string_view subject, vector<T_str>& permutationContainer);
61
62 template<typename T_str = string> requires is_string<T_str>
63 [[nodiscard]] bool IsNumber(const T_str& s);
64
65 [[nodiscard]] bool IsNumber(const char* s);
66
67 [[nodiscard]] bool BeginsWith(std::string_view input, std::string_view compare, bool ignoreWhitespace);
68
69 template<typename T_str = string> requires is_string<T_str>
70 [[nodiscard]] T_str GetTrailingCharacters(const T_str& input, size_t count);
71
72 template<typename T_str = string> requires is_string<T_str>
73 [[nodiscard]] T_str GetStartingCharacters(const T_str& input, size_t count);
74
75 [[nodiscard]] bool CompareIgnoreCase(const char* a, const char* b) noexcept;
76 [[nodiscard]] bool CompareIgnoreCase(std::string_view a, std::string_view b) noexcept;
77
79 template<typename T_vec, typename T_str> requires is_vector<T_vec, T_str> && is_string<T_str>
80 [[nodiscard]] T_vec Split(const char* input, char delimiter);
81
82 template<typename T_vec, typename T_str> requires is_vector<T_vec, T_str> && is_string<T_str>
83 void Split(const char* input, char delimiter, T_vec& elems);
84
86 template<typename T_str = string> requires is_string<T_str>
87 T_str& Ltrim(T_str& s);
88
89 template<typename T_str = string> requires is_string<T_str>
90 [[nodiscard]] T_str Ltrim(const T_str& s);
91
92 template<typename T_str = string> requires is_string<T_str>
93 T_str& Rtrim(T_str& s);
94
95 template<typename T_str = string> requires is_string<T_str>
96 [[nodiscard]] T_str Rtrim(const T_str& s);
97
98 template<typename T_str = string> requires is_string<T_str>
99 T_str& Trim(T_str& s);
100
101 template<typename T_str = string> requires is_string<T_str>
102 [[nodiscard]] T_str Trim(const T_str& s);
103
104 template<typename T_str = string> requires is_string<T_str>
105 [[nodiscard]] bool GetLine(istringstream& input, T_str& line, char delimiter = '\n');
106
107 template <typename Str = string, typename... Args> requires (!concept_const_char<Str>)
108 [[nodiscard]] Str StringFormat(const char* fmt, Args&& ...args);
109
110 template <typename Str = string, typename... Args> requires (!concept_const_char<Str>)
111 void StringFormat( Str& output, const char* fmt, Args&& ...args );
112
113 template<typename T>
114 [[nodiscard]] string to_string( GET_PASS_TYPE<T> value);
115
116 template<typename T_str = string> requires is_string<T_str>
117 [[nodiscard]] U32 LineCount(const T_str& str);
118
119 void CStringRemoveChar(char* str, char charToRemove) noexcept;
120
121 [[nodiscard]] bool IsEmptyOrNull(const char* str) noexcept;
122
123 [[nodiscard]] char *commaprint(U64 number) noexcept;
124 } //namespace Util
125} //namespace Divide
126
127#endif //DVD_CORE_STRING_HELPER_H_
128
129#include "StringHelper.inl"
char * argv[]
Definition: main.cpp:8
bool GetLine(istringstream &input, T_str &line, char delimiter='\n')
Str StringFormat(const char *fmt, Args &&...args)
string to_string(GET_PASS_TYPE< T > value)
void GetPermutations(std::string_view subject, vector< T_str > &permutationContainer)
bool CompareIgnoreCase(const char *a, const char *b) noexcept
bool BeginsWith(std::string_view input, std::string_view compare, bool ignoreWhitespace)
T_vec Split(const char *input, char delimiter)
http://stackoverflow.com/questions/236129/split-a-string-in-c
T_str & Trim(T_str &s)
bool ExtractStartupProject(int argc, char **argv, string &projectOut, const char *arg_prefix="--")
T_str & Ltrim(T_str &s)
http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring
bool IsEmptyOrNull(const char *str) noexcept
void CStringRemoveChar(char *str, char charToRemove) noexcept
bool FindCommandLineArgument(int argc, char **argv, const char *target_arg, const char *arg_prefix="--")
T_str ReplaceString(std::string_view subject, std::span< const std::string_view > search, std::string_view replace, bool recursive=false)
string MakeXMLSafe(std::string_view subject)
bool IsNumber(const T_str &s)
U32 LineCount(const T_str &str)
T_str GetStartingCharacters(const T_str &input, size_t count)
T_str & Rtrim(T_str &s)
char * commaprint(U64 number) noexcept
bool ReplaceStringInPlace(T_str &subject, std::span< const std::string_view > search, std::string_view replace, bool recursive=false)
T_str GetTrailingCharacters(const T_str &input, size_t count)
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
typename std::conditional< pass_by_value< Type >(), typename std::conditional< std::is_move_assignable_v< Type >, Type, const Type >::type, Type const & >::type GET_PASS_TYPE
std::basic_istringstream< char, std::char_traits< char >, dvd_allocator< char > > istringstream
Definition: STLString.h:47
std::basic_string< char, std::char_traits< char >, dvd_allocator< char > > string
Definition: STLString.h:41
uint32_t U32
uint64_t U64