From patchwork Mon Aug 10 16:43:01 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: 9280 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 15518BD87C for ; Mon, 10 Aug 2020 16:43:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D958C610E6; Mon, 10 Aug 2020 18:43:24 +0200 (CEST) Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7854460DCA for ; Mon, 10 Aug 2020 18:43:22 +0200 (CEST) X-Halon-ID: 99ec37c1-db28-11ea-a39b-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p54ac52a8.dip0.t-ipconnect.de [84.172.82.168]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 99ec37c1-db28-11ea-a39b-005056917f90; Mon, 10 Aug 2020 18:43:21 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Mon, 10 Aug 2020 18:43:01 +0200 Message-Id: <20200810164306.1472692-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200810164306.1472692-1-niklas.soderlund@ragnatech.se> References: <20200810164306.1472692-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 *