feature (libnx): implemented basic string utils

This commit is contained in:
antifallobst 2023-06-07 10:46:59 +02:00
parent 21290535d4
commit 62d0f7be06
2 changed files with 39 additions and 1 deletions

View File

@ -7,6 +7,11 @@
typedef const char* string_t;
uint64_t strlen(string_t str);
uint64_t strlen (string_t str);
uint64_t str2int (string_t str, uint32_t base, uint64_t* len);
bool is_numeric (char chr);
bool is_lower (char chr);
bool is_upper (char chr);
#endif //LIBNX_STRING_H

View File

@ -7,3 +7,36 @@ uint64_t strlen(string_t str) {
while (str[n++]);
return n;
}
uint64_t str2int(string_t str, uint32_t base, uint64_t* len) {
uint64_t num = 0;
while (is_numeric(*str)) {
num *= base;
num += *str - '0';
str++;
if (len != NULL) *len += 1;
}
return num;
}
bool is_numeric(char chr) {
return (chr >= '0' && chr <= '9');
}
bool is_lower(char chr) {
return (chr >= 'a' && chr <= 'z');
}
bool is_upper(char chr) {
return (chr >= 'A' && chr <= 'Z');
}
bool is_special(char chr) {
return ((chr >= '!' && chr <= '/') ||
(chr >= ':' && chr <= '@') ||
(chr >= '[' && chr <= '`') ||
(chr >= '{' && chr <= '~'));
}