From patchwork Thu Aug 13 09:57:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 9309 X-Patchwork-Delegate: niklas.soderlund@ragnatech.se Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 2C89FBD87D for ; Thu, 13 Aug 2020 09:57:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A728D6138F; Thu, 13 Aug 2020 11:57:41 +0200 (CEST) Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 96674603D9 for ; Thu, 13 Aug 2020 11:57:39 +0200 (CEST) X-Halon-ID: 6b0f1488-dd4b-11ea-92dc-005056917a89 Authorized-sender: niklas.soderlund@fsdn.se Received: from bismarck.berto.se (p54ac52a8.dip0.t-ipconnect.de [84.172.82.168]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id 6b0f1488-dd4b-11ea-92dc-005056917a89; Thu, 13 Aug 2020 11:57:37 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Thu, 13 Aug 2020 11:57:21 +0200 Message-Id: <20200813095726.3497193-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200813095726.3497193-1-niklas.soderlund@ragnatech.se> References: <20200813095726.3497193-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/7] libcamera: utils: Add method to strip Unicode characters X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add method that strips non-ASCII characters from a string. Signed-off-by: Niklas Söderlund --- include/libcamera/internal/utils.h | 2 ++ src/libcamera/utils.cpp | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/libcamera/internal/utils.h b/include/libcamera/internal/utils.h index 45cd6f120c51586b..5bfd2a8782dbd623 100644 --- a/include/libcamera/internal/utils.h +++ b/include/libcamera/internal/utils.h @@ -197,6 +197,8 @@ private: details::StringSplitter split(const std::string &str, const std::string &delim); +std::string stripUnicode(const std::string &str); + std::string libcameraBuildPath(); std::string libcameraSourcePath(); diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp index 615df46ac142a2a9..041fdc91a0a35277 100644 --- a/src/libcamera/utils.cpp +++ b/src/libcamera/utils.cpp @@ -342,6 +342,27 @@ details::StringSplitter split(const std::string &str, const std::string &delim) return details::StringSplitter(str, delim); } +/** + * \brief Strip all Unicode characters from a string + * \param[in] str The string to strip + * + * Strip all non-ASCII characters form a string. An Unicode character that spans + * multiple bytes (and therefor is not also an ASCII character) may be + * identified by the fact that its most significant bit is always set. + * + * \todo When switching to C++ 20 use std::remove_if. + * + * \return An ASCII string + */ +std::string stripUnicode(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 *