stringutil: text case convert functions
This commit is contained in:
parent
1addf869ec
commit
c9da6b9a0c
@ -104,7 +104,6 @@ void ContentLoader::fixPackIndices() {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: add basic validation and logging
|
||||
void ContentLoader::loadBlock(Block& def, std::string name, fs::path file) {
|
||||
auto root = files::read_json(file);
|
||||
|
||||
|
||||
@ -331,6 +331,7 @@ static void pick_block(ContentIndices* indices, Chunks* chunks, Player* player,
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: refactor this nesting nest
|
||||
void PlayerController::updateInteraction(){
|
||||
auto indices = level->content->getIndices();
|
||||
Chunks* chunks = level->chunks.get();
|
||||
@ -374,7 +375,6 @@ void PlayerController::updateInteraction(){
|
||||
uint8_t states = determine_rotation(def, norm, camera->dir);
|
||||
|
||||
if (lclick && !input.shift && item->rt.funcsset.on_block_break_by) {
|
||||
// TODO: move scripting to interaction callbacks
|
||||
if (scripting::on_item_break_block(player.get(), item, x, y, z))
|
||||
return;
|
||||
}
|
||||
@ -428,7 +428,6 @@ void PlayerController::updateInteraction(){
|
||||
chunks->set(x, y, z, chosenBlock, states);
|
||||
lighting->onBlockSet(x,y,z, chosenBlock);
|
||||
if (def->rt.funcsset.onplaced) {
|
||||
// TODO: move scripting to interaction callbacks
|
||||
scripting::on_block_placed(player.get(), def, x, y, z);
|
||||
}
|
||||
blocksController->updateSides(x, y, z);
|
||||
|
||||
@ -292,6 +292,49 @@ double util::parse_double(const std::string& str, size_t offset, size_t len) {
|
||||
return parse_double(str.substr(offset, len));
|
||||
}
|
||||
|
||||
std::wstring util::lower_case(const std::wstring& str) {
|
||||
std::wstring result = str;
|
||||
static const std::locale loc("");
|
||||
for (uint i = 0; i < result.length(); i++) {
|
||||
result[i] = static_cast<wchar_t>(std::tolower(str[i], loc));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring util::upper_case(const std::wstring& str) {
|
||||
std::wstring result = str;
|
||||
static const std::locale loc("");
|
||||
for (uint i = 0; i < result.length(); i++) {
|
||||
result[i] = static_cast<wchar_t>(std::toupper(str[i], loc));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring util::capitalized(const std::wstring& str) {
|
||||
if (str.empty())
|
||||
return str;
|
||||
static const std::locale loc("");
|
||||
return std::wstring({static_cast<wchar_t>(std::toupper(str[0], loc))}) + str.substr(1);
|
||||
}
|
||||
|
||||
std::wstring util::pascal_case(const std::wstring& str) {
|
||||
if (str.empty())
|
||||
return str;
|
||||
static const std::locale loc("");
|
||||
std::wstring result = str;
|
||||
bool upper = true;
|
||||
for (uint i = 0; i < result.length(); i++) {
|
||||
auto c = result[i];
|
||||
if (c <= ' ') {
|
||||
upper = true;
|
||||
} else if (upper) {
|
||||
result[i] = static_cast<wchar_t>(std::toupper(str[i], loc));
|
||||
upper = false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// @brief Split string by delimiter
|
||||
/// @param str source string
|
||||
/// @param delimiter split delimiter size
|
||||
|
||||
@ -34,6 +34,11 @@ namespace util {
|
||||
extern double parse_double(const std::string& str);
|
||||
extern double parse_double(const std::string& str, size_t offset, size_t len);
|
||||
|
||||
extern std::wstring lower_case(const std::wstring& str);
|
||||
extern std::wstring upper_case(const std::wstring& str);
|
||||
extern std::wstring capitalized(const std::wstring& str);
|
||||
extern std::wstring pascal_case(const std::wstring& str);
|
||||
|
||||
extern std::vector<std::string> split(const std::string& str, char delimiter);
|
||||
extern std::vector<std::wstring> split(const std::wstring& str, char delimiter);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user