Do not treat F_number_positive and F_number_negative as an error.
The "unsigned" concept should be internal to the function and not whether or not the user input has a sign.
If F_number_negative is returned, the value can still be of type f_number_unsigned_t.
This is because the return status designates the effective sign.
The caller can then decide whether or not this is an error.
#ifndef _di_f_conversion_character_is_binary_
f_status_t f_conversion_character_is_binary(const f_char_t character) {
- if (character == 0x30 || character == 0x31) {
- return F_true;
- }
-
- return F_false;
+ return (character == 0x30 || character == 0x31) ? F_true : F_false;
}
#endif // _di_f_conversion_character_is_binary_
#ifndef _di_f_conversion_character_is_decimal_
f_status_t f_conversion_character_is_decimal(const f_char_t character) {
- if (character > 0x2f && character < 0x3a) {
- return F_true;
- }
-
- return F_false;
+ return (character > 0x2f && character < 0x3a) ? F_true : F_false;
}
#endif // _di_f_conversion_character_is_decimal_
#ifndef _di_f_conversion_character_is_duodecimal_
f_status_t f_conversion_character_is_duodecimal(const f_char_t character) {
- if (character > 0x2f && character < 0x3a) {
- return F_true;
- }
-
- if (character == 0x41 || character == 0x42) {
- return F_true;
- }
-
- if (character == 0x61 || character == 0x62) {
- return F_true;
- }
+ if (character > 0x2f && character < 0x3a) return F_true;
+ if (character == 0x41 || character == 0x42) return F_true;
+ if (character == 0x61 || character == 0x62) return F_true;
return F_false;
}
#ifndef _di_f_conversion_character_is_hexidecimal_
f_status_t f_conversion_character_is_hexidecimal(const f_char_t character) {
- if (character > 0x2f && character < 0x3a) {
- return F_true;
- }
-
- if (character > 0x40 && character < 0x47) {
- return F_true;
- }
-
- if (character > 0x60 && character < 0x67) {
- return F_true;
- }
+ if (character > 0x2f && character < 0x3a) return F_true;
+ if (character > 0x40 && character < 0x47) return F_true;
+ if (character > 0x60 && character < 0x67) return F_true;
return F_false;
}
#ifndef _di_f_conversion_character_is_octal_
f_status_t f_conversion_character_is_octal(const f_char_t character) {
- if (character > 0x2f && character < 0x38) {
- return F_true;
- }
-
- return F_false;
+ return (character > 0x2f && character < 0x38) ? F_true : F_false;
}
#endif // _di_f_conversion_character_is_octal_
if (!number) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
- if (character < 0x30 || character > 0x37) {
- return F_status_set_error(F_number);
- }
+ if (character < 0x30 || character > 0x37) return F_status_set_error(F_number);
*number = 0xf & character;
if (!number) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
- if (!buffer.used || range.start > range.stop) {
- return F_data_not;
- }
+ if (!buffer.used || range.start > range.stop) return F_data_not;
if (data.base == 10 || data.base == 16 || data.base == 12 || data.base == 8) {
return private_fl_conversion_dynamic_to_base_signed(data, buffer.string + range.start, (range.stop - range.start) + 1, number);
}
- else if (data.base == 2) {
+
+ if (data.base == 2) {
return private_fl_conversion_dynamic_to_binary_signed(data.flag, buffer.string + range.start, (range.stop - range.start) + 1, number);
}
if (!number) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
- if (!buffer.used || range.start > range.stop) {
- return F_data_not;
- }
+ if (!buffer.used || range.start > range.stop) return F_data_not;
if (data.base == 10 || data.base == 16 || data.base == 12 || data.base == 8) {
return private_fl_conversion_dynamic_to_base_unsigned(data, buffer.string + range.start, (range.stop - range.start) + 1, number);
}
- else if (data.base == 2) {
+
+ if (data.base == 2) {
return private_fl_conversion_dynamic_to_binary_unsigned(data.flag, buffer.string + range.start, (range.stop - range.start) + 1, number);
}
if (!number) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
- if (!buffer.used || range.start > range.stop) {
- return F_data_not;
- }
+ if (!buffer.used || range.start > range.stop) return F_data_not;
return private_fl_conversion_dynamic_to_signed_detect(data.flag, buffer.string + range.start, (range.stop - range.start) + 1, number);
}
if (!number) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
- if (!buffer.used || range.start > range.stop) {
- return F_data_not;
- }
+ if (!buffer.used || range.start > range.stop) return F_data_not;
return private_fl_conversion_dynamic_to_unsigned_detect(data.flag, buffer.string + range.start, (range.stop - range.start) + 1, number);
}
if (!number) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
- if (!buffer.used) {
- return F_data_not;
- }
+ if (!buffer.used) return F_data_not;
if (data.base == 10 || data.base == 16 || data.base == 12 || data.base == 8) {
return private_fl_conversion_dynamic_to_base_signed(data, buffer.string, buffer.used, number);
}
- else if (data.base == 2) {
+
+ if (data.base == 2) {
return private_fl_conversion_dynamic_to_binary_signed(data.flag, buffer.string, buffer.used, number);
}
if (!number) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
- if (!buffer.used) {
- return F_data_not;
- }
+ if (!buffer.used) return F_data_not;
if (data.base == 10 || data.base == 16 || data.base == 12 || data.base == 8) {
return private_fl_conversion_dynamic_to_base_unsigned(data, buffer.string, buffer.used, number);
}
- else if (data.base == 2) {
+
+ if (data.base == 2) {
return private_fl_conversion_dynamic_to_binary_unsigned(data.flag, buffer.string, buffer.used, number);
}
if (!number) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
- if (!buffer.used) {
- return F_data_not;
- }
+ if (!buffer.used) return F_data_not;
return private_fl_conversion_dynamic_to_signed_detect(data.flag, buffer.string, buffer.used, number);
}
if (!number) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
- if (!buffer.used) {
- return F_data_not;
- }
+ if (!buffer.used) return F_data_not;
return private_fl_conversion_dynamic_to_unsigned_detect(data.flag, buffer.string, buffer.used, number);
}
*
* @param data
* Conversion data for specifying things such as treating this as a negative number.
+ * This auto-detects the base and negative, ignoring the base number and negative flag.
* @param buffer
* The string to convert.
* @param range
* @return
* F_none on success.
* F_data_not if string starts with a null (length is 0).
+ * F_number_negative on negative value (has a -, such as '-1').
+ * F_number_positive on positive value (has a +, such as '+1').
*
* F_base_not (with error bit) if no supported or valid base unit is provided.
* F_complete_not_utf (with error bit) if an incomplete UTF-8 fragment is found.
* F_number (with error bit) if parameter is not a number.
* F_number_decimal (with error bit) if number has a decimal digit.
- * F_number_negative (with error bit) on negative value.
- * F_number_positive (with error bit) on positive value (has a +, such as '+1', when only '1' is valid here).
* F_number_overflow (with error bit) on integer overflow.
* F_parameter (with error bit) if a parameter is invalid.
*
* @return
* F_none on success.
* F_data_not if string starts with a null (length is 0).
+ * F_number_negative on negative value (has a -, such as '-1').
+ * F_number_positive on positive value (has a +, such as '+1').
*
* F_base_not (with error bit) if no supported or valid base unit is provided.
* F_complete_not_utf (with error bit) if an incomplete UTF-8 fragment is found.
* F_number (with error bit) if parameter is not a number.
* F_number_decimal (with error bit) if number has a decimal digit.
- * F_number_negative (with error bit) on negative value.
- * F_number_positive (with error bit) on positive value (has a +, such as '+1', when only '1' is valid here).
* F_number_overflow (with error bit) on integer overflow.
* F_parameter (with error bit) if a parameter is invalid.
*
for (f_number_unsigned_t i = 0; i < length; ++i) {
- if (string[i] == f_string_ascii_period_s.string[0]) {
- return F_status_set_error(F_number_decimal);
- }
+ if (string[i] == f_string_ascii_period_s.string[0]) return F_status_set_error(F_number_decimal);
if (f_conversion_character_to_binary(string[i], &digit) == F_none) {
if (digits) {
++digits;
if (flag & fl_conversion_data_flag_negative_e) {
- if (digits > F_conversion_digits_binary_signed_d) {
- return F_status_set_error(F_number_underflow);
- }
+ if (digits > F_conversion_digits_binary_signed_d) return F_status_set_error(F_number_underflow);
if (flag & fl_conversion_data_flag_endian_big_e) {
converted >>= 1;
converted -= digit;
}
else {
- if (digits > F_conversion_digits_binary_signed_d) {
- return F_status_set_error(F_number_overflow);
- }
+ if (digits > F_conversion_digits_binary_signed_d) return F_status_set_error(F_number_overflow);
if (flag & fl_conversion_data_flag_endian_big_e) {
converted >>= 1;
for (f_number_unsigned_t i = 0; i < length; ++i) {
- if (string[i] == f_string_ascii_period_s.string[0]) {
- return F_status_set_error(F_number_decimal);
- }
+ if (string[i] == f_string_ascii_period_s.string[0]) return F_status_set_error(F_number_decimal);
if (f_conversion_character_to_binary(string[i], &digit) == F_none) {
if (digits) {
++digits;
- if (digits > F_conversion_digits_binary_unsigned_d) {
- return F_status_set_error(F_number_overflow);
- }
+ if (digits > F_conversion_digits_binary_unsigned_d) return F_status_set_error(F_number_overflow);
if (flag & fl_conversion_data_flag_endian_big_e) {
converted >>= 1;
for (f_number_unsigned_t i = 0; i < length; ++i) {
- if (string[i] == f_string_ascii_period_s.string[0]) {
- return F_status_set_error(F_number_decimal);
- }
+ if (string[i] == f_string_ascii_period_s.string[0]) return F_status_set_error(F_number_decimal);
if (character_to_digit(string[i], &digit) == F_none) {
if (digits) {
for (f_number_unsigned_t i = 0; i < length; ++i) {
- if (string[i] == f_string_ascii_period_s.string[0]) {
- return F_status_set_error(F_number_decimal);
- }
+ if (string[i] == f_string_ascii_period_s.string[0]) return F_status_set_error(F_number_decimal);
if (character_to_digit(string[i], &digit) == F_none) {
if (digits) {
return F_status_set_error(F_number);
} // for
- if (!mode) {
- return F_status_set_error(F_number);
- }
-
- if (offset >= length) {
- return F_status_set_error(F_number);
- }
+ if (!mode || offset >= length) return F_status_set_error(F_number);
fl_conversion_data_t data = macro_fl_conversion_data_t_initialize_1(mode, flag);
}
if (string[i] == f_string_ascii_plus_s.string[0]) {
- ++offset;
- sign_found = 1;
+ if (!sign_found) {
+ ++offset;
+ sign_found = 1;
+
+ continue;
+ }
}
if (string[i] == f_string_ascii_minus_s.string[0]) {
- ++offset;
- sign_found = -1;
+ if (!sign_found) {
+ ++offset;
+ sign_found = -1;
+
+ continue;
+ }
}
if (f_conversion_character_is_decimal(string[i]) == F_true) {
return F_status_set_error(F_number);
} // for
- if (!mode) {
- return F_status_set_error(F_number);
- }
-
- if (offset >= length) {
- return F_status_set_error(F_number);
- }
+ if (!mode || offset >= length) return F_status_set_error(F_number);
fl_conversion_data_t data = macro_fl_conversion_data_t_initialize_1(mode, flag);
// The +/- signs are not allowed.
if (sign_found) {
- if (status == F_none) {
- if (sign_found == -1) {
- return F_status_set_error(F_number_negative);
- }
-
- return F_status_set_error(F_number_positive);
- }
+ if (status == F_none) return (sign_found == -1) ? F_number_negative : F_number_positive;
return F_status_set_error(F_number);
}
* @return
* F_none on success.
* F_data_not if string starts with a null (length is 0).
+ * F_number_negative on negative value (has a -, such as '-1').
+ * F_number_positive on positive value (has a +, such as '+1').
*
* F_complete_not_utf (with error bit) if an incomplete UTF-8 fragment is found.
* F_number (with error bit) if parameter is not a number.
* F_number_decimal (with error bit) if number has a decimal digit.
- * F_number_negative (with error bit) on negative value.
- * F_number_positive (with error bit) on positive value (has a +, such as '+1', when only '1' is valid here).
* F_number_overflow (with error bit) on integer overflow.
* F_parameter (with error bit) if a parameter is invalid.
*
status = fl_conversion_dynamic_to_unsigned_detect(fl_conversion_data_base_10_c, data.argv[index], &number);
+ // Negative numbers are not supported.
+ if (status == F_number_negative) {
+ status = F_status_set_error(F_number_negative);
+ }
+
if (F_status_is_error(status) || number < 1 || number >= 0xfb) {
f_file_stream_lock(main->error.to);
status = fl_conversion_dynamic_to_unsigned_detect(fl_conversion_data_base_10_c, data.argv[index], &number);
+ // Negative numbers are not supported.
+ if (status == F_number_negative) {
+ status = F_status_set_error(F_number_negative);
+ }
+
if (F_status_is_error(status) || number > F_number_t_size_unsigned_d) {
f_file_stream_lock(main->error.to);
status = fl_conversion_dynamic_to_unsigned_detect(fl_conversion_data_base_10_c, data.argv[index], &number);
+ // Negative numbers are not supported.
+ if (status == F_number_negative) {
+ status = F_status_set_error(F_number_negative);
+ }
+
if (F_status_is_error(status) || number < 0 || number > F_number_t_size_unsigned_d) {
f_file_stream_lock(main->error.to);
main->setting.state.status = fl_conversion_dynamic_to_unsigned_detect(fl_conversion_data_base_10_c, buffer, &number);
+ // Negative numbers are not supported.
+ if (main->setting.state.status == F_number_negative) {
+ main->setting.state.status = F_status_set_error(F_number_negative);
+ }
+
if (F_status_is_error(main->setting.state.status)) {
// When the buffer is not a number, then check to see if this is a group or owner name.
main->setting.state.status = fl_conversion_dynamic_to_unsigned_detect(fl_conversion_data_base_10_c, main->program.parameters.arguments.array[index], &main->setting.line);
+ // Negative numbers are not supported.
+ if (main->setting.state.status == F_number_negative) {
+ main->setting.state.status = F_status_set_error(F_number_negative);
+ }
+
if (F_status_is_error(main->setting.state.status)) {
if ((main->setting.flag & fss_identify_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) {
fll_print_dynamic_raw(f_string_eol_s, main->program.message.to);
main->setting.state.status = fl_conversion_dynamic_to_unsigned_detect(fl_conversion_data_base_10_c, main->program.parameters.arguments.array[index], &main->setting.at);
+ // Negative numbers are not supported.
+ if (main->setting.state.status == F_number_negative) {
+ main->setting.state.status = F_status_set_error(F_number_negative);
+ }
+
if (F_status_is_error(main->setting.state.status)) {
main->setting.state.status = F_status_set_error(F_parameter);
main->setting.state.status = fl_conversion_dynamic_to_unsigned_detect(fl_conversion_data_base_10_c, main->program.parameters.arguments.array[index], &main->setting.line);
+ // Negative numbers are not supported.
+ if (main->setting.state.status == F_number_negative) {
+ main->setting.state.status = F_status_set_error(F_number_negative);
+ }
+
if (F_status_is_error(main->setting.state.status)) {
main->setting.state.status = F_status_set_error(F_parameter);
main->setting.state.status = fl_conversion_dynamic_to_unsigned_detect(fl_conversion_data_base_10_c, main->setting.text, &number);
raw = (f_utf_char_t) number;
+
+ // Negative numbers are not supported.
+ if (main->setting.state.status == F_number_negative) {
+ main->setting.state.status = F_status_set_error(F_number_negative);
+ }
}
if (F_status_is_error(main->setting.state.status)) {