Added more string calls + fix prototypes

- Added g_strrchr() and g_strstr()
- Made C prototypes for g_strchr() and g_strnchr() compatible with
  expected C library functions
This commit is contained in:
matt335672 2021-10-25 16:13:09 +01:00
parent 50e37bf673
commit a7b48cd1cf
2 changed files with 37 additions and 6 deletions

View File

@ -188,7 +188,7 @@ g_strlen(const char *text)
/*****************************************************************************/
/* locates char in text */
const char *
char *
g_strchr(const char *text, int c)
{
if (text == NULL)
@ -196,12 +196,27 @@ g_strchr(const char *text, int c)
return 0;
}
return strchr(text, c);
/* Cast needed to compile with C++ */
return (char *)strchr(text, c);
}
/*****************************************************************************/
/* locates char in text */
char *
g_strrchr(const char *text, int c)
{
if (text == NULL)
{
return 0;
}
/* Cast needed to compile with C++ */
return (char *)strrchr(text, c);
}
/*****************************************************************************/
/* locates char in text with length */
const char *
char *
g_strnchr(const char *text, int c, int len)
{
if (text == NULL || len <= 0)
@ -209,7 +224,7 @@ g_strnchr(const char *text, int c, int len)
return NULL;
}
return (const char *)memchr(text, c, len);
return (char *)memchr(text, c, len);
}
/*****************************************************************************/
@ -680,6 +695,20 @@ g_pos(const char *str, const char *to_find)
return (pp - str);
}
/*****************************************************************************/
char *
g_strstr(const char *haystack, const char *needle)
{
if (haystack == NULL || needle == NULL)
{
return NULL;
}
/* Cast needed to compile with C++ */
return (char *)strstr(haystack, needle);
}
/*****************************************************************************/
int
g_mbstowcs(twchar *dest, const char *src, int n)

View File

@ -175,8 +175,9 @@ g_bitmask_to_str(int bitmask, const struct bitmask_string[],
char delim, char *buff, int bufflen);
int g_strlen(const char *text);
const char *g_strchr(const char *text, int c);
const char *g_strnchr(const char *text, int c, int len);
char *g_strchr(const char *text, int c);
char *g_strrchr(const char *text, int c);
char *g_strnchr(const char *text, int c, int len);
char *g_strcpy(char *dest, const char *src);
char *g_strncpy(char *dest, const char *src, int len);
char *g_strcat(char *dest, const char *src);
@ -202,6 +203,7 @@ int g_htoi(char *str);
int g_bytes_to_hexstr(const void *bytes, int num_bytes, char *out_str,
int bytes_out_str);
int g_pos(const char *str, const char *to_find);
char *g_strstr(const char *haystack, const char *needle);
int g_mbstowcs(twchar *dest, const char *src, int n);
int g_wcstombs(char *dest, const twchar *src, int n);
int g_strtrim(char *str, int trim_flags);