utils: utf8: change utf8_count_chars return to int
Change utf8_count_chars return type to int and drop thesys/types.h, this way the function does not depend on posix types. Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
This commit is contained in:
committed by
Anas Nashif
parent
8366365c03
commit
fbe0c9feb9
@@ -15,7 +15,6 @@
|
||||
#define ZEPHYR_INCLUDE_SYS_UTIL_UFT8_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -81,7 +80,7 @@ char *utf8_lcpy(char *dst, const char *src, size_t n);
|
||||
* @return Number of UTF-8 characters in @p s on success or (negative) error code
|
||||
* otherwise.
|
||||
*/
|
||||
ssize_t utf8_count_chars(const char *s);
|
||||
int utf8_count_chars(const char *s);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <string.h>
|
||||
#include <zephyr/sys/__assert.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <zephyr/sys/util_utf8.h>
|
||||
|
||||
#define ASCII_CHAR 0x7F
|
||||
@@ -84,9 +83,9 @@ char *utf8_lcpy(char *dst, const char *src, size_t n)
|
||||
return dst;
|
||||
}
|
||||
|
||||
ssize_t utf8_count_chars(const char *s)
|
||||
int utf8_count_chars(const char *s)
|
||||
{
|
||||
ssize_t count = 0;
|
||||
int count = 0;
|
||||
const char *p = s; /* getting a pointer to increment */
|
||||
|
||||
while (*p != '\0') {
|
||||
|
||||
@@ -1008,7 +1008,7 @@ ZTEST(util, test_utf8_lcpy_null_termination)
|
||||
ZTEST(util, test_utf8_count_chars_ASCII)
|
||||
{
|
||||
const char *test_str = "I have 15 char.";
|
||||
ssize_t count = utf8_count_chars(test_str);
|
||||
int count = utf8_count_chars(test_str);
|
||||
|
||||
zassert_equal(count, 15, "Failed to count ASCII");
|
||||
}
|
||||
@@ -1016,7 +1016,7 @@ ZTEST(util, test_utf8_count_chars_ASCII)
|
||||
ZTEST(util, test_utf8_count_chars_non_ASCII)
|
||||
{
|
||||
const char *test_str = "Hello دنیا!🌍";
|
||||
ssize_t count = utf8_count_chars(test_str);
|
||||
int count = utf8_count_chars(test_str);
|
||||
|
||||
zassert_equal(count, 12, "Failed to count non-ASCII");
|
||||
}
|
||||
@@ -1024,8 +1024,8 @@ ZTEST(util, test_utf8_count_chars_non_ASCII)
|
||||
ZTEST(util, test_utf8_count_chars_invalid_utf)
|
||||
{
|
||||
const char test_str[] = { (char)0x80, 0x00 };
|
||||
ssize_t count = utf8_count_chars(test_str);
|
||||
ssize_t expected_result = -EINVAL;
|
||||
int count = utf8_count_chars(test_str);
|
||||
int expected_result = -EINVAL;
|
||||
|
||||
zassert_equal(count, expected_result, "Failed to detect invalid UTF");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user