Message ID | 20200925150743.1822226-3-niklas.soderlund@ragnatech.se |
---|---|
State | Accepted |
Headers | show |
Series |
|
Related | show |
Hi Niklas, On Fri, Sep 25, 2020 at 05:07:38PM +0200, Niklas Söderlund wrote: > Add method that removes non-ASCII characters from a string. > > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> > Reviewed-by: Kieran Bingham <kieran.bingham@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 s/charachters/characters > + * \param[in] str The string to strip > + * > + * Remove all non-ASCII characters form a string. s/form/from > + * > + * \return An ASCII string \return A string equal to \a str stripped out of all non-ASCII characters ? nits apart Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Thanks j > + */ > +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 > * > -- > 2.28.0 > > _______________________________________________ > libcamera-devel mailing list > libcamera-devel@lists.libcamera.org > https://lists.libcamera.org/listinfo/libcamera-devel
Hi Niklas, Thanks for this work. Apart from nits already pointed out: Reviewed-by: Umang Jain <email@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@ragnatech.se> > Reviewed-by: Kieran Bingham <kieran.bingham@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 > *
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 *