Use simpler logic for determining if character is a decimal or a hexidecimal.
Rename digit to decimal.
extern "C" {
#endif
-#ifndef _di_f_is_digit_
- f_return_status f_is_digit(const char character) {
+#ifndef _di_f_is_decimal_
+ f_return_status f_is_decimal(const char character) {
- // at this point, it seems that it would incur more overhead to use the libc isdigit here, so just use one less call and test it here
- switch (character) {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- break;
- default:
- return f_false;
+ if (character > 0x29 && character < 0x40) {
+ return f_true;
}
- return f_true;
+ return f_false;
}
-#endif // _di_f_is_digit_
+#endif // _di_f_is_decimal_
-#ifndef _di_f_is_hexdigit_
- f_return_status f_is_hexdigit(const char character) {
+#ifndef _di_f_is_hexidecimal_
+ f_return_status f_is_hexidecimal(const char character) {
- switch (character) {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- case 'A':
- case 'B':
- case 'C':
- case 'D':
- case 'E':
- case 'F':
- case 'a':
- case 'b':
- case 'c':
- case 'd':
- case 'e':
- case 'f':
- break;
- default:
- return f_false;
+ if (character > 0x29 && character < 0x40) {
+ return f_true;
+ }
+ else if (character > 0x40 && character < 0x47) {
+ return f_true;
+ }
+ else if (character > 0x60 && character < 0x67) {
+ return f_true;
}
- return f_true;
+ return f_false;
}
-#endif // _di_f_is_hexdigit_
+#endif // _di_f_is_hexidecimal_
#ifndef _di_f_character_to_digit_
f_return_status f_character_to_digit(const char character, f_u_long *digit) {
#endif // _di_level_0_parameter_checking_
switch (character) {
- case '0': *digit = 0; break;
- case '1': *digit = 1; break;
- case '2': *digit = 2; break;
- case '3': *digit = 3; break;
- case '4': *digit = 4; break;
- case '5': *digit = 5; break;
- case '6': *digit = 6; break;
- case '7': *digit = 7; break;
- case '8': *digit = 8; break;
- case '9': *digit = 9; break;
+ case 0x30: *digit = 0; break;
+ case 0x31: *digit = 1; break;
+ case 0x32: *digit = 2; break;
+ case 0x33: *digit = 3; break;
+ case 0x34: *digit = 4; break;
+ case 0x35: *digit = 5; break;
+ case 0x36: *digit = 6; break;
+ case 0x37: *digit = 7; break;
+ case 0x38: *digit = 8; break;
+ case 0x39: *digit = 9; break;
default:
return f_no_data;
}
}
#endif // _di_f_character_to_digit_
-#ifndef _di_f_character_to_hexdigit_
- f_return_status f_character_to_hexdigit(const char character, f_u_long *digit) {
+#ifndef _di_f_character_to_hexdecimal_
+ f_return_status f_character_to_hexdecimal(const char character, f_u_long *digit) {
#ifndef _di_level_0_parameter_checking_
if (digit == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_0_parameter_checking_
switch (character) {
- case '0': *digit = 0; break;
- case '1': *digit = 1; break;
- case '2': *digit = 2; break;
- case '3': *digit = 3; break;
- case '4': *digit = 4; break;
- case '5': *digit = 5; break;
- case '6': *digit = 6; break;
- case '7': *digit = 7; break;
- case '8': *digit = 8; break;
- case '9': *digit = 9; break;
- case 'A': *digit = 10; break;
- case 'B': *digit = 11; break;
- case 'C': *digit = 12; break;
- case 'D': *digit = 13; break;
- case 'E': *digit = 14; break;
- case 'F': *digit = 15; break;
- case 'a': *digit = 10; break;
- case 'b': *digit = 11; break;
- case 'c': *digit = 12; break;
- case 'd': *digit = 13; break;
- case 'e': *digit = 14; break;
- case 'f': *digit = 15; break;
+ case 0x30: *digit = 0; break;
+ case 0x31: *digit = 1; break;
+ case 0x32: *digit = 2; break;
+ case 0x33: *digit = 3; break;
+ case 0x34: *digit = 4; break;
+ case 0x35: *digit = 5; break;
+ case 0x36: *digit = 6; break;
+ case 0x37: *digit = 7; break;
+ case 0x38: *digit = 8; break;
+ case 0x39: *digit = 9; break;
+ case 0x41: *digit = 10; break;
+ case 0x42: *digit = 11; break;
+ case 0x43: *digit = 12; break;
+ case 0x44: *digit = 13; break;
+ case 0x45: *digit = 14; break;
+ case 0x46: *digit = 15; break;
+ case 0x61: *digit = 10; break;
+ case 0x62: *digit = 11; break;
+ case 0x63: *digit = 12; break;
+ case 0x64: *digit = 13; break;
+ case 0x65: *digit = 14; break;
+ case 0x66: *digit = 15; break;
default:
return f_no_data;
}
return f_none;
}
-#endif // _di_f_character_to_hexdigit_
+#endif // _di_f_character_to_hexdecimal_
-#ifndef _di_f_string_to_digit_
- f_return_status f_string_to_digit(const f_string string, f_u_long *digit, const f_string_location location) {
+#ifndef _di_f_string_to_decimal_
+ f_return_status f_string_to_decimal(const f_string string, f_u_long *digit, const f_string_location location) {
#ifndef _di_level_0_parameter_checking_
if (digit == 0) return f_status_set_error(f_invalid_parameter);
if (location.start < 0) return f_status_set_error(f_invalid_parameter);
}
++current_location;
- }
+ } // while
return f_none;
}
-#endif // _di_f_string_to_digit_
+#endif // _di_f_string_to_decimal_
-#ifndef _di_f_string_to_hexdigit_
- f_return_status f_string_to_hexdigit(const f_string string, f_u_long *digit, const f_string_location location) {
+#ifndef _di_f_string_to_hexidecimal_
+ f_return_status f_string_to_hexidecimal(const f_string string, f_u_long *digit, const f_string_location location) {
#ifndef _di_level_0_parameter_checking_
if (digit == 0) return f_status_set_error(f_invalid_parameter);
if (location.start < 0) return f_status_set_error(f_invalid_parameter);
f_u_long temp_digit = 0;
while (current_location < location.stop) {
- if (f_character_to_hexdigit(string[current_location], &temp_digit) == f_none) {
+ if (f_character_to_hexdecimal(string[current_location], &temp_digit) == f_none) {
// when the scale exists, then we need to make the number larger, for this function the scale is base 16
if (scale > 0) {
}
++current_location;
- }
+ } // while
return f_none;
}
-#endif // _di_f_string_to_hexdigit_
+#endif // _di_f_string_to_hexidecimal_
#ifdef __cplusplus
} // extern "C"
extern "C" {
#endif
-#ifndef _di_f_is_digit_
+#ifndef _di_f_is_decimal_
/**
- * convert a single character into the digit that it represents.
+ * convert a single character into the decimal value that it represents.
*/
- extern f_return_status f_is_digit(const char character);
-#endif // _di_f_is_digit_
+ extern f_return_status f_is_decimal(const char character);
+#endif // _di_f_is_decimal_
-#ifndef _di_f_is_hexdigit_
+#ifndef _di_f_is_hexidecimal_
/**
* convert a single character into the hexidecimal digit that it represents
*/
- extern f_return_status f_is_hexdigit(const char character);
-#endif // _di_f_is_hexdigit_
+ extern f_return_status f_is_hexidecimal(const char character);
+#endif // _di_f_is_hexidecimal_
#ifndef _di_f_character_to_digit_
/**
extern f_return_status f_character_to_digit(const char character, f_u_long *digit);
#endif // _di_f_character_to_digit_
-#ifndef _di_f_character_to_hexdigit_
+#ifndef _di_f_character_to_hexdecimal_
/**
*convert a single character into the hexidecimal digit that it represents.
*/
- extern f_return_status f_character_to_hexdigit(const char character, f_u_long *digit);
-#endif // _di_f_character_to_hexdigit_
+ extern f_return_status f_character_to_hexdecimal(const char character, f_u_long *digit);
+#endif // _di_f_character_to_hexdecimal_
-#ifndef _di_f_string_to_digit_
+#ifndef _di_f_string_to_decimal_
/**
* works like atoi, except there is a start/stop range.
* convert a series of positive numbers into a string, stopping at one of the following: EOS, max_length, or a non-digit.
* will not process signed statuses (+/-).
*/
- extern f_return_status f_string_to_digit(const f_string string, f_u_long *digit, const f_string_location location);
-#endif // _di_f_string_to_digit_
+ extern f_return_status f_string_to_decimal(const f_string string, f_u_long *digit, const f_string_location location);
+#endif // _di_f_string_to_decimal_
-#ifndef _di_f_string_to_hexdigit_
+#ifndef _di_f_string_to_hexidecimal_
/**
* works like atoi, except there is a start/stop range and that this is for hexidecimal digits.
* convert a series of positive numbers into a string, stopping at one of the following: EOS, max_length, or a non-hexdigit.
* will not process signed statuses (+/-).
*/
- extern f_return_status f_string_to_hexdigit(const f_string string, f_u_long *digit, const f_string_location location);
-#endif // _di_f_string_to_hexdigit_
+ extern f_return_status f_string_to_hexidecimal(const f_string string, f_u_long *digit, const f_string_location location);
+#endif // _di_f_string_to_hexidecimal_
#ifdef __cplusplus
} // extern "C"
if (buffer.string[i] == f_fss_type_header_part5) {
i++;
- if (f_is_hexdigit(buffer.string[i]) == f_true) {
+ if (f_is_hexidecimal(buffer.string[i]) == f_true) {
i++;
- if (f_is_hexdigit(buffer.string[i]) == f_true) {
+ if (f_is_hexidecimal(buffer.string[i]) == f_true) {
i++;
- if (f_is_hexdigit(buffer.string[i]) == f_true) {
+ if (f_is_hexidecimal(buffer.string[i]) == f_true) {
i++;
- if (f_is_hexdigit(buffer.string[i]) == f_true) {
+ if (f_is_hexidecimal(buffer.string[i]) == f_true) {
i++;
f_string_location location = f_string_location_initialize;
location.stop = i;
// 1: A possibly valid header type was found, now convert it into its proper format and save the header type
- f_string_to_hexdigit(buffer.string, &header->type, location);
+ f_string_to_hexidecimal(buffer.string, &header->type, location);
// 2: At this point, we can still know the proper format for the file and still have a invalid header, handle accordingly
if (buffer.string[i] == f_fss_type_header_close) {
if (buffer.string[i] == f_fss_type_header_part5) {
i++;
- if (f_is_hexdigit(buffer.string[i]) == f_true) {
+ if (f_is_hexidecimal(buffer.string[i]) == f_true) {
i++;
- if (f_is_hexdigit(buffer.string[i]) == f_true) {
+ if (f_is_hexidecimal(buffer.string[i]) == f_true) {
i++;
- if (f_is_hexdigit(buffer.string[i]) == f_true) {
+ if (f_is_hexidecimal(buffer.string[i]) == f_true) {
i++;
- if (f_is_hexdigit(buffer.string[i]) == f_true) {
+ if (f_is_hexidecimal(buffer.string[i]) == f_true) {
i++;
f_string_location location = f_string_location_initialize;
location.start = i - 4;
location.stop = i;
- f_string_to_hexdigit(buffer.string, &header->type, location);
+ f_string_to_hexidecimal(buffer.string, &header->type, location);
header->length = i + 1;
}
// numbers are not valid status code strings.
- if ((status = f_is_digit(string[0])) == f_true) {
+ if ((status = f_is_decimal(string[0])) == f_true) {
return f_invalid_data;
}
}
// numbers are not valid status code strings.
- if ((status = f_is_digit(string[0])) == f_true) {
+ if ((status = f_is_decimal(string[0])) == f_true) {
return f_invalid_data;
}
for (; counter < data->remaining.used; counter++) {
// only numbers are valid status codes.
- if (f_is_digit(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
+ if (f_is_decimal(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
status = f_false;
continue;
}
for (; counter < data->remaining.used; counter++) {
// only numbers are valid status codes.
- if (f_is_digit(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
+ if (f_is_decimal(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
status = f_false;
continue;
}
for (; counter < data->remaining.used; counter++) {
// only numbers are valid status codes.
- if (f_is_digit(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
+ if (f_is_decimal(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
status = f_false;
continue;
}
for (; counter < data->remaining.used; counter++) {
// numbers are not valid status code strings.
- if (f_is_digit(arguments.argv[data->remaining.array[counter]][0]) == f_true) {
+ if (f_is_decimal(arguments.argv[data->remaining.array[counter]][0]) == f_true) {
status = f_false;
continue;
}
if (data->remaining.used > 0) {
for (; counter < data->remaining.used; counter++) {
// only numbers are valid status code.
- if (f_is_digit(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
+ if (f_is_decimal(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
status = f_false;
continue;
}
for (; counter < data->remaining.used; counter++) {
// only numbers are valid status codes.
- if (f_is_digit(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
+ if (f_is_decimal(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
status = f_false;
continue;
}
for (; counter < data->remaining.used; counter++) {
// only numbers are valid status codes.
- if (f_is_digit(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
+ if (f_is_decimal(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
status = f_false;
continue;
}
for (; counter < data->remaining.used; counter++) {
// only numbers are valid status codes.
- if (f_is_digit(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
+ if (f_is_decimal(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
status = f_false;
continue;
}
for (; counter < data->remaining.used; counter++) {
// numbers are not valid status code strings.
- if (f_is_digit(arguments.argv[data->remaining.array[counter]][0]) == f_true) {
+ if (f_is_decimal(arguments.argv[data->remaining.array[counter]][0]) == f_true) {
status = f_false;
continue;
}
if (data->remaining.used > 0) {
for (; counter < data->remaining.used; counter++) {
// only numbers are valid status code.
- if (f_is_digit(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
+ if (f_is_decimal(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
status = f_false;
continue;
}