Cleanup string manipulation

This commit is contained in:
twinaphex 2018-02-01 11:16:13 +01:00
parent a7bad98b39
commit 8d99fd7ce0
3 changed files with 31 additions and 42 deletions

View File

@ -61,36 +61,6 @@
#define DB_CURSOR_SIZE 0x7c9dede0U
#define DB_CURSOR_SERIAL 0x1b843ec5U
static void database_info_build_query_add_quote(char *s, size_t len)
{
strlcat(s, "\"", len);
}
static void database_info_build_query_add_bracket_open(char *s, size_t len)
{
strlcat(s, "{'", len);
}
static void database_info_build_query_add_bracket_close(char *s, size_t len)
{
strlcat(s, "}", len);
}
static void database_info_build_query_add_colon(char *s, size_t len)
{
strlcat(s, "':", len);
}
static void database_info_build_query_add_glob_open(char *s, size_t len)
{
strlcat(s, "glob('*", len);
}
static void database_info_build_query_add_glob_close(char *s, size_t len)
{
strlcat(s, "*')", len);
}
int database_info_build_query_enum(char *s, size_t len,
enum database_query_type type,
const char *path)
@ -98,7 +68,8 @@ int database_info_build_query_enum(char *s, size_t len,
bool add_quotes = true;
bool add_glob = false;
database_info_build_query_add_bracket_open(s, len);
string_add_bracket_open(s, len);
string_add_single_quote(s, len);
switch (type)
{
@ -169,17 +140,19 @@ int database_info_build_query_enum(char *s, size_t len,
break;
}
database_info_build_query_add_colon(s, len);
string_add_single_quote(s, len);
string_add_colon(s, len);
if (add_glob)
database_info_build_query_add_glob_open(s, len);
string_add_glob_open(s, len);
if (add_quotes)
database_info_build_query_add_quote(s, len);
string_add_quote(s, len);
strlcat(s, path, len);
if (add_glob)
database_info_build_query_add_glob_close(s, len);
string_add_glob_close(s, len);
if (add_quotes)
database_info_build_query_add_quote(s, len);
database_info_build_query_add_bracket_close(s, len);
string_add_quote(s, len);
string_add_bracket_close(s, len);
#if 0
RARCH_LOG("query: %s\n", s);

View File

@ -31,6 +31,7 @@
#include <retro_common_api.h>
#include <retro_inline.h>
#include <compat/strl.h>
RETRO_BEGIN_DECLS
@ -53,6 +54,24 @@ static INLINE bool string_is_not_equal(const char *a, const char *b)
return !string_is_equal(a, b);
}
#define string_add_pair_open(s, size) strlcat((s), " (", (size))
#define string_add_pair_close(s, size) strlcat((s), ")", (size))
#define string_add_bracket_open(s, size) strlcat((s), "{", (size))
#define string_add_bracket_close(s, size) strlcat((s), "}", (size))
#define string_add_single_quote(s, size) strlcat((s), "'", (size))
#define string_add_quote(s, size) strlcat((s), "\"", (size))
#define string_add_colon(s, size) strlcat((s), ":", (size))
#define string_add_glob_open(s, size) strlcat((s), "glob('*", (size))
#define string_add_glob_close(s, size) strlcat((s), "*')", (size))
static INLINE void string_add_between_pairs(char *s, const char *str,
size_t size)
{
string_add_pair_open(s, size);
strlcat(s, str, size);
string_add_pair_close(s, size);
}
#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)

View File

@ -3136,11 +3136,8 @@ void netplay_refresh_rooms_menu(file_list_t *list)
char country[PATH_MAX_LENGTH] = {0};
if (*netplay_room_list[i].country)
{
strlcat(country, " (", sizeof(country));
strlcat(country, netplay_room_list[i].country, sizeof(country));
strlcat(country, ")", sizeof(country));
}
string_add_between_pairs(country, netplay_room_list[i].country,
sizeof(country));
/* Uncomment this to debug mismatched room parameters*/
#if 0