From d934cfb48f767fb38514efc3d8dade4c54f1c066 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 3 Jan 2024 17:29:22 +0100 Subject: [PATCH] Added support for filtering UTF-8 strings using UTF8-CPP --- CMakeLists.txt | 1 + es-core/src/utils/StringUtil.cpp | 7 +++++++ es-core/src/utils/StringUtil.h | 3 +++ 3 files changed, 11 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0dda9b4cc..02a2b25b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -449,6 +449,7 @@ set(COMMON_INCLUDE_DIRS ${CURL_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/external/lunasvg/include ${CMAKE_CURRENT_SOURCE_DIR}/external/rapidjson/include ${CMAKE_CURRENT_SOURCE_DIR}/external/rlottie/inc + ${CMAKE_CURRENT_SOURCE_DIR}/external/utfcpp/source ${CMAKE_CURRENT_SOURCE_DIR}/es-core/src ${CMAKE_CURRENT_SOURCE_DIR}/es-pdf-converter/src) diff --git a/es-core/src/utils/StringUtil.cpp b/es-core/src/utils/StringUtil.cpp index eb4707200..756ceafb3 100644 --- a/es-core/src/utils/StringUtil.cpp +++ b/es-core/src/utils/StringUtil.cpp @@ -569,6 +569,13 @@ namespace Utils return line; } + std::string filterUtf8(const std::string& stringArg) + { + std::string tempString; + utf8::replace_invalid(stringArg.begin(), stringArg.end(), back_inserter(tempString)); + return tempString; + } + std::string trim(const std::string& stringArg) { std::string trimString = stringArg; diff --git a/es-core/src/utils/StringUtil.h b/es-core/src/utils/StringUtil.h index 67ef426cb..4284cab3f 100644 --- a/es-core/src/utils/StringUtil.h +++ b/es-core/src/utils/StringUtil.h @@ -14,6 +14,8 @@ #include #include +#include "utf8.h" + namespace Utils { namespace String @@ -28,6 +30,7 @@ namespace Utils std::string toLower(const std::string& stringArg); std::string toUpper(const std::string& stringArg); std::string toCapitalized(const std::string& stringArg); + std::string filterUtf8(const std::string& stringArg); std::string trim(const std::string& stringArg); std::string replace(const std::string& stringArg, const std::string& from,