Skip to content

Commit

Permalink
Add ctype variants to stdstring and use it in RA
Browse files Browse the repository at this point in the history
  • Loading branch information
inactive123 committed Sep 27, 2020
1 parent f1432db commit c744bae
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 41 deletions.
15 changes: 11 additions & 4 deletions core_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -1351,8 +1351,8 @@ bool core_info_hw_api_supported(core_info_t *info)
{
case STATE_API_NAME:
{
if ( isupper((unsigned char)cur_api[j]) ||
islower((unsigned char)cur_api[j]))
if ( ISUPPER((unsigned char)cur_api[j]) ||
ISLOWER((unsigned char)cur_api[j]))
api_str[api_pos++] = cur_api[j];
else
{
Expand Down Expand Up @@ -1401,14 +1401,21 @@ bool core_info_hw_api_supported(core_info_t *info)
}
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;

if (major_str_pos < sizeof(major_str) - 1)
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)
minor_str[minor_str_pos++] = cur_api[j];
Expand Down
2 changes: 1 addition & 1 deletion gfx/drivers_font_renderer/freetype.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

for (i = 0; i < 256; i++)
if (isalnum(i))
if (ISALNUM(i))
font_renderer_ft_get_glyph(handle, i);

return true;
Expand Down
3 changes: 2 additions & 1 deletion gfx/drivers_font_renderer/stb.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <file/file_path.h>
#include <streams/file_stream.h>
#include <retro_miscellaneous.h>
#include <string/stdstring.h>

#include "../font_driver.h"
#include "../../verbosity.h"
Expand Down Expand Up @@ -108,7 +109,7 @@ static bool font_renderer_stb_create_atlas(stb_font_renderer_t *self,
g->height = c->y1 - c->y0;

/* 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_height = height * 1.2;
Expand Down
3 changes: 2 additions & 1 deletion gfx/drivers_font_renderer/stb_unicode.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <file/file_path.h>
#include <streams/file_stream.h>
#include <string/stdstring.h>
#include <retro_miscellaneous.h>

#ifdef WIIU
Expand Down Expand Up @@ -220,7 +221,7 @@ static bool font_renderer_stb_unicode_create_atlas(

for (i = 0; i < 256; i++)
{
if (isalnum(i))
if (ISALNUM(i))
font_renderer_stb_unicode_get_glyph(self, i);
}

Expand Down
6 changes: 3 additions & 3 deletions libretro-common/file/config_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ static char *config_file_extract_value(char *line, bool is_value)

if (is_value)
{
while (isspace((int)*line))
while (ISSPACE((int)*line))
line++;

/* If we don't have an equal sign here,
Expand All @@ -230,7 +230,7 @@ static char *config_file_extract_value(char *line, bool is_value)
line++;
}

while (isspace((int)*line))
while (ISSPACE((int)*line))
line++;

/* Note: From this point on, an empty value
Expand Down Expand Up @@ -517,7 +517,7 @@ static bool config_file_parse_line(config_file_t *conf,
}

/* Skip to first non-space character */
while (isspace((int)*line))
while (ISSPACE((int)*line))
line++;

/* Allocate storage for key */
Expand Down
38 changes: 28 additions & 10 deletions libretro-common/include/string/stdstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,32 @@

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)
{
Expand Down Expand Up @@ -85,12 +110,6 @@ static INLINE size_t strlen_size(const char *str, size_t size)
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,
const char *b)
Expand All @@ -111,9 +130,6 @@ static INLINE bool string_is_equal_case_insensitive(const char *a,
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_lower(char *s);
Expand Down Expand Up @@ -175,6 +191,8 @@ char *string_init(const char *src);

void string_set(char **string, const char *src);

extern const unsigned char lr_char_props[256];

RETRO_END_DECLS

#endif
3 changes: 2 additions & 1 deletion libretro-common/streams/file_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <compat/msvc.h>
#endif

#include <string/stdstring.h>
#include <streams/file_stream.h>
#define VFS_FRONTEND
#include <vfs/vfs_implementation.h>
Expand Down Expand Up @@ -255,7 +256,7 @@ int filestream_scanf(RFILE *stream, const char* format, ...)
*subfmtiter++ = *format++;
}

while (isdigit((unsigned char)*format))
while (ISDIGIT((unsigned char)*format))
*subfmtiter++ = *format++; /* width */

/* length */
Expand Down
28 changes: 24 additions & 4 deletions libretro-common/string/stdstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@
#include <string/stdstring.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)
{
return src ? strdup(src) : NULL;
Expand Down Expand Up @@ -124,7 +144,7 @@ char *string_trim_whitespace_left(char *const s)
size_t len = strlen(s);
char *current = s;

while (*current && isspace((unsigned char)*current))
while (*current && ISSPACE((unsigned char)*current))
{
++current;
--len;
Expand All @@ -145,13 +165,13 @@ char *string_trim_whitespace_right(char *const s)
size_t len = strlen(s);
char *current = s + len - 1;

while (current != s && isspace((unsigned char)*current))
while (current != s && ISSPACE((unsigned char)*current))
{
--current;
--len;
}

current[isspace((unsigned char)*current) ? 0 : 1] = '\0';
current[ISSPACE((unsigned char)*current) ? 0 : 1] = '\0';
}

return s;
Expand Down Expand Up @@ -355,7 +375,7 @@ unsigned string_to_unsigned(const char *str)

for (ptr = str; *ptr != '\0'; ptr++)
{
if (!isdigit((unsigned char)*ptr))
if (!ISDIGIT((unsigned char)*ptr))
return 0;
}

Expand Down
16 changes: 8 additions & 8 deletions libretro-db/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ static struct buffer query_parse_integer(
}
else
{
while (isdigit((int)buff.data[buff.offset]))
while (ISDIGIT((int)buff.data[buff.offset]))
buff.offset++;
}

Expand All @@ -339,7 +339,7 @@ static struct buffer query_parse_integer(
static struct buffer query_chomp(struct buffer buff)
{
for (; (unsigned)buff.offset < buff.len
&& isspace((int)buff.data[buff.offset]); buff.offset++);
&& ISSPACE((int)buff.data[buff.offset]); buff.offset++);
return buff;
}

Expand Down Expand Up @@ -512,7 +512,7 @@ static struct buffer query_parse_value(
query_peek(buff, "'", STRLEN_CONST("'")))
buff = query_parse_string(s, len,
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);
return buff;
}
Expand Down Expand Up @@ -556,7 +556,7 @@ static struct buffer query_get_ident(
*len = 0;
query_peek_char(s, _len, buff, &c, error);

if (*error || !isalpha((int)c))
if (*error || !ISALPHA((int)c))
return buff;

buff.offset++;
Expand All @@ -565,7 +565,7 @@ static struct buffer query_get_ident(

while (!*error)
{
if (!(isalnum((int)c) || c == '_'))
if (!(ISALNUM((int)c) || c == '_'))
break;
buff.offset++;
*len = *len + 1;
Expand Down Expand Up @@ -608,7 +608,7 @@ static struct buffer query_parse_argument(
buff = query_chomp(buff);

if (
isalpha((int)buff.data[buff.offset])
ISALPHA((int)buff.data[buff.offset])
&& !(
query_peek(buff, "nil", STRLEN_CONST("nil"))
|| query_peek(buff, "true", STRLEN_CONST("true"))
Expand Down Expand Up @@ -814,7 +814,7 @@ static struct buffer query_parse_table(
goto clean;
}

if (isalpha((int)buff.data[buff.offset]))
if (ISALPHA((int)buff.data[buff.offset]))
{
buff = query_get_ident(s, len,
buff, &ident_name, &ident_len, error);
Expand Down Expand Up @@ -955,7 +955,7 @@ void *libretrodb_query_compile(libretrodb_t *db,
if (*error_string)
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,
error_buff_len,
buff, &q->root, error_string);
Expand Down
12 changes: 6 additions & 6 deletions retroarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -5371,7 +5371,7 @@ static int menu_entries_elem_get_first_char(
if ((path = list->list[offset].alt
? list->list[offset].alt
: list->list[offset].path))
ret = tolower((int)*path);
ret = TOLOWER((int)*path);

/* "Normalize" non-alphabetical entries so they
* are lumped together for purposes of jumping. */
Expand Down Expand Up @@ -15045,7 +15045,7 @@ static void command_event_set_savestate_auto_index(
continue;

end = dir_elem + strlen(dir_elem);
while ((end > dir_elem) && isdigit((int)end[-1]))
while ((end > dir_elem) && ISDIGIT((int)end[-1]))
end--;

idx = (unsigned)strtoul(end, NULL, 0);
Expand Down Expand Up @@ -17907,7 +17907,7 @@ static const char *core_option_manager_parse_value_label(
/* Any label starting with a digit (or +/-)
* cannot be a boolean string, and requires
* no further processing */
if (isdigit((unsigned char)*label) ||
if (ISDIGIT((unsigned char)*label) ||
(*label == '+') ||
(*label == '-'))
return label;
Expand Down Expand Up @@ -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)
{
size_t i;
if (strlen(str) == 1 && isalpha((int)*str))
return (enum retro_key)(RETROK_a + (tolower((int)*str) - (int)'a'));
if (strlen(str) == 1 && ISALPHA((int)*str))
return (enum retro_key)(RETROK_a + (TOLOWER((int)*str) - (int)'a'));
for (i = 0; input_config_key_map[i].str; i++)
{
if (string_is_equal_noncase(input_config_key_map[i].str, str))
Expand Down Expand Up @@ -28140,7 +28140,7 @@ static void input_config_parse_joy_button(
if (*btn == 'h')
{
const char *str = btn + 1;
if (str && isdigit((int)*str))
if (str && ISDIGIT((int)*str))
parse_hat(bind, str);
}
else
Expand Down
4 changes: 2 additions & 2 deletions tasks/task_database_cue.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ static int detect_ps1_game_sub(intfstream_t *fp,
*game_id++ = toupper(*tmp++);
*game_id++ = '-';

if (!isalnum(*tmp))
if (!ISALNUM(*tmp))
tmp++;

while (isalnum(*tmp))
while (ISALNUM(*tmp))
{
*game_id++ = *tmp++;
if (*tmp == '.')
Expand Down

0 comments on commit c744bae

Please sign in to comment.