From patchwork Fri Sep 25 15:07:38 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: 9831 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 9DA27C3B5B for ; Fri, 25 Sep 2020 15:08:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 62C9D631D2; Fri, 25 Sep 2020 17:08:01 +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 1F09062FD8 for ; Fri, 25 Sep 2020 17:07:58 +0200 (CEST) X-Halon-ID: e4d84431-ff40-11ea-a39b-005056917f90 Authorized-sender: niklas.soderlund@fsdn.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 e4d84431-ff40-11ea-a39b-005056917f90; Fri, 25 Sep 2020 17:07:57 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 25 Sep 2020 17:07:38 +0200 Message-Id: <20200925150743.1822226-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200925150743.1822226-1-niklas.soderlund@ragnatech.se> References: <20200925150743.1822226-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 2/7] libcamera: utils: Add method to remove non-ASCII 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 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 --- * Changes since v4 - Update documentation. * Changes since v3 - Fix spelling in comment. - Rename to toAscii() --- include/libcamera/internal/utils.h | 2 ++ src/libcamera/utils.cpp | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/libcamera/internal/utils.h b/include/libcamera/internal/utils.h index a1b644b0345bdb48..ebb2c4038e196f05 100644 --- a/include/libcamera/internal/utils.h +++ b/include/libcamera/internal/utils.h @@ -190,6 +190,8 @@ private: details::StringSplitter split(const std::string &str, const std::string &delim); +std::string toAscii(const std::string &str); + std::string libcameraBuildPath(); std::string libcameraSourcePath(); diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp index a5232902191eec85..551658323700f00f 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 charachters from a string + * \param[in] str The string to strip + * + * Remove all non-ASCII characters form a string. + * + * \return An ASCII string + */ +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 *