feature (utils): Implemented some 'is_char_' functions

This commit is contained in:
antifallobst 2023-03-02 22:53:01 +01:00
parent b4df3a0bf4
commit 12c0d8f58a
3 changed files with 35 additions and 3 deletions

View File

@ -48,6 +48,10 @@ void string_hex_64bit_to_alpha (string_t string, uint64_t value);
void string_bin_to_alpha (string_t string, uint8_t num_bits, uint64_t value);
void string_bool_to_alpha (string_t string, bool value);
bool string_is_char_text (char chr);
bool string_is_char_number (char chr);
bool string_is_char_alpha (char chr);
bool string_is_char_uppercase (char chr);
bool string_is_char_lowercase (char chr);
#endif //NOX_STRING_H

View File

@ -109,7 +109,7 @@ void memory_hexdump(uint8_t* address, uint64_t num) {
for (uint64_t i = 0; i < rows; i++) {
char buffer[10] = ".... ....";
for (uint8_t j = 0; j < 8; j++) {
if (string_is_char_alpha((char)address[j])) {
if (string_is_char_text((char)address[j])) {
buffer[(j < 4) ? j : (j + 1)] = (char)address[j];
}
}
@ -123,7 +123,7 @@ void memory_hexdump(uint8_t* address, uint64_t num) {
char buffer[10] = " ";
for (uint8_t j = 0; j < remainder; j++) {
if (string_is_char_alpha((char)address[j])) {
if (string_is_char_text((char)address[j])) {
buffer[(j < 4) ? j : (j + 1)] = (char)address[j];
} else {
buffer[(j < 4) ? j : (j + 1)] = '.';

View File

@ -423,9 +423,37 @@ void string_bool_to_alpha(string_t string, bool value) {
memory_copy(value ? "true" : "false", (void*)string, value ? 5 : 6);
}
bool string_is_char_alpha(char chr) {
bool string_is_char_text(char chr) {
if (chr >= '!' && chr <= '~') {
return true;
}
return false;
}
bool string_is_char_number(char chr) {
if (chr >= '0' && chr <= '9') {
return true;
}
return false;
}
bool string_is_char_alpha(char chr) {
if (string_is_char_uppercase(chr) || string_is_char_lowercase(chr) || string_is_char_number(chr)) {
return true;
}
return false;
}
bool string_is_char_uppercase (char chr) {
if (chr >= 'A' && chr <= 'Z') {
return true;
}
return false;
}
bool string_is_char_lowercase (char chr) {
if (chr >= 'a' && chr <= 'z') {
return true;
}
return false;
}