]> Kevux Git Server - fll/commitdiff
Update: Improve error handling and add F_utf_fragment to generic FLL error printing.
authorKevin Day <thekevinday@gmail.com>
Fri, 10 Dec 2021 02:39:34 +0000 (20:39 -0600)
committerKevin Day <thekevinday@gmail.com>
Fri, 10 Dec 2021 02:39:34 +0000 (20:39 -0600)
level_2/fll_error/c/private-error.c
level_3/utf8/c/private-print.c
level_3/utf8/c/private-print.h
level_3/utf8/c/private-utf8.c
level_3/utf8/c/private-utf8_binary.c
level_3/utf8/c/private-utf8_codepoint.c

index 7cd587449606c5bffbfa12edd95117e89bcb7812..a8fcae68782bbe77c50e1aa8588ed94a5bd4d24f 100644 (file)
@@ -108,7 +108,23 @@ extern "C" {
       if (print.verbosity != f_console_verbosity_quiet) {
         flockfile(print.to.stream);
 
-        fl_print_format("%c%[%SInvalid UTF-8 character", print.to.stream, f_string_eol_s[0], print.context, print.prefix);
+        fl_print_format("%c%[%SInvalid UTF-8 character found", print.to.stream, f_string_eol_s[0], print.context, print.prefix);
+
+        private_fll_error_print_function(print, function);
+
+        fl_print_format(".%]%c", print.to.stream, print.context, f_string_eol_s[0]);
+
+        funlockfile(print.to.stream);
+      }
+
+      return F_false;
+    }
+
+    if (status == F_utf_fragment) {
+      if (print.verbosity != f_console_verbosity_quiet) {
+        flockfile(print.to.stream);
+
+        fl_print_format("%c%[%SInvalid UTF-8 character (Fragment) found", print.to.stream, f_string_eol_s[0], print.context, print.prefix);
 
         private_fll_error_print_function(print, function);
 
index af811da5dd80434e1c49fcba1db8fc51fa422afe..23b75c575448959f289ef797ff33731ed1c957ce 100644 (file)
@@ -53,14 +53,48 @@ extern "C" {
 
     if (data->main->error.verbosity == f_console_verbosity_quiet) return;
 
-    fl_print_format("%c%[%SFailed to decode character '%]", data->main->error.to.stream, f_string_eol_s[0], data->main->context.set.error, data->main->error.prefix, data->main->context.set.error);
-    fl_print_format("%[%r%]", data->main->error.to.stream, data->main->context.set.notable, character, data->main->context.set.notable);
-    fl_print_format("%[', error status code%] ", data->main->error.to.stream, data->main->context.set.error, data->main->context.set.error, f_string_eol_s[0]);
-    fl_print_format("%[%ui%]", data->main->error.to.stream, data->main->context.set.notable, F_status_set_fine(status), data->main->context.set.notable);
-    fl_print_format("%[.%]%c", data->main->error.to.stream, data->main->context.set.error, data->main->context.set.error, f_string_eol_s[0]);
+    fl_print_format("%c%[%SFailed to decode character code '%]", data->main->error.to.stream, f_string_eol_s[0], data->main->context.set.error, data->main->error.prefix, data->main->context.set.error);
+
+    if (character.used) {
+      fl_print_format("%[0x", data->main->error.to.stream, data->main->context.set.notable);
+
+      for (uint8_t i = 0; i < character.used; ++i) {
+        fl_print_format("%02_uii", data->main->error.to.stream, (uint8_t) character.string[i]);
+      } // for
+
+      fl_print_format("%]", data->main->error.to.stream, data->main->context.set.notable);
+    }
+
+    if (F_status_set_fine(status) == F_utf) {
+      fl_print_format("%[', not a valid UTF-8 character sequence.%]%c", data->main->error.to.stream, data->main->context.set.error, data->main->context.set.error, f_string_eol_s[0]);
+    }
+    else {
+      fl_print_format("%[', error status code%] ", data->main->error.to.stream, data->main->context.set.error, data->main->context.set.error, f_string_eol_s[0]);
+      fl_print_format("%[%ui%]", data->main->error.to.stream, data->main->context.set.notable, F_status_set_fine(status), data->main->context.set.notable);
+      fl_print_format("%[.%]%c", data->main->error.to.stream, data->main->context.set.error, data->main->context.set.error, f_string_eol_s[0]);
+    }
   }
 #endif // _di_utf8_print_error_decode_
 
+#ifndef _di_utf8_print_error_encode_
+  void utf8_print_error_encode(utf8_data_t * const data, const f_status_t status, const uint32_t codepoint) {
+
+    if (data->main->error.verbosity == f_console_verbosity_quiet) return;
+
+    fl_print_format("%c%[%SFailed to encode Unicode codepoint '%]", data->main->error.to.stream, f_string_eol_s[0], data->main->context.set.error, data->main->error.prefix, data->main->context.set.error);
+    fl_print_format("%[U+%_U%]", data->main->error.to.stream, data->main->context.set.notable, codepoint, data->main->context.set.notable);
+
+    if (F_status_set_fine(status) == F_utf) {
+      fl_print_format("%[', not a valid Unicode codepoint.%]%c", data->main->error.to.stream, data->main->context.set.error, data->main->context.set.error, f_string_eol_s[0]);
+    }
+    else {
+      fl_print_format("%[', error status code%] ", data->main->error.to.stream, data->main->context.set.error, data->main->context.set.error, f_string_eol_s[0]);
+      fl_print_format("%[%ui%]", data->main->error.to.stream, data->main->context.set.notable, F_status_set_fine(status), data->main->context.set.notable);
+      fl_print_format("%[.%]%c", data->main->error.to.stream, data->main->context.set.error, data->main->context.set.error, f_string_eol_s[0]);
+    }
+  }
+#endif // _di_utf8_print_error_encode_
+
 #ifndef _di_utf8_print_error_no_from_
   void utf8_print_error_no_from(utf8_data_t * const data) {
 
index 8b0049ec42bd8916de6ff20d670f6e4c6db34286..bcf1bcdc42fa12834d5b03cdf068edb879080199 100644 (file)
@@ -58,13 +58,25 @@ extern "C" {
  * @param data
  *   The program data.
  * @param character
- *   The character block to print.
+ *   The character that is invalid.
  */
 #ifndef _di_utf8_print_error_decode_
   extern void utf8_print_error_decode(utf8_data_t * const data, const f_status_t status, const f_string_static_t character) F_attribute_visibility_internal_d;
 #endif // _di_utf8_print_error_decode_
 
 /**
+ * Print error message when attempt to encode the character failed.
+ *
+ * @param data
+ *   The program data.
+ * @param codepoint
+ *   The codepoint that is invalid.
+ */
+#ifndef _di_utf8_print_error_encode_
+  extern void utf8_print_error_encode(utf8_data_t * const data, const f_status_t status, const uint32_t codepoint) F_attribute_visibility_internal_d;
+#endif // _di_utf8_print_error_encode_
+
+/**
  * Print error message for when no sources are provided.
  *
  * @param data
index ccee4d40d1f7ca3c48bffe80d9d4f6e9149fbdb0..89e3c3fd09798e2cde07ec70205cf82d5ae8dcf3 100644 (file)
@@ -57,6 +57,12 @@ extern "C" {
       else {
         status = utf8_detect_codepoint(data, current, &mode_codepoint);
 
+        if (F_status_is_error(status)) {
+          fll_error_print(data->main->error, F_status_set_fine(status), "utf8_detect_codepoint", F_true);
+
+          break;
+        }
+
         if (F_status_is_fine(status) && status != F_next) {
           status = utf8_convert_codepoint(data, current, &mode_codepoint);
         }
index aa7477243d88bacbf0226d8310d57bd04dc14749..dae939cb887509138ce21b3498d22c9aa69b4f14 100644 (file)
@@ -128,7 +128,7 @@ extern "C" {
     } while (F_status_is_fine(status) && status != F_signal);
 
     // Handle last (incomplete) character when the buffer ended before the character is supposed to end.
-    if (status != F_signal && next == F_false) {
+    if (F_status_is_error_not(status) && status != F_signal && next == F_false) {
       character.used = j;
 
       if (data->mode & utf8_mode_from_binary_d) {
index 87e73bd9a2356fd5c70972a5adc77aa16ebe1af0..79c12b95d8765d4f595a5d06e4bcdcb10402d8f6 100644 (file)
@@ -59,7 +59,7 @@ extern "C" {
           status = f_utf_unicode_from(codepoint, 4, &character.string);
 
           if (F_status_is_error(status)) {
-            utf8_print_error_decode(data, status, character);
+            utf8_print_error_encode(data, status, codepoint);
           }
           else {
             status = F_none;
@@ -251,7 +251,7 @@ extern "C" {
     } while (F_status_is_fine(status) && status != F_signal);
 
     // Handle last (incomplete) character when the buffer ended before the character is supposed to end.
-    if (status != F_signal && next == F_false) {
+    if (F_status_is_error_not(status) && status != F_signal && next == F_false) {
       character.used = j;
 
       if (data->mode & utf8_mode_from_binary_d) {