Add ctype variants to stdstring and use it in RA

This commit is contained in:
twinaphex 2020-09-27 22:15:32 +02:00
parent f1432db433
commit c744baeb89
11 changed files with 89 additions and 41 deletions

View File

@ -1351,8 +1351,8 @@ bool core_info_hw_api_supported(core_info_t *info)
{ {
case STATE_API_NAME: case STATE_API_NAME:
{ {
if ( isupper((unsigned char)cur_api[j]) || if ( ISUPPER((unsigned char)cur_api[j]) ||
islower((unsigned char)cur_api[j])) ISLOWER((unsigned char)cur_api[j]))
api_str[api_pos++] = cur_api[j]; api_str[api_pos++] = cur_api[j];
else else
{ {
@ -1401,14 +1401,21 @@ bool core_info_hw_api_supported(core_info_t *info)
} }
case STATE_API_VERSION: case STATE_API_VERSION:
{ {
if (!found_minor && cur_api[j] >= '0' && cur_api[j] <= '9' && cur_api[j] != '.') if ( !found_minor
&& cur_api[j] >= '0'
&& cur_api[j] <= '9'
&& cur_api[j] != '.')
{ {
found_major = true; found_major = true;
if (major_str_pos < sizeof(major_str) - 1) if (major_str_pos < sizeof(major_str) - 1)
major_str[major_str_pos++] = cur_api[j]; major_str[major_str_pos++] = cur_api[j];
} }
else if (found_major && found_minor && cur_api[j] >= '0' && cur_api[j] <= '9') else if (
found_major
&& found_minor
&& cur_api[j] >= '0'
&& cur_api[j] <= '9')
{ {
if (minor_str_pos < sizeof(minor_str) - 1) if (minor_str_pos < sizeof(minor_str) - 1)
minor_str[minor_str_pos++] = cur_api[j]; minor_str[minor_str_pos++] = cur_api[j];

View File

@ -205,7 +205,7 @@ static bool font_renderer_create_atlas(ft_font_renderer_t *handle, float font_si
font_renderer_ft_get_glyph(handle, i); font_renderer_ft_get_glyph(handle, i);
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
if (isalnum(i)) if (ISALNUM(i))
font_renderer_ft_get_glyph(handle, i); font_renderer_ft_get_glyph(handle, i);
return true; return true;

View File

@ -19,6 +19,7 @@
#include <file/file_path.h> #include <file/file_path.h>
#include <streams/file_stream.h> #include <streams/file_stream.h>
#include <retro_miscellaneous.h> #include <retro_miscellaneous.h>
#include <string/stdstring.h>
#include "../font_driver.h" #include "../font_driver.h"
#include "../../verbosity.h" #include "../../verbosity.h"
@ -108,7 +109,7 @@ static bool font_renderer_stb_create_atlas(stb_font_renderer_t *self,
g->height = c->y1 - c->y0; g->height = c->y1 - c->y0;
/* Make sure important characters fit */ /* Make sure important characters fit */
if (isalnum(i) && (!g->width || !g->height)) if (ISALNUM(i) && (!g->width || !g->height))
{ {
int new_width = width * 1.2; int new_width = width * 1.2;
int new_height = height * 1.2; int new_height = height * 1.2;

View File

@ -18,6 +18,7 @@
#include <file/file_path.h> #include <file/file_path.h>
#include <streams/file_stream.h> #include <streams/file_stream.h>
#include <string/stdstring.h>
#include <retro_miscellaneous.h> #include <retro_miscellaneous.h>
#ifdef WIIU #ifdef WIIU
@ -220,7 +221,7 @@ static bool font_renderer_stb_unicode_create_atlas(
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
if (isalnum(i)) if (ISALNUM(i))
font_renderer_stb_unicode_get_glyph(self, i); font_renderer_stb_unicode_get_glyph(self, i);
} }

View File

@ -219,7 +219,7 @@ static char *config_file_extract_value(char *line, bool is_value)
if (is_value) if (is_value)
{ {
while (isspace((int)*line)) while (ISSPACE((int)*line))
line++; line++;
/* If we don't have an equal sign here, /* If we don't have an equal sign here,
@ -230,7 +230,7 @@ static char *config_file_extract_value(char *line, bool is_value)
line++; line++;
} }
while (isspace((int)*line)) while (ISSPACE((int)*line))
line++; line++;
/* Note: From this point on, an empty value /* Note: From this point on, an empty value
@ -517,7 +517,7 @@ static bool config_file_parse_line(config_file_t *conf,
} }
/* Skip to first non-space character */ /* Skip to first non-space character */
while (isspace((int)*line)) while (ISSPACE((int)*line))
line++; line++;
/* Allocate storage for key */ /* Allocate storage for key */

View File

@ -35,7 +35,32 @@
RETRO_BEGIN_DECLS RETRO_BEGIN_DECLS
#define strcpy_literal(a, b) strcpy(a, b) #define STRLEN_CONST(x) ((sizeof((x))-1))
#define strcpy_literal(a, b) strcpy(a, b)
#define string_is_not_equal(a, b) !string_is_equal((a), (b))
#define string_is_not_equal_fast(a, b, size) (memcmp(a, b, size) != 0)
#define string_is_equal_fast(a, b, size) (memcmp(a, b, size) == 0)
#define TOLOWER(c) (c | (lr_char_props[c] & 0x20))
#define TOUPPER(c) (c & ~(lr_char_props[c] & 0x20))
/* C standard says \f \v are space, but this one disagrees */
#define ISSPACE(c) (lr_char_props[c] & 0x80)
#define ISDIGIT(c) (lr_char_props[c] & 0x40)
#define ISALPHA(c) (lr_char_props[c] & 0x20)
#define ISLOWER(c) (lr_char_props[c] & 0x04)
#define ISUPPER(c) (lr_char_props[c] & 0x02)
#define ISALNUM(c) (lr_char_props[c] & 0x60)
#define ISUALPHA(c) (lr_char_props[c] & 0x28)
#define ISUALNUM(c) (lr_char_props[c] & 0x68)
#define IS_XDIGIT(c) (lr_char_props[c] & 0x01)
/* Deprecated alias, all callers should use string_is_equal_case_insensitive instead */
#define string_is_equal_noncase string_is_equal_case_insensitive
static INLINE bool string_is_empty(const char *data) static INLINE bool string_is_empty(const char *data)
{ {
@ -85,12 +110,6 @@ static INLINE size_t strlen_size(const char *str, size_t size)
return i; return i;
} }
#define STRLEN_CONST(x) ((sizeof((x))-1))
#define string_is_not_equal(a, b) !string_is_equal((a), (b))
#define string_is_not_equal_fast(a, b, size) (memcmp(a, b, size) != 0)
#define string_is_equal_fast(a, b, size) (memcmp(a, b, size) == 0)
static INLINE bool string_is_equal_case_insensitive(const char *a, static INLINE bool string_is_equal_case_insensitive(const char *a,
const char *b) const char *b)
@ -111,9 +130,6 @@ static INLINE bool string_is_equal_case_insensitive(const char *a,
return (result == 0); return (result == 0);
} }
/* Deprecated alias, all callers should use string_is_equal_case_insensitive instead */
#define string_is_equal_noncase string_is_equal_case_insensitive
char *string_to_upper(char *s); char *string_to_upper(char *s);
char *string_to_lower(char *s); char *string_to_lower(char *s);
@ -175,6 +191,8 @@ char *string_init(const char *src);
void string_set(char **string, const char *src); void string_set(char **string, const char *src);
extern const unsigned char lr_char_props[256];
RETRO_END_DECLS RETRO_END_DECLS
#endif #endif

View File

@ -35,6 +35,7 @@
#include <compat/msvc.h> #include <compat/msvc.h>
#endif #endif
#include <string/stdstring.h>
#include <streams/file_stream.h> #include <streams/file_stream.h>
#define VFS_FRONTEND #define VFS_FRONTEND
#include <vfs/vfs_implementation.h> #include <vfs/vfs_implementation.h>
@ -255,7 +256,7 @@ int filestream_scanf(RFILE *stream, const char* format, ...)
*subfmtiter++ = *format++; *subfmtiter++ = *format++;
} }
while (isdigit((unsigned char)*format)) while (ISDIGIT((unsigned char)*format))
*subfmtiter++ = *format++; /* width */ *subfmtiter++ = *format++; /* width */
/* length */ /* length */

View File

@ -26,6 +26,26 @@
#include <string/stdstring.h> #include <string/stdstring.h>
#include <encodings/utf.h> #include <encodings/utf.h>
const uint8_t lr_char_props[256] = {
/*x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x80,0x00,0x00, /* 0x */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 1x */
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 2x !"#$%&'()*+,-./ */
0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x00,0x00,0x00,0x00,0x00,0x00, /* 3x 0123456789:;<=>? */
0x00,0x23,0x23,0x23,0x23,0x23,0x23,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22, /* 4x @ABCDEFGHIJKLMNO */
0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x00,0x00,0x00,0x00,0x08, /* 5x PQRSTUVWXYZ[\]^_ */
0x00,0x25,0x25,0x25,0x25,0x25,0x25,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24, /* 6x `abcdefghijklmno */
0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x00,0x00,0x00,0x00,0x00, /* 7x pqrstuvwxyz{|}~ */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 8x */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 9x */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* Ax */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* Bx */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* Cx */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* Dx */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* Ex */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* Fx */
};
char *string_init(const char *src) char *string_init(const char *src)
{ {
return src ? strdup(src) : NULL; return src ? strdup(src) : NULL;
@ -124,7 +144,7 @@ char *string_trim_whitespace_left(char *const s)
size_t len = strlen(s); size_t len = strlen(s);
char *current = s; char *current = s;
while (*current && isspace((unsigned char)*current)) while (*current && ISSPACE((unsigned char)*current))
{ {
++current; ++current;
--len; --len;
@ -145,13 +165,13 @@ char *string_trim_whitespace_right(char *const s)
size_t len = strlen(s); size_t len = strlen(s);
char *current = s + len - 1; char *current = s + len - 1;
while (current != s && isspace((unsigned char)*current)) while (current != s && ISSPACE((unsigned char)*current))
{ {
--current; --current;
--len; --len;
} }
current[isspace((unsigned char)*current) ? 0 : 1] = '\0'; current[ISSPACE((unsigned char)*current) ? 0 : 1] = '\0';
} }
return s; return s;
@ -355,7 +375,7 @@ unsigned string_to_unsigned(const char *str)
for (ptr = str; *ptr != '\0'; ptr++) for (ptr = str; *ptr != '\0'; ptr++)
{ {
if (!isdigit((unsigned char)*ptr)) if (!ISDIGIT((unsigned char)*ptr))
return 0; return 0;
} }

View File

@ -329,7 +329,7 @@ static struct buffer query_parse_integer(
} }
else else
{ {
while (isdigit((int)buff.data[buff.offset])) while (ISDIGIT((int)buff.data[buff.offset]))
buff.offset++; buff.offset++;
} }
@ -339,7 +339,7 @@ static struct buffer query_parse_integer(
static struct buffer query_chomp(struct buffer buff) static struct buffer query_chomp(struct buffer buff)
{ {
for (; (unsigned)buff.offset < buff.len for (; (unsigned)buff.offset < buff.len
&& isspace((int)buff.data[buff.offset]); buff.offset++); && ISSPACE((int)buff.data[buff.offset]); buff.offset++);
return buff; return buff;
} }
@ -512,7 +512,7 @@ static struct buffer query_parse_value(
query_peek(buff, "'", STRLEN_CONST("'"))) query_peek(buff, "'", STRLEN_CONST("'")))
buff = query_parse_string(s, len, buff = query_parse_string(s, len,
buff, value, error); buff, value, error);
else if (isdigit((int)buff.data[buff.offset])) else if (ISDIGIT((int)buff.data[buff.offset]))
buff = query_parse_integer(s, len, buff, value, error); buff = query_parse_integer(s, len, buff, value, error);
return buff; return buff;
} }
@ -556,7 +556,7 @@ static struct buffer query_get_ident(
*len = 0; *len = 0;
query_peek_char(s, _len, buff, &c, error); query_peek_char(s, _len, buff, &c, error);
if (*error || !isalpha((int)c)) if (*error || !ISALPHA((int)c))
return buff; return buff;
buff.offset++; buff.offset++;
@ -565,7 +565,7 @@ static struct buffer query_get_ident(
while (!*error) while (!*error)
{ {
if (!(isalnum((int)c) || c == '_')) if (!(ISALNUM((int)c) || c == '_'))
break; break;
buff.offset++; buff.offset++;
*len = *len + 1; *len = *len + 1;
@ -608,7 +608,7 @@ static struct buffer query_parse_argument(
buff = query_chomp(buff); buff = query_chomp(buff);
if ( if (
isalpha((int)buff.data[buff.offset]) ISALPHA((int)buff.data[buff.offset])
&& !( && !(
query_peek(buff, "nil", STRLEN_CONST("nil")) query_peek(buff, "nil", STRLEN_CONST("nil"))
|| query_peek(buff, "true", STRLEN_CONST("true")) || query_peek(buff, "true", STRLEN_CONST("true"))
@ -814,7 +814,7 @@ static struct buffer query_parse_table(
goto clean; goto clean;
} }
if (isalpha((int)buff.data[buff.offset])) if (ISALPHA((int)buff.data[buff.offset]))
{ {
buff = query_get_ident(s, len, buff = query_get_ident(s, len,
buff, &ident_name, &ident_len, error); buff, &ident_name, &ident_len, error);
@ -955,7 +955,7 @@ void *libretrodb_query_compile(libretrodb_t *db,
if (*error_string) if (*error_string)
goto error; goto error;
} }
else if (isalpha((int)buff.data[buff.offset])) else if (ISALPHA((int)buff.data[buff.offset]))
buff = query_parse_method_call(tmp_error_buff, buff = query_parse_method_call(tmp_error_buff,
error_buff_len, error_buff_len,
buff, &q->root, error_string); buff, &q->root, error_string);

View File

@ -5371,7 +5371,7 @@ static int menu_entries_elem_get_first_char(
if ((path = list->list[offset].alt if ((path = list->list[offset].alt
? list->list[offset].alt ? list->list[offset].alt
: list->list[offset].path)) : list->list[offset].path))
ret = tolower((int)*path); ret = TOLOWER((int)*path);
/* "Normalize" non-alphabetical entries so they /* "Normalize" non-alphabetical entries so they
* are lumped together for purposes of jumping. */ * are lumped together for purposes of jumping. */
@ -15045,7 +15045,7 @@ static void command_event_set_savestate_auto_index(
continue; continue;
end = dir_elem + strlen(dir_elem); end = dir_elem + strlen(dir_elem);
while ((end > dir_elem) && isdigit((int)end[-1])) while ((end > dir_elem) && ISDIGIT((int)end[-1]))
end--; end--;
idx = (unsigned)strtoul(end, NULL, 0); idx = (unsigned)strtoul(end, NULL, 0);
@ -17907,7 +17907,7 @@ static const char *core_option_manager_parse_value_label(
/* Any label starting with a digit (or +/-) /* Any label starting with a digit (or +/-)
* cannot be a boolean string, and requires * cannot be a boolean string, and requires
* no further processing */ * no further processing */
if (isdigit((unsigned char)*label) || if (ISDIGIT((unsigned char)*label) ||
(*label == '+') || (*label == '+') ||
(*label == '-')) (*label == '-'))
return label; return label;
@ -28031,8 +28031,8 @@ static const char *input_config_get_prefix(unsigned user, bool meta)
enum retro_key input_config_translate_str_to_rk(const char *str) enum retro_key input_config_translate_str_to_rk(const char *str)
{ {
size_t i; size_t i;
if (strlen(str) == 1 && isalpha((int)*str)) if (strlen(str) == 1 && ISALPHA((int)*str))
return (enum retro_key)(RETROK_a + (tolower((int)*str) - (int)'a')); return (enum retro_key)(RETROK_a + (TOLOWER((int)*str) - (int)'a'));
for (i = 0; input_config_key_map[i].str; i++) for (i = 0; input_config_key_map[i].str; i++)
{ {
if (string_is_equal_noncase(input_config_key_map[i].str, str)) if (string_is_equal_noncase(input_config_key_map[i].str, str))
@ -28140,7 +28140,7 @@ static void input_config_parse_joy_button(
if (*btn == 'h') if (*btn == 'h')
{ {
const char *str = btn + 1; const char *str = btn + 1;
if (str && isdigit((int)*str)) if (str && ISDIGIT((int)*str))
parse_hat(bind, str); parse_hat(bind, str);
} }
else else

View File

@ -215,10 +215,10 @@ static int detect_ps1_game_sub(intfstream_t *fp,
*game_id++ = toupper(*tmp++); *game_id++ = toupper(*tmp++);
*game_id++ = '-'; *game_id++ = '-';
if (!isalnum(*tmp)) if (!ISALNUM(*tmp))
tmp++; tmp++;
while (isalnum(*tmp)) while (ISALNUM(*tmp))
{ {
*game_id++ = *tmp++; *game_id++ = *tmp++;
if (*tmp == '.') if (*tmp == '.')