strutil: character test functions return gboolean instead of int.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2018-01-21 11:04:25 +03:00
parent 2a973f7a46
commit 52d1980c46
5 changed files with 70 additions and 68 deletions

View File

@ -103,10 +103,11 @@ typedef enum
/* all functions in str_class must be defined for every encoding */
struct str_class
{
/* *INDENT-OFF* */
gchar *(*conv_gerror_message) (GError * error, const char *def_msg);
/*I*/ estr_t (*vfs_convert_to) (GIConv coder, const char *string, int size, GString * buffer);
/*I*/ void (*insert_replace_char) (GString * buffer);
int (*is_valid_string) (const char *);
gboolean (*is_valid_string) (const char *);
/*I*/ int (*is_valid_char) (const char *, size_t);
/*I*/ void (*cnext_char) (const char **);
void (*cprev_char) (const char **);
@ -114,17 +115,17 @@ struct str_class
/*I*/ void (*cprev_char_safe) (const char **);
/*I*/ int (*cnext_noncomb_char) (const char **text);
/*I*/ int (*cprev_noncomb_char) (const char **text, const char *begin);
/*I*/ int (*char_isspace) (const char *);
/*I*/ int (*char_ispunct) (const char *);
/*I*/ int (*char_isalnum) (const char *);
/*I*/ int (*char_isdigit) (const char *);
/*I*/ int (*char_isprint) (const char *);
/*I*/ gboolean (*char_isspace) (const char *);
/*I*/ gboolean (*char_ispunct) (const char *);
/*I*/ gboolean (*char_isalnum) (const char *);
/*I*/ gboolean (*char_isdigit) (const char *);
/*I*/ gboolean (*char_isprint) (const char *);
/*I*/ gboolean (*char_iscombiningmark) (const char *);
/*I*/ int (*length) (const char *);
/*I*/ int (*length2) (const char *, int);
/*I*/ int (*length_noncomb) (const char *);
/*I*/ int (*char_toupper) (const char *, char **, size_t *);
int (*char_tolower) (const char *, char **, size_t *);
/*I*/ gboolean (*char_toupper) (const char *, char **, size_t *);
gboolean (*char_tolower) (const char *, char **, size_t *);
void (*fix_string) (char *);
/*I*/ const char *(*term_form) (const char *);
/*I*/ const char *(*fit_to_term) (const char *, int, align_crt_t);
@ -150,7 +151,8 @@ struct str_class
/*I*/ char *(*create_key_for_filename) (const char *text, gboolean case_sen);
/*I*/ int (*key_collate) (const char *t1, const char *t2, gboolean case_sen);
/*I*/ void (*release_key) (char *key, gboolean case_sen);
/*I*/};
/* *INDENT-ON* */
};
/*** global variables defined in .c file *********************************************************/
@ -245,7 +247,7 @@ estr_t str_translate_char (GIConv conv, const char *ch, size_t ch_size,
/* test, if text is valid in terminal encoding
* I
*/
int str_is_valid_string (const char *text);
gboolean str_is_valid_string (const char *text);
/* test, if first char of ch is valid
* size, how many bytes characters occupied, could be (size_t)(-1)
@ -322,27 +324,27 @@ int str_cprev_noncomb_char (const char **text, const char *begin);
/* if first characters in ch is space, tabulator or new lines
* I
*/
int str_isspace (const char *ch);
gboolean str_isspace (const char *ch);
/* if first characters in ch is punctuation or symbol
* I
*/
int str_ispunct (const char *ch);
gboolean str_ispunct (const char *ch);
/* if first characters in ch is alphanum
* I
*/
int str_isalnum (const char *ch);
gboolean str_isalnum (const char *ch);
/* if first characters in ch is digit
* I
*/
int str_isdigit (const char *ch);
gboolean str_isdigit (const char *ch);
/* if first characters in ch is printable
* I
*/
int str_isprint (const char *ch);
gboolean str_isprint (const char *ch);
/* if first characters in ch is a combining mark (only in utf-8)
* combining makrs are assumed to be zero width
@ -354,13 +356,13 @@ gboolean str_iscombiningmark (const char *ch);
* decrase remain by size of returned characters
* if out is not big enough, do nothing
*/
int str_toupper (const char *ch, char **out, size_t * remain);
gboolean str_toupper (const char *ch, char **out, size_t * remain);
/* write upper from of fisrt characters in ch into out
* decrase remain by size of returned characters
* if out is not big enough, do nothing
*/
int str_tolower (const char *ch, char **out, size_t * remain);
gboolean str_tolower (const char *ch, char **out, size_t * remain);
/* return length of text in characters
* I

View File

@ -714,7 +714,7 @@ str_column_to_pos (const char *text, size_t pos)
/* --------------------------------------------------------------------------------------------- */
int
gboolean
str_isspace (const char *ch)
{
return used_class.char_isspace (ch);
@ -722,7 +722,7 @@ str_isspace (const char *ch)
/* --------------------------------------------------------------------------------------------- */
int
gboolean
str_ispunct (const char *ch)
{
return used_class.char_ispunct (ch);
@ -730,7 +730,7 @@ str_ispunct (const char *ch)
/* --------------------------------------------------------------------------------------------- */
int
gboolean
str_isalnum (const char *ch)
{
return used_class.char_isalnum (ch);
@ -738,7 +738,7 @@ str_isalnum (const char *ch)
/* --------------------------------------------------------------------------------------------- */
int
gboolean
str_isdigit (const char *ch)
{
return used_class.char_isdigit (ch);
@ -746,7 +746,7 @@ str_isdigit (const char *ch)
/* --------------------------------------------------------------------------------------------- */
int
gboolean
str_toupper (const char *ch, char **out, size_t * remain)
{
return used_class.char_toupper (ch, out, remain);
@ -754,7 +754,7 @@ str_toupper (const char *ch, char **out, size_t * remain)
/* --------------------------------------------------------------------------------------------- */
int
gboolean
str_tolower (const char *ch, char **out, size_t * remain)
{
return used_class.char_tolower (ch, out, remain);
@ -762,7 +762,7 @@ str_tolower (const char *ch, char **out, size_t * remain)
/* --------------------------------------------------------------------------------------------- */
int
gboolean
str_isprint (const char *ch)
{
return used_class.char_isprint (ch);
@ -818,7 +818,7 @@ str_search_last (const char *text, const char *search, gboolean case_sen)
/* --------------------------------------------------------------------------------------------- */
int
gboolean
str_is_valid_string (const char *text)
{
return used_class.is_valid_string (text);

View File

@ -84,11 +84,11 @@ str_8bit_insert_replace_char (GString * buffer)
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_8bit_is_valid_string (const char *text)
{
(void) text;
return 1;
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */
@ -143,42 +143,42 @@ str_8bit_cprev_noncomb_char (const char **text, const char *begin)
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_8bit_isspace (const char *text)
{
return char_isspace (text[0]);
return char_isspace (text[0]) != 0;
}
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_8bit_ispunct (const char *text)
{
return char_ispunct (text[0]);
return char_ispunct (text[0]) != 0;
}
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_8bit_isalnum (const char *text)
{
return char_isalnum (text[0]);
return char_isalnum (text[0]) != 0;
}
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_8bit_isdigit (const char *text)
{
return char_isdigit (text[0]);
return char_isdigit (text[0]) != 0;
}
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_8bit_isprint (const char *text)
{
return char_isprint (text[0]);
return char_isprint (text[0]) != 0;
}
/* --------------------------------------------------------------------------------------------- */
@ -196,26 +196,26 @@ static int
str_8bit_toupper (const char *text, char **out, size_t * remain)
{
if (*remain <= 1)
return 0;
return FALSE;
(*out)[0] = char_toupper (text[0]);
(*out)++;
(*remain)--;
return 1;
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_8bit_tolower (const char *text, char **out, size_t * remain)
{
if (*remain <= 1)
return 0;
return FALSE;
(*out)[0] = char_tolower (text[0]);
(*out)++;
(*remain)--;
return 1;
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -57,11 +57,11 @@ str_ascii_insert_replace_char (GString * buffer)
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_ascii_is_valid_string (const char *text)
{
(void) text;
return 1;
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */
@ -116,7 +116,7 @@ str_ascii_cprev_noncomb_char (const char **text, const char *begin)
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_ascii_isspace (const char *text)
{
return g_ascii_isspace ((gchar) text[0]);
@ -124,7 +124,7 @@ str_ascii_isspace (const char *text)
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_ascii_ispunct (const char *text)
{
return g_ascii_ispunct ((gchar) text[0]);
@ -132,7 +132,7 @@ str_ascii_ispunct (const char *text)
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_ascii_isalnum (const char *text)
{
return g_ascii_isalnum ((gchar) text[0]);
@ -140,7 +140,7 @@ str_ascii_isalnum (const char *text)
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_ascii_isdigit (const char *text)
{
return g_ascii_isdigit ((gchar) text[0]);
@ -148,7 +148,7 @@ str_ascii_isdigit (const char *text)
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_ascii_isprint (const char *text)
{
return g_ascii_isprint ((gchar) text[0]);
@ -169,26 +169,26 @@ static int
str_ascii_toupper (const char *text, char **out, size_t * remain)
{
if (*remain <= 1)
return 0;
return FALSE;
(*out)[0] = (char) g_ascii_toupper ((gchar) text[0]);
(*out)++;
(*remain)--;
return 1;
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_ascii_tolower (const char *text, char **out, size_t * remain)
{
if (*remain <= 1)
return 0;
return FALSE;
(*out)[0] = (char) g_ascii_tolower ((gchar) text[0]);
(*out)++;
(*remain)--;
return 1;
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -84,7 +84,7 @@ str_utf8_insert_replace_char (GString * buffer)
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_utf8_is_valid_string (const char *text)
{
return g_utf8_validate (text, -1, NULL);
@ -171,7 +171,7 @@ str_utf8_fix_string (char *text)
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_utf8_isspace (const char *text)
{
gunichar uni;
@ -182,7 +182,7 @@ str_utf8_isspace (const char *text)
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_utf8_ispunct (const char *text)
{
gunichar uni;
@ -193,7 +193,7 @@ str_utf8_ispunct (const char *text)
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_utf8_isalnum (const char *text)
{
gunichar uni;
@ -204,7 +204,7 @@ str_utf8_isalnum (const char *text)
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_utf8_isdigit (const char *text)
{
gunichar uni;
@ -215,7 +215,7 @@ str_utf8_isdigit (const char *text)
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_utf8_isprint (const char *ch)
{
gunichar uni;
@ -273,7 +273,7 @@ str_utf8_cprev_noncomb_char (const char **text, const char *begin)
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_utf8_toupper (const char *text, char **out, size_t * remain)
{
gunichar uni;
@ -281,22 +281,22 @@ str_utf8_toupper (const char *text, char **out, size_t * remain)
uni = g_utf8_get_char_validated (text, -1);
if (uni == (gunichar) (-1) || uni == (gunichar) (-2))
return 0;
return FALSE;
uni = g_unichar_toupper (uni);
left = g_unichar_to_utf8 (uni, NULL);
if (left >= *remain)
return 0;
return FALSE;
left = g_unichar_to_utf8 (uni, *out);
(*out) += left;
(*remain) -= left;
return 1;
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
str_utf8_tolower (const char *text, char **out, size_t * remain)
{
gunichar uni;
@ -304,17 +304,17 @@ str_utf8_tolower (const char *text, char **out, size_t * remain)
uni = g_utf8_get_char_validated (text, -1);
if (uni == (gunichar) (-1) || uni == (gunichar) (-2))
return 0;
return FALSE;
uni = g_unichar_tolower (uni);
left = g_unichar_to_utf8 (uni, NULL);
if (left >= *remain)
return 0;
return FALSE;
left = g_unichar_to_utf8 (uni, *out);
(*out) += left;
(*remain) -= left;
return 1;
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */