From mboxrd@z Thu Jan 1 00:00:00 1970 From: Heinrich Schuchardt Date: Wed, 24 Apr 2019 18:24:44 +0200 Subject: [U-Boot] [PATCH v2 01/11] lib: charset: add u16_strcmp() In-Reply-To: <20190424063045.14443-2-takahiro.akashi@linaro.org> References: <20190424063045.14443-1-takahiro.akashi@linaro.org> <20190424063045.14443-2-takahiro.akashi@linaro.org> Message-ID: <2751c0b5-94b7-9080-c14a-fb4eff9f9c2e@gmx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 4/24/19 8:30 AM, AKASHI Takahiro wrote: > u16 version of strcmp() > > AUTHER: Patrick Wildt %s/AUTHER/Author/ > Signed-off-by: AKASHI Takahiro > --- > include/charset.h | 5 +++++ > lib/charset.c | 10 ++++++++++ > 2 files changed, 15 insertions(+) > > diff --git a/include/charset.h b/include/charset.h > index 65087f76d1fc..747a9b376c03 100644 > --- a/include/charset.h > +++ b/include/charset.h > @@ -166,6 +166,11 @@ s32 utf_to_lower(const s32 code); > */ > s32 utf_to_upper(const s32 code); > > +/* > + * u16_strcmp() - strcmp() for u16 strings > + */ > +int u16_strcmp(const u16 *s1, const u16 *s2); > + > /** > * u16_strlen - count non-zero words > * > diff --git a/lib/charset.c b/lib/charset.c > index 5e349ed5ee45..4a25ac0bdb9c 100644 > --- a/lib/charset.c > +++ b/lib/charset.c > @@ -335,6 +335,16 @@ s32 utf_to_upper(const s32 code) > return ret; > } > > +int u16_strcmp(const u16 *s1, const u16 *s2) > +{ > + while (*s1 == *s2++) > + if (*s1++ == 0) > + return (0); > + --s2; for (;*s1 == *s2; ++s1, ++s2) if (!s1) return 0; does the same job without superfluous increment/decrement. > + > + return (*(uint16_t *)s1 - *(uint16_t *)s2); Why would you use both u16 and uint16_t in the same function? You can do without any conversion here. How about #define u16_strcmp(s1, s2) u16_strncmp(s1, s2, SIZE_MAX) like we do for the other string functions? Best regards Heinrich > +} > + > size_t u16_strlen(const u16 *in) > { > size_t i; >