feature (libnx): implemented basic string utils
This commit is contained in:
parent
21290535d4
commit
62d0f7be06
|
@ -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
|
||||
|
|
|
@ -6,4 +6,37 @@ uint64_t strlen(string_t str) {
|
|||
uint64_t n = 0;
|
||||
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 <= '~'));
|
||||
}
|
Loading…
Reference in New Issue