From b33ec3433194b50f2f6b8e4038c321b6f3293798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Mon, 10 Aug 2020 17:32:01 +0200 Subject: libcamera: utils: Add method to remove non-ASCII characters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add method that removes non-ASCII characters from a string. Signed-off-by: Niklas Söderlund Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi Reviewed-by: Umang Jain --- src/libcamera/utils.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/libcamera/utils.cpp') diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp index a5232902..da85c9c2 100644 --- a/src/libcamera/utils.cpp +++ b/src/libcamera/utils.cpp @@ -334,6 +334,23 @@ details::StringSplitter split(const std::string &str, const std::string &delim) return details::StringSplitter(str, delim); } +/** + * \brief Remove any non-ASCII characters from a string + * \param[in] str The string to strip + * + * Remove all non-ASCII characters from a string. + * + * \return A string equal to \a str stripped out of all non-ASCII characters + */ +std::string toAscii(const std::string &str) +{ + std::string ret; + for (const char &c : str) + if (!(c & 0x80)) + ret += c; + return ret; +} + /** * \brief Check if libcamera is installed or not * -- cgit v1.2.1