From 3f7c905522c32905fa350a64558dbaa0c4c8b5ac Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 29 Mar 2023 23:52:18 -0500 Subject: [PATCH] Cleanup: Syntax in f_utf. --- level_0/f_utf/c/private-utf.c | 30 +++++++---------------------- level_0/f_utf/c/utf/convert.c | 45 +++++++++++-------------------------------- 2 files changed, 18 insertions(+), 57 deletions(-) diff --git a/level_0/f_utf/c/private-utf.c b/level_0/f_utf/c/private-utf.c index 39da3c5..8eb9ba5 100644 --- a/level_0/f_utf/c/private-utf.c +++ b/level_0/f_utf/c/private-utf.c @@ -15,31 +15,20 @@ extern "C" { return F_none; } - if (macro_f_utf_byte_width_is(*sequence) == 1) { - return F_status_set_error(F_utf_fragment); - } - - if (macro_f_utf_byte_width_is(*sequence) > width_max) { - return F_status_set_error(F_complete_not_utf); - } + if (macro_f_utf_byte_width_is(*sequence) == 1) return F_status_set_error(F_utf_fragment); + if (macro_f_utf_byte_width_is(*sequence) > width_max) return F_status_set_error(F_complete_not_utf); *character_utf = macro_f_utf_char_t_from_char_1(sequence[0]); - if (macro_f_utf_byte_width_is(*sequence) < 2) { - return F_none; - } + if (macro_f_utf_byte_width_is(*sequence) < 2) return F_none; *character_utf |= macro_f_utf_char_t_from_char_2(sequence[1]); - if (macro_f_utf_byte_width_is(*sequence) == 2) { - return F_none; - } + if (macro_f_utf_byte_width_is(*sequence) == 2) return F_none; *character_utf |= macro_f_utf_char_t_from_char_3(sequence[2]); - if (macro_f_utf_byte_width_is(*sequence) == 3) { - return F_none; - } + if (macro_f_utf_byte_width_is(*sequence) == 3) return F_none; *character_utf |= macro_f_utf_char_t_from_char_4(sequence[3]); @@ -50,13 +39,8 @@ extern "C" { #if !defined(_di_f_utf_unicode_to_) || !defined(_di_f_utf_character_unicode_to_) f_status_t private_f_utf_character_unicode_to(const f_utf_char_t sequence, uint32_t *codepoint) { - if (macro_f_utf_char_t_width_is(sequence) == 1) { - return F_status_set_error(F_utf_fragment); - } - - if (private_f_utf_character_is_valid(sequence) == F_false) { - return F_status_set_error(F_utf_not); - } + if (macro_f_utf_char_t_width_is(sequence) == 1) return F_status_set_error(F_utf_fragment); + if (private_f_utf_character_is_valid(sequence) == F_false) return F_status_set_error(F_utf_not); // U+0000 -> U+007F (ASCII). if (macro_f_utf_char_t_width(sequence) == 1) { diff --git a/level_0/f_utf/c/utf/convert.c b/level_0/f_utf/c/utf/convert.c index c881e0d..6aabab5 100644 --- a/level_0/f_utf/c/utf/convert.c +++ b/level_0/f_utf/c/utf/convert.c @@ -12,13 +12,8 @@ extern "C" { if (!character_utf) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (macro_f_utf_byte_width_is(*character) > width_max) { - return F_status_set_error(F_failure); - } - - if (macro_f_utf_byte_width_is(*character) == 1) { - return F_status_set_error(F_utf_fragment); - } + if (macro_f_utf_byte_width_is(*character) > width_max) return F_status_set_error(F_failure); + if (macro_f_utf_byte_width_is(*character) == 1) return F_status_set_error(F_utf_fragment); return private_f_utf_char_to_character(character, width_max, character_utf); } @@ -33,9 +28,7 @@ extern "C" { #endif // _di_level_0_parameter_checking_ if (macro_f_utf_char_t_width_is(unicode)) { - if (macro_f_utf_char_t_width_is(unicode) == 1) { - return F_status_set_error(F_utf_fragment); - } + if (macro_f_utf_char_t_width_is(unicode) == 1) return F_status_set_error(F_utf_fragment); memcpy(*character, &unicode, sizeof(f_char_t) * macro_f_utf_char_t_width_is(unicode)); /*#if __BYTE_ORDER == __LITTLE_ENDIAN @@ -100,9 +93,7 @@ extern "C" { if (!character) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (unicode > 0x10ffff) { - return F_status_set_error(F_utf_not); - } + if (unicode > 0x10ffff) return F_status_set_error(F_utf_not); // U+0000 -> U+007F. if (unicode < 0x80) { @@ -184,9 +175,7 @@ extern "C" { if (!string[i]) continue; // Only ASCII character numbers are allowed to represent - if (macro_f_utf_char_t_width_is(string[i])) { - return F_status_set_error(F_valid_not); - } + if (macro_f_utf_char_t_width_is(string[i])) return F_status_set_error(F_valid_not); value *= 16; character = macro_f_utf_char_t_to_char_1(string[i]); @@ -217,9 +206,7 @@ extern "C" { if (width_max < 1) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (codepoint > 0x10ffff) { - return F_status_set_error(F_utf_not); - } + if (codepoint > 0x10ffff) return F_status_set_error(F_utf_not); if (codepoint < 0x80) { @@ -239,9 +226,7 @@ extern "C" { } } else if (codepoint < 0x800) { - if (width_max < 2) { - return F_status_set_error(F_utf_not); - } + if (width_max < 2) return F_status_set_error(F_utf_not); // U+0080 -> U+07FF (*character)[0] = F_utf_byte_2_d | ((f_char_t) ((codepoint & 0x7c0) >> 6)); @@ -256,9 +241,7 @@ extern "C" { } } else if (codepoint < 0x10000) { - if (width_max < 3) { - return F_status_set_error(F_utf_not); - } + if (width_max < 3) return F_status_set_error(F_utf_not); // U+0800 -> U+FFFF (*character)[0] = F_utf_byte_3_d | ((f_char_t) ((codepoint & 0xf000) >> 12)); @@ -270,9 +253,7 @@ extern "C" { } } else { - if (width_max < 4) { - return F_status_set_error(F_utf_not); - } + if (width_max < 4) return F_status_set_error(F_utf_not); // U+10000 -> U+10FFFF (*character)[0] = F_utf_byte_4_d | ((f_char_t) ((codepoint & 0x1c0000) >> 18)); @@ -333,9 +314,7 @@ extern "C" { } } - if (i == length) { - return F_status_set_error(F_valid_not); - } + if (i == length) return F_status_set_error(F_valid_not); uint32_t value = 0; @@ -359,9 +338,7 @@ extern "C" { } } // for - if (value > 0x10ffff) { - return F_status_set_error(F_valid_not); - } + if (value > 0x10ffff) return F_status_set_error(F_valid_not); *unicode = value; -- 1.8.3.1