[libcamera-devel] [PATCH v5 2/7] libcamera: utils: Add method to remove non-ASCII characters

Umang Jain email at uajain.com
Mon Sep 28 14:43:34 CEST 2020


Hi Niklas,

Thanks for this work.

Apart from nits  already pointed out:
Reviewed-by: Umang Jain <email at uajain.com>

This patch will also help me sanitize EXIF_FORMAT_ASCII strings in the 
android layer.

On 9/25/20 8:37 PM, Niklas Söderlund wrote:
> Add method that removes non-ASCII characters from a string.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
> Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
> ---
> * 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
>    *



More information about the libcamera-devel mailing list