-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved string functions to source files
- Loading branch information
1 parent
8ed58b7
commit 9efd996
Showing
16 changed files
with
121 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef RFL_INTERNAL_STRINGS_STRINGS_HPP_ | ||
#define RFL_INTERNAL_STRINGS_STRINGS_HPP_ | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace rfl::internal::strings { | ||
|
||
/// Joins a series of strings. | ||
std::string join(const std::string& _delimiter, | ||
const std::vector<std::string>& _strings); | ||
|
||
/// Replace all occurences of _from with _to. | ||
std::string replace_all(const std::string& _str, const std::string& _from, | ||
const std::string& _to); | ||
|
||
/// Splits _str along _delimiter. | ||
std::vector<std::string> split(const std::string& _str, | ||
const std::string& _delimiter); | ||
|
||
/// Transforms the string to camel case. | ||
std::string to_camel_case(const std::string& _str); | ||
|
||
/// Transforms the string to pascal case. | ||
std::string to_pascal_case(const std::string& _str); | ||
|
||
} // namespace rfl::internal::strings | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
|
||
namespace rfl ::internal ::strings { | ||
|
||
char to_lower(const char ch) { | ||
if (ch >= 'A' && ch <= 'Z') { | ||
return ch + ('a' - 'A'); | ||
} else { | ||
return ch; | ||
} | ||
} | ||
|
||
char to_upper(const char ch) { | ||
if (ch >= 'a' && ch <= 'z') { | ||
return ch + ('A' - 'a'); | ||
} else { | ||
return ch; | ||
} | ||
} | ||
|
||
std::string join(const std::string& _delimiter, | ||
const std::vector<std::string>& _strings) { | ||
if (_strings.size() == 0) { | ||
return ""; | ||
} | ||
auto res = _strings[0]; | ||
for (size_t i = 1; i < _strings.size(); ++i) { | ||
res += _delimiter + _strings[i]; | ||
} | ||
return res; | ||
} | ||
|
||
std::string replace_all(const std::string& _str, const std::string& _from, | ||
const std::string& _to) { | ||
auto str = _str; | ||
|
||
size_t pos = 0; | ||
while ((pos = str.find(_from, pos)) != std::string::npos) { | ||
str.replace(pos, _from.length(), _to); | ||
pos += _to.length(); | ||
} | ||
return str; | ||
} | ||
|
||
std::vector<std::string> split(const std::string& _str, | ||
const std::string& _delimiter) { | ||
auto str = _str; | ||
size_t pos = 0; | ||
std::vector<std::string> result; | ||
while ((pos = str.find(_delimiter)) != std::string::npos) { | ||
result.emplace_back(str.substr(0, pos)); | ||
str.erase(0, pos + _delimiter.length()); | ||
} | ||
result.emplace_back(std::move(str)); | ||
return result; | ||
} | ||
|
||
std::string to_camel_case(const std::string& _str) { | ||
std::string result; | ||
bool capitalize = false; | ||
for (const char ch : _str) { | ||
if (ch == '_') { | ||
capitalize = true; | ||
} else if (capitalize) { | ||
result.push_back(to_upper(ch)); | ||
capitalize = false; | ||
} else { | ||
result.push_back(ch); | ||
} | ||
} | ||
if (result.size() > 0) { | ||
result[0] = to_lower(result[0]); | ||
} | ||
return result; | ||
} | ||
|
||
std::string to_pascal_case(const std::string& _str) { | ||
auto result = to_camel_case("_" + _str); | ||
if (result.size() > 0) { | ||
result[0] = to_upper(result[0]); | ||
} | ||
return result; | ||
} | ||
|
||
} // namespace rfl::internal::strings |