mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
Minor refactor
This commit is contained in:
parent
5bd78c09ad
commit
73595cd558
2 changed files with 25 additions and 37 deletions
|
|
@ -6,17 +6,11 @@
|
|||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
using std::stringstream;
|
||||
using std::wstring;
|
||||
using std::wstringstream;
|
||||
|
||||
wstring util::lfill(wstring s, uint length, wchar_t c) {
|
||||
std::wstring util::lfill(std::wstring s, uint length, wchar_t c) {
|
||||
if (s.length() >= length) {
|
||||
return s;
|
||||
}
|
||||
wstringstream ss;
|
||||
std::wstringstream ss;
|
||||
for (uint i = 0; i < length-s.length(); i++) {
|
||||
ss << c;
|
||||
}
|
||||
|
|
@ -24,11 +18,11 @@ wstring util::lfill(wstring s, uint length, wchar_t c) {
|
|||
return ss.str();
|
||||
}
|
||||
|
||||
wstring util::rfill(wstring s, uint length, wchar_t c) {
|
||||
std::wstring util::rfill(std::wstring s, uint length, wchar_t c) {
|
||||
if (s.length() >= length) {
|
||||
return s;
|
||||
}
|
||||
wstringstream ss;
|
||||
std::wstringstream ss;
|
||||
ss << s;
|
||||
for (uint i = 0; i < length-s.length(); i++) {
|
||||
ss << c;
|
||||
|
|
@ -103,8 +97,8 @@ extern uint32_t util::decode_utf8(uint& size, const char* chr) {
|
|||
return code;
|
||||
}
|
||||
|
||||
string util::wstr2str_utf8(const wstring ws) {
|
||||
vector<char> chars;
|
||||
std::string util::wstr2str_utf8(const std::wstring ws) {
|
||||
std::vector<char> chars;
|
||||
char buffer[4];
|
||||
for (wchar_t wc : ws) {
|
||||
uint size = encode_utf8((uint)wc, (ubyte*)buffer);
|
||||
|
|
@ -112,21 +106,21 @@ string util::wstr2str_utf8(const wstring ws) {
|
|||
chars.push_back(buffer[i]);
|
||||
}
|
||||
}
|
||||
return string(chars.data(), chars.size());
|
||||
return std::string(chars.data(), chars.size());
|
||||
}
|
||||
|
||||
wstring util::str2wstr_utf8(const string s) {
|
||||
vector<wchar_t> chars;
|
||||
std::wstring util::str2wstr_utf8(const std::string s) {
|
||||
std::vector<wchar_t> chars;
|
||||
size_t pos = 0;
|
||||
uint size = 0;
|
||||
while (pos < s.length()) {
|
||||
chars.push_back(decode_utf8(size, &s.at(pos)));
|
||||
pos += size;
|
||||
}
|
||||
return wstring(chars.data(), chars.size());
|
||||
return std::wstring(chars.data(), chars.size());
|
||||
}
|
||||
|
||||
bool util::is_integer(string text) {
|
||||
bool util::is_integer(std::string text) {
|
||||
for (char c : text) {
|
||||
if (c < '0' || c > '9')
|
||||
return false;
|
||||
|
|
@ -134,7 +128,7 @@ bool util::is_integer(string text) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool util::is_integer(wstring text) {
|
||||
bool util::is_integer(std::wstring text) {
|
||||
for (wchar_t c : text) {
|
||||
if (c < L'0' || c > L'9')
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue