add util::crop_utf8 (stringutil)

This commit is contained in:
MihailRis
2024-08-29 15:39:14 +03:00
parent f2b9d0620a
commit f8d0a4f4c7
3 changed files with 38 additions and 0 deletions
+15
View File
@@ -17,8 +17,23 @@ namespace util {
uint encode_utf8(uint32_t c, ubyte* bytes);
uint32_t decode_utf8(uint& size, const char* bytes);
/// @brief Encode raw wstring to UTF-8
/// @param ws source raw wstring
/// @return new UTF-8 encoded string
std::string wstr2str_utf8(const std::wstring& ws);
/// @brief Decode UTF
/// @param s source encoded string
/// @return new raw decoded string
std::wstring str2wstr_utf8(const std::string& s);
/// @brief Calculated length of UTF-8 encoded string that fits into maxSize
/// @param s source UTF-8 encoded string view
/// @param maxSize max encoded string length after crop
/// @return cropped string size (less or equal to maxSize)
size_t crop_utf8(std::string_view s, size_t maxSize);
bool is_integer(const std::string& text);
bool is_integer(const std::wstring& text);
bool is_valid_filename(const std::wstring& name);