]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
utf8: Rename `IsUTF8` to `utf8_valid` to match collectd's naming schema.
authorFlorian Forster <octo@collectd.org>
Fri, 22 Dec 2023 14:23:21 +0000 (15:23 +0100)
committerFlorian Forster <octo@collectd.org>
Thu, 28 Dec 2023 08:53:22 +0000 (09:53 +0100)
src/utils/utf8/utf8.c
src/utils/utf8/utf8.h
src/utils/utf8/utf8_test.c

index 25d2c1eb728de805f24ae940264c5dcd31491b89..4b9ec4b77db5bb956f0f6c837a557ec1895b3b5a 100644 (file)
@@ -56,7 +56,7 @@ static uint32_t decode(uint32_t *state, uint32_t *codep, uint32_t byte) {
   return *state;
 }
 
-int IsUTF8(uint8_t *s) {
+int utf8_valid(uint8_t *s) {
   uint32_t codepoint, state = 0;
 
   while (*s)
index a392f308279883af4674c7299c784d60e3d1615a..a7331b95a3903288d243d826ed5b9b8ae75d25f3 100644 (file)
@@ -25,6 +25,6 @@
 
 #include "collectd.h"
 
-int IsUTF8(uint8_t *s);
+int utf8_valid(uint8_t *s);
 
 #endif
index d8b99e2c7fc01fb666d1a035d105530f3a270bc5..35702a78c5386e59a092f977ea4b54acfb20f00a 100644 (file)
 #include "utils/common/common.h"
 #include "utils/utf8/utf8.h"
 
-DEF_TEST(IsUTF8) {
+DEF_TEST(utf8_valid) {
   struct {
     char const *name;
     char *input;
     bool want;
   } cases[] = {
-    {
-        .name = "simple string",
-        .input = "Hello, World!",
-        .want = true,
-    },
-    {
-        .name = "empty string",
-        .input = "",
-        .want = true,
-    },
-    {
-        .name = "The greek work \"kosme\"",
-        .input = (char[]){0xce, 0xba, 0xe1, 0xbd, 0xb9, 0xcf, 0x83, 0xce, 0xbc,
-                          0xce, 0xb5, 0},
-        .want = true,
-    },
-    {
-        .name = "First possible sequence of three bytes",
-        .input = (char[]){0xe0, 0xa0, 0x80, 0},
-        .want = true,
-    },
-    {
-        .name = "First possible sequence of four bytes",
-        .input = (char[]){0xf0, 0x90, 0x80, 0x80, 0},
-        .want = true,
-    },
-    {
-        .name = "U-0000D7F",
-        .input = (char[]){0xed, 0x9f, 0xbf, 0},
-        .want = true,
-    },
-    {
-        .name = "0xFE (invalid byte)",
-        .input = (char[]){'H', 0xfe, 'l', 'l', 'o', 0},
-        .want = false,
-    },
-    {
-        .name = "0xFF (invalid byte)",
-        .input = (char[]){'C', 'o', 0xff, 'e', 'e', 0},
-        .want = false,
-    },
-    {
-        .name = "Continuation byte at end of string",
-        .input = (char[]){0xce, 0xba, 0xe1, 0xbd, 0xb9, 0xcf, 0x83, 0xce, 0xbc,
-                          0xce, 0},
-        .want = false,
-    },
-    {
-        .name = "U+002F (overlong ASCII character, 2 bytes)",
-        .input = (char[]){0xc0, 0xaf, 0},
-        .want = false,
-    },
-    {
-        .name = "U+002F (overlong ASCII character, 3 bytes)",
-        .input = (char[]){0xe0, 0x80, 0xaf, 0},
-        .want = false,
-    },
+      {
+          .name = "simple string",
+          .input = "Hello, World!",
+          .want = true,
+      },
+      {
+          .name = "empty string",
+          .input = "",
+          .want = true,
+      },
+      {
+          .name = "The greek work \"kosme\"",
+          .input = (char[]){0xce, 0xba, 0xe1, 0xbd, 0xb9, 0xcf, 0x83, 0xce,
+                            0xbc, 0xce, 0xb5, 0},
+          .want = true,
+      },
+      {
+          .name = "First possible sequence of three bytes",
+          .input = (char[]){0xe0, 0xa0, 0x80, 0},
+          .want = true,
+      },
+      {
+          .name = "First possible sequence of four bytes",
+          .input = (char[]){0xf0, 0x90, 0x80, 0x80, 0},
+          .want = true,
+      },
+      {
+          .name = "U-0000D7F",
+          .input = (char[]){0xed, 0x9f, 0xbf, 0},
+          .want = true,
+      },
+      {
+          .name = "0xFE (invalid byte)",
+          .input = (char[]){'H', 0xfe, 'l', 'l', 'o', 0},
+          .want = false,
+      },
+      {
+          .name = "0xFF (invalid byte)",
+          .input = (char[]){'C', 'o', 0xff, 'e', 'e', 0},
+          .want = false,
+      },
+      {
+          .name = "Continuation byte at end of string",
+          .input = (char[]){0xce, 0xba, 0xe1, 0xbd, 0xb9, 0xcf, 0x83, 0xce,
+                            0xbc, 0xce, 0},
+          .want = false,
+      },
+      {
+          .name = "U+002F (overlong ASCII character, 2 bytes)",
+          .input = (char[]){0xc0, 0xaf, 0},
+          .want = false,
+      },
+      {
+          .name = "U+002F (overlong ASCII character, 3 bytes)",
+          .input = (char[]){0xe0, 0x80, 0xaf, 0},
+          .want = false,
+      },
   };
 
   for (size_t i = 0; i < STATIC_ARRAY_SIZE(cases); i++) {
     printf("Case #%zu: %s\n", i, cases[i].name);
-    EXPECT_EQ_INT(cases[i].want, IsUTF8((uint8_t *)cases[i].input));
+    EXPECT_EQ_INT(cases[i].want, utf8_valid((uint8_t *)cases[i].input));
   }
   return 0;
 }
 
 int main(void) {
-  RUN_TEST(IsUTF8);
+  RUN_TEST(utf8_valid);
 
   END_TEST;
 }