From 615eba776da90ad2f68b201acaca4b336cf34cd1 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sat, 20 Jun 2015 21:40:26 +0300 Subject: [PATCH] Ticket #3420: code cleanup before 4.8.15 release. lib/strutil/*.c: apply template. Signed-off-by: Andrew Borodin --- lib/strutil/strutil.c | 268 ++++++++++++++++++++++++++++++++++++--------- lib/strutil/strutil8bit.c | 121 ++++++++++++++++++-- lib/strutil/strutilascii.c | 104 +++++++++++++++++- lib/strutil/strutilutf8.c | 198 +++++++++++++++++++++++++++------ lib/strutil/strverscmp.c | 18 ++- 5 files changed, 617 insertions(+), 92 deletions(-) diff --git a/lib/strutil/strutil.c b/lib/strutil/strutil.c index 7f52fa40b..91d0562c9 100644 --- a/lib/strutil/strutil.c +++ b/lib/strutil/strutil.c @@ -33,7 +33,19 @@ #include "lib/global.h" #include "lib/strutil.h" -/*names, that are used for utf-8 */ +/*** global variables ****************************************************************************/ + +GIConv str_cnv_to_term; +GIConv str_cnv_from_term; +GIConv str_cnv_not_convert = INVALID_CONV; + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/* names, that are used for utf-8 */ static const char *str_utf8_encodings[] = { "utf-8", "utf8", @@ -66,9 +78,9 @@ static char *term_encoding = NULL; /* function for encoding specific operations */ static struct str_class used_class; -GIConv str_cnv_to_term; -GIConv str_cnv_from_term; -GIConv str_cnv_not_convert = INVALID_CONV; +/* --------------------------------------------------------------------------------------------- */ +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ /* if enc is same encoding like on terminal */ static int @@ -77,25 +89,7 @@ str_test_not_convert (const char *enc) return g_ascii_strcasecmp (enc, codeset) == 0; } -GIConv -str_crt_conv_to (const char *to_enc) -{ - return (!str_test_not_convert (to_enc)) ? g_iconv_open (to_enc, codeset) : str_cnv_not_convert; -} - -GIConv -str_crt_conv_from (const char *from_enc) -{ - return (!str_test_not_convert (from_enc)) - ? g_iconv_open (codeset, from_enc) : str_cnv_not_convert; -} - -void -str_close_conv (GIConv conv) -{ - if (conv != str_cnv_not_convert) - g_iconv_close (conv); -} +/* --------------------------------------------------------------------------------------------- */ static estr_t _str_convert (GIConv coder, const char *string, int size, GString * buffer) @@ -221,24 +215,92 @@ _str_convert (GIConv coder, const char *string, int size, GString * buffer) return state; } +/* --------------------------------------------------------------------------------------------- */ + +static int +str_test_encoding_class (const char *encoding, const char **table) +{ + int result = 0; + + if (encoding != NULL) + { + int t; + + for (t = 0; table[t] != NULL; t++) + if (g_ascii_strncasecmp (encoding, table[t], strlen (table[t])) == 0) + result++; + } + + return result; +} + +/* --------------------------------------------------------------------------------------------- */ + +static void +str_choose_str_functions (void) +{ + if (str_test_encoding_class (codeset, str_utf8_encodings)) + used_class = str_utf8_init (); + else if (str_test_encoding_class (codeset, str_8bit_encodings)) + used_class = str_8bit_init (); + else + used_class = str_ascii_init (); +} + +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +GIConv +str_crt_conv_to (const char *to_enc) +{ + return (!str_test_not_convert (to_enc)) ? g_iconv_open (to_enc, codeset) : str_cnv_not_convert; +} + +/* --------------------------------------------------------------------------------------------- */ + +GIConv +str_crt_conv_from (const char *from_enc) +{ + return (!str_test_not_convert (from_enc)) + ? g_iconv_open (codeset, from_enc) : str_cnv_not_convert; +} + +/* --------------------------------------------------------------------------------------------- */ + +void +str_close_conv (GIConv conv) +{ + if (conv != str_cnv_not_convert) + g_iconv_close (conv); +} + +/* --------------------------------------------------------------------------------------------- */ + estr_t str_convert (GIConv coder, const char *string, GString * buffer) { return _str_convert (coder, string, -1, buffer); } +/* --------------------------------------------------------------------------------------------- */ + estr_t str_nconvert (GIConv coder, const char *string, int size, GString * buffer) { return _str_convert (coder, string, size, buffer); } +/* --------------------------------------------------------------------------------------------- */ + gchar * str_conv_gerror_message (GError * mcerror, const char *def_msg) { return used_class.conv_gerror_message (mcerror, def_msg); } +/* --------------------------------------------------------------------------------------------- */ + estr_t str_vfs_convert_from (GIConv coder, const char *string, GString * buffer) { @@ -252,12 +314,16 @@ str_vfs_convert_from (GIConv coder, const char *string, GString * buffer) return result; } +/* --------------------------------------------------------------------------------------------- */ + estr_t str_vfs_convert_to (GIConv coder, const char *string, int size, GString * buffer) { return used_class.vfs_convert_to (coder, string, size, buffer); } +/* --------------------------------------------------------------------------------------------- */ + void str_printf (GString * buffer, const char *format, ...) { @@ -268,12 +334,16 @@ str_printf (GString * buffer, const char *format, ...) va_end (ap); } +/* --------------------------------------------------------------------------------------------- */ + void str_insert_replace_char (GString * buffer) { used_class.insert_replace_char (buffer); } +/* --------------------------------------------------------------------------------------------- */ + estr_t str_translate_char (GIConv conv, const char *keys, size_t ch_size, char *output, size_t out_size) { @@ -292,6 +362,7 @@ str_translate_char (GIConv conv, const char *keys, size_t ch_size, char *output, return ESTR_SUCCESS; } +/* --------------------------------------------------------------------------------------------- */ const char * str_detect_termencoding (void) @@ -308,33 +379,7 @@ str_detect_termencoding (void) return term_encoding; } -static int -str_test_encoding_class (const char *encoding, const char **table) -{ - int result = 0; - - if (encoding != NULL) - { - int t; - - for (t = 0; table[t] != NULL; t++) - if (g_ascii_strncasecmp (encoding, table[t], strlen (table[t])) == 0) - result++; - } - - return result; -} - -static void -str_choose_str_functions (void) -{ - if (str_test_encoding_class (codeset, str_utf8_encodings)) - used_class = str_utf8_init (); - else if (str_test_encoding_class (codeset, str_8bit_encodings)) - used_class = str_8bit_init (); - else - used_class = str_ascii_init (); -} +/* --------------------------------------------------------------------------------------------- */ gboolean str_isutf8 (const char *codeset_name) @@ -342,6 +387,8 @@ str_isutf8 (const char *codeset_name) return (str_test_encoding_class (codeset_name, str_utf8_encodings) != 0); } +/* --------------------------------------------------------------------------------------------- */ + void str_init_strings (const char *termenc) { @@ -371,6 +418,8 @@ str_init_strings (const char *termenc) str_choose_str_functions (); } +/* --------------------------------------------------------------------------------------------- */ + void str_uninit_strings (void) { @@ -380,30 +429,40 @@ str_uninit_strings (void) g_free (codeset); } +/* --------------------------------------------------------------------------------------------- */ + const char * str_term_form (const char *text) { return used_class.term_form (text); } +/* --------------------------------------------------------------------------------------------- */ + const char * str_fit_to_term (const char *text, int width, align_crt_t just_mode) { return used_class.fit_to_term (text, width, just_mode); } +/* --------------------------------------------------------------------------------------------- */ + const char * str_term_trim (const char *text, int width) { return used_class.term_trim (text, width); } +/* --------------------------------------------------------------------------------------------- */ + const char * str_term_substring (const char *text, int start, int width) { return used_class.term_substring (text, start, width); } +/* --------------------------------------------------------------------------------------------- */ + char * str_get_next_char (char *text) { @@ -412,6 +471,8 @@ str_get_next_char (char *text) return text; } +/* --------------------------------------------------------------------------------------------- */ + const char * str_cget_next_char (const char *text) { @@ -419,18 +480,24 @@ str_cget_next_char (const char *text) return text; } +/* --------------------------------------------------------------------------------------------- */ + void str_next_char (char **text) { used_class.cnext_char ((const char **) text); } +/* --------------------------------------------------------------------------------------------- */ + void str_cnext_char (const char **text) { used_class.cnext_char (text); } +/* --------------------------------------------------------------------------------------------- */ + char * str_get_prev_char (char *text) { @@ -438,6 +505,8 @@ str_get_prev_char (char *text) return text; } +/* --------------------------------------------------------------------------------------------- */ + const char * str_cget_prev_char (const char *text) { @@ -445,18 +514,24 @@ str_cget_prev_char (const char *text) return text; } +/* --------------------------------------------------------------------------------------------- */ + void str_prev_char (char **text) { used_class.cprev_char ((const char **) text); } +/* --------------------------------------------------------------------------------------------- */ + void str_cprev_char (const char **text) { used_class.cprev_char (text); } +/* --------------------------------------------------------------------------------------------- */ + char * str_get_next_char_safe (char *text) { @@ -464,6 +539,8 @@ str_get_next_char_safe (char *text) return text; } +/* --------------------------------------------------------------------------------------------- */ + const char * str_cget_next_char_safe (const char *text) { @@ -471,18 +548,24 @@ str_cget_next_char_safe (const char *text) return text; } +/* --------------------------------------------------------------------------------------------- */ + void str_next_char_safe (char **text) { used_class.cnext_char_safe ((const char **) text); } +/* --------------------------------------------------------------------------------------------- */ + void str_cnext_char_safe (const char **text) { used_class.cnext_char_safe (text); } +/* --------------------------------------------------------------------------------------------- */ + char * str_get_prev_char_safe (char *text) { @@ -490,6 +573,8 @@ str_get_prev_char_safe (char *text) return text; } +/* --------------------------------------------------------------------------------------------- */ + const char * str_cget_prev_char_safe (const char *text) { @@ -497,162 +582,215 @@ str_cget_prev_char_safe (const char *text) return text; } +/* --------------------------------------------------------------------------------------------- */ + void str_prev_char_safe (char **text) { used_class.cprev_char_safe ((const char **) text); } +/* --------------------------------------------------------------------------------------------- */ + void str_cprev_char_safe (const char **text) { used_class.cprev_char_safe (text); } +/* --------------------------------------------------------------------------------------------- */ + int str_next_noncomb_char (char **text) { return used_class.cnext_noncomb_char ((const char **) text); } +/* --------------------------------------------------------------------------------------------- */ + int str_cnext_noncomb_char (const char **text) { return used_class.cnext_noncomb_char (text); } +/* --------------------------------------------------------------------------------------------- */ + int str_prev_noncomb_char (char **text, const char *begin) { return used_class.cprev_noncomb_char ((const char **) text, begin); } +/* --------------------------------------------------------------------------------------------- */ + int str_cprev_noncomb_char (const char **text, const char *begin) { return used_class.cprev_noncomb_char (text, begin); } +/* --------------------------------------------------------------------------------------------- */ + int str_is_valid_char (const char *ch, size_t size) { return used_class.is_valid_char (ch, size); } +/* --------------------------------------------------------------------------------------------- */ + int str_term_width1 (const char *text) { return used_class.term_width1 (text); } +/* --------------------------------------------------------------------------------------------- */ + int str_term_width2 (const char *text, size_t length) { return used_class.term_width2 (text, length); } +/* --------------------------------------------------------------------------------------------- */ + int str_term_char_width (const char *text) { return used_class.term_char_width (text); } +/* --------------------------------------------------------------------------------------------- */ + int str_offset_to_pos (const char *text, size_t length) { return used_class.offset_to_pos (text, length); } +/* --------------------------------------------------------------------------------------------- */ + int str_length (const char *text) { return used_class.length (text); } +/* --------------------------------------------------------------------------------------------- */ + int str_length_char (const char *text) { return str_cget_next_char_safe (text) - text; } +/* --------------------------------------------------------------------------------------------- */ + int str_length2 (const char *text, int size) { return used_class.length2 (text, size); } +/* --------------------------------------------------------------------------------------------- */ + int str_length_noncomb (const char *text) { return used_class.length_noncomb (text); } +/* --------------------------------------------------------------------------------------------- */ + int str_column_to_pos (const char *text, size_t pos) { return used_class.column_to_pos (text, pos); } +/* --------------------------------------------------------------------------------------------- */ + int str_isspace (const char *ch) { return used_class.char_isspace (ch); } +/* --------------------------------------------------------------------------------------------- */ + int str_ispunct (const char *ch) { return used_class.char_ispunct (ch); } +/* --------------------------------------------------------------------------------------------- */ + int str_isalnum (const char *ch) { return used_class.char_isalnum (ch); } +/* --------------------------------------------------------------------------------------------- */ + int str_isdigit (const char *ch) { return used_class.char_isdigit (ch); } +/* --------------------------------------------------------------------------------------------- */ + int str_toupper (const char *ch, char **out, size_t * remain) { return used_class.char_toupper (ch, out, remain); } +/* --------------------------------------------------------------------------------------------- */ + int str_tolower (const char *ch, char **out, size_t * remain) { return used_class.char_tolower (ch, out, remain); } +/* --------------------------------------------------------------------------------------------- */ + int str_isprint (const char *ch) { return used_class.char_isprint (ch); } +/* --------------------------------------------------------------------------------------------- */ + gboolean str_iscombiningmark (const char *ch) { return used_class.char_iscombiningmark (ch); } +/* --------------------------------------------------------------------------------------------- */ + const char * str_trunc (const char *text, int width) { return used_class.trunc (text, width); } +/* --------------------------------------------------------------------------------------------- */ + char * str_create_search_needle (const char *needle, int case_sen) { return used_class.create_search_needle (needle, case_sen); } +/* --------------------------------------------------------------------------------------------- */ void str_release_search_needle (char *needle, int case_sen) @@ -660,90 +798,120 @@ str_release_search_needle (char *needle, int case_sen) used_class.release_search_needle (needle, case_sen); } +/* --------------------------------------------------------------------------------------------- */ + const char * str_search_first (const char *text, const char *search, int case_sen) { return used_class.search_first (text, search, case_sen); } +/* --------------------------------------------------------------------------------------------- */ + const char * str_search_last (const char *text, const char *search, int case_sen) { return used_class.search_last (text, search, case_sen); } +/* --------------------------------------------------------------------------------------------- */ + int str_is_valid_string (const char *text) { return used_class.is_valid_string (text); } +/* --------------------------------------------------------------------------------------------- */ + int str_compare (const char *t1, const char *t2) { return used_class.compare (t1, t2); } +/* --------------------------------------------------------------------------------------------- */ + int str_ncompare (const char *t1, const char *t2) { return used_class.ncompare (t1, t2); } +/* --------------------------------------------------------------------------------------------- */ + int str_casecmp (const char *t1, const char *t2) { return used_class.casecmp (t1, t2); } +/* --------------------------------------------------------------------------------------------- */ + int str_ncasecmp (const char *t1, const char *t2) { return used_class.ncasecmp (t1, t2); } +/* --------------------------------------------------------------------------------------------- */ + int str_prefix (const char *text, const char *prefix) { return used_class.prefix (text, prefix); } +/* --------------------------------------------------------------------------------------------- */ + int str_caseprefix (const char *text, const char *prefix) { return used_class.caseprefix (text, prefix); } +/* --------------------------------------------------------------------------------------------- */ + void str_fix_string (char *text) { used_class.fix_string (text); } +/* --------------------------------------------------------------------------------------------- */ + char * str_create_key (const char *text, int case_sen) { return used_class.create_key (text, case_sen); } +/* --------------------------------------------------------------------------------------------- */ + char * str_create_key_for_filename (const char *text, int case_sen) { return used_class.create_key_for_filename (text, case_sen); } +/* --------------------------------------------------------------------------------------------- */ + int str_key_collate (const char *t1, const char *t2, int case_sen) { return used_class.key_collate (t1, t2, case_sen); } +/* --------------------------------------------------------------------------------------------- */ + void str_release_key (char *key, int case_sen) { used_class.release_key (key, case_sen); } +/* --------------------------------------------------------------------------------------------- */ + void str_msg_term_size (const char *text, int *lines, int *columns) { diff --git a/lib/strutil/strutil8bit.c b/lib/strutil/strutil8bit.c index d533f446d..c2a904fc9 100644 --- a/lib/strutil/strutil8bit.c +++ b/lib/strutil/strutil8bit.c @@ -31,28 +31,39 @@ #include "lib/global.h" #include "lib/strutil.h" -/* functions for singlebyte encodings, all characters have width 1 - * using standard system functions - * there are only small differences between functions in strutil8bit.c - * and strutilascii.c +/* Functions for singlebyte encodings, all characters have width 1 + * using standard system functions. + * There are only small differences between functions in strutil8bit.c + * and strutilascii.c. */ -static const char replch = '?'; +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ /* * Inlines to equalize 'char' signedness for single 'char' encodings. * Instead of writing - * isspace((unsigned char)c); + * isspace ((unsigned char) c); * you can write - * char_isspace(c); + * char_isspace (c); */ - #define DECLARE_CTYPE_WRAPPER(func_name) \ static inline int char_##func_name(char c) \ { \ return func_name((int)(unsigned char)c); \ } +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +static const char replch = '?'; + +/* --------------------------------------------------------------------------------------------- */ +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + /* *INDENT-OFF* */ DECLARE_CTYPE_WRAPPER (isalnum) DECLARE_CTYPE_WRAPPER (isdigit) @@ -63,12 +74,16 @@ DECLARE_CTYPE_WRAPPER (toupper) DECLARE_CTYPE_WRAPPER (tolower) /* *INDENT-ON* */ +/* --------------------------------------------------------------------------------------------- */ + static void str_8bit_insert_replace_char (GString * buffer) { g_string_append_c (buffer, replch); } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_is_valid_string (const char *text) { @@ -76,6 +91,8 @@ str_8bit_is_valid_string (const char *text) return 1; } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_is_valid_char (const char *ch, size_t size) { @@ -84,18 +101,24 @@ str_8bit_is_valid_char (const char *ch, size_t size) return 1; } +/* --------------------------------------------------------------------------------------------- */ + static void str_8bit_cnext_char (const char **text) { (*text)++; } +/* --------------------------------------------------------------------------------------------- */ + static void str_8bit_cprev_char (const char **text) { (*text)--; } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_cnext_noncomb_char (const char **text) { @@ -106,6 +129,8 @@ str_8bit_cnext_noncomb_char (const char **text) return 1; } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_cprev_noncomb_char (const char **text, const char *begin) { @@ -116,36 +141,48 @@ str_8bit_cprev_noncomb_char (const char **text, const char *begin) return 1; } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_isspace (const char *text) { return char_isspace (text[0]); } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_ispunct (const char *text) { return char_ispunct (text[0]); } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_isalnum (const char *text) { return char_isalnum (text[0]); } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_isdigit (const char *text) { return char_isdigit (text[0]); } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_isprint (const char *text) { return char_isprint (text[0]); } +/* --------------------------------------------------------------------------------------------- */ + static gboolean str_8bit_iscombiningmark (const char *text) { @@ -153,6 +190,8 @@ str_8bit_iscombiningmark (const char *text) return FALSE; } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_toupper (const char *text, char **out, size_t * remain) { @@ -165,6 +204,8 @@ str_8bit_toupper (const char *text, char **out, size_t * remain) return 1; } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_tolower (const char *text, char **out, size_t * remain) { @@ -177,18 +218,24 @@ str_8bit_tolower (const char *text, char **out, size_t * remain) return 1; } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_length (const char *text) { return strlen (text); } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_length2 (const char *text, int size) { return (size >= 0) ? min (strlen (text), (gsize) size) : strlen (text); } +/* --------------------------------------------------------------------------------------------- */ + static gchar * str_8bit_conv_gerror_message (GError * mcerror, const char *def_msg) { @@ -220,6 +267,8 @@ str_8bit_conv_gerror_message (GError * mcerror, const char *def_msg) return ret; } +/* --------------------------------------------------------------------------------------------- */ + static estr_t str_8bit_vfs_convert_to (GIConv coder, const char *string, int size, GString * buffer) { @@ -233,6 +282,8 @@ str_8bit_vfs_convert_to (GIConv coder, const char *string, int size, GString * b return result; } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_8bit_term_form (const char *text) { @@ -253,6 +304,8 @@ str_8bit_term_form (const char *text) return result; } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_8bit_fit_to_term (const char *text, int width, align_crt_t just_mode) { @@ -340,6 +393,8 @@ str_8bit_fit_to_term (const char *text, int width, align_crt_t just_mode) return result; } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_8bit_term_trim (const char *text, int width) { @@ -381,18 +436,24 @@ str_8bit_term_trim (const char *text, int width) return result; } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_term_width2 (const char *text, size_t length) { return (length != (size_t) (-1)) ? min (strlen (text), length) : strlen (text); } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_term_width1 (const char *text) { return str_8bit_term_width2 (text, (size_t) (-1)); } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_term_char_width (const char *text) { @@ -400,6 +461,8 @@ str_8bit_term_char_width (const char *text) return 1; } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_8bit_term_substring (const char *text, int start, int width) { @@ -428,6 +491,8 @@ str_8bit_term_substring (const char *text, int start, int width) return result; } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_8bit_trunc (const char *text, int width) { @@ -467,6 +532,8 @@ str_8bit_trunc (const char *text, int width) return result; } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_offset_to_pos (const char *text, size_t length) { @@ -474,6 +541,8 @@ str_8bit_offset_to_pos (const char *text, size_t length) return (int) length; } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_column_to_pos (const char *text, size_t pos) { @@ -481,6 +550,8 @@ str_8bit_column_to_pos (const char *text, size_t pos) return (int) pos; } +/* --------------------------------------------------------------------------------------------- */ + static char * str_8bit_create_search_needle (const char *needle, int case_sen) { @@ -488,6 +559,8 @@ str_8bit_create_search_needle (const char *needle, int case_sen) return (char *) needle; } +/* --------------------------------------------------------------------------------------------- */ + static void str_8bit_release_search_needle (char *needle, int case_sen) { @@ -495,6 +568,8 @@ str_8bit_release_search_needle (char *needle, int case_sen) (void) needle; } +/* --------------------------------------------------------------------------------------------- */ + static char * str_8bit_strdown (const char *str) { @@ -511,6 +586,8 @@ str_8bit_strdown (const char *str) return rets; } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_8bit_search_first (const char *text, const char *search, int case_sen) { @@ -539,6 +616,8 @@ str_8bit_search_first (const char *text, const char *search, int case_sen) return match; } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_8bit_search_last (const char *text, const char *search, int case_sen) { @@ -567,18 +646,24 @@ str_8bit_search_last (const char *text, const char *search, int case_sen) return match; } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_compare (const char *t1, const char *t2) { return strcmp (t1, t2); } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_ncompare (const char *t1, const char *t2) { return strncmp (t1, t2, min (strlen (t1), strlen (t2))); } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_casecmp (const char *s1, const char *s2) { @@ -612,6 +697,8 @@ str_8bit_casecmp (const char *s1, const char *s2) #endif } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_ncasecmp (const char *s1, const char *s2) { @@ -651,6 +738,8 @@ str_8bit_ncasecmp (const char *s1, const char *s2) #endif } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_prefix (const char *text, const char *prefix) { @@ -662,6 +751,8 @@ str_8bit_prefix (const char *text, const char *prefix) return result; } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_caseprefix (const char *text, const char *prefix) { @@ -673,18 +764,24 @@ str_8bit_caseprefix (const char *text, const char *prefix) return result; } +/* --------------------------------------------------------------------------------------------- */ + static void str_8bit_fix_string (char *text) { (void) text; } +/* --------------------------------------------------------------------------------------------- */ + static char * str_8bit_create_key (const char *text, int case_sen) { return (case_sen) ? (char *) text : str_8bit_strdown (text); } +/* --------------------------------------------------------------------------------------------- */ + static int str_8bit_key_collate (const char *t1, const char *t2, int case_sen) { @@ -694,6 +791,8 @@ str_8bit_key_collate (const char *t1, const char *t2, int case_sen) return strcoll (t1, t2); } +/* --------------------------------------------------------------------------------------------- */ + static void str_8bit_release_key (char *key, int case_sen) { @@ -701,6 +800,10 @@ str_8bit_release_key (char *key, int case_sen) g_free (key); } +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + struct str_class str_8bit_init (void) { @@ -756,3 +859,5 @@ str_8bit_init (void) return result; } + +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/strutil/strutilascii.c b/lib/strutil/strutilascii.c index ac8165c0a..e93f663ee 100644 --- a/lib/strutil/strutilascii.c +++ b/lib/strutil/strutilascii.c @@ -32,17 +32,31 @@ #include "lib/strutil.h" /* using g_ascii function from glib - * on terminal are showed only ascii characters (lower than 0x80) + * on terminal are showed only ascii characters (lower than 0x80) */ +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + static const char replch = '?'; +/* --------------------------------------------------------------------------------------------- */ +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + static void str_ascii_insert_replace_char (GString * buffer) { g_string_append_c (buffer, replch); } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_is_valid_string (const char *text) { @@ -50,6 +64,8 @@ str_ascii_is_valid_string (const char *text) return 1; } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_is_valid_char (const char *ch, size_t size) { @@ -58,18 +74,24 @@ str_ascii_is_valid_char (const char *ch, size_t size) return 1; } +/* --------------------------------------------------------------------------------------------- */ + static void str_ascii_cnext_char (const char **text) { (*text)++; } +/* --------------------------------------------------------------------------------------------- */ + static void str_ascii_cprev_char (const char **text) { (*text)--; } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_cnext_noncomb_char (const char **text) { @@ -80,6 +102,8 @@ str_ascii_cnext_noncomb_char (const char **text) return 1; } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_cprev_noncomb_char (const char **text, const char *begin) { @@ -90,36 +114,48 @@ str_ascii_cprev_noncomb_char (const char **text, const char *begin) return 1; } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_isspace (const char *text) { return g_ascii_isspace ((gchar) text[0]); } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_ispunct (const char *text) { return g_ascii_ispunct ((gchar) text[0]); } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_isalnum (const char *text) { return g_ascii_isalnum ((gchar) text[0]); } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_isdigit (const char *text) { return g_ascii_isdigit ((gchar) text[0]); } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_isprint (const char *text) { return g_ascii_isprint ((gchar) text[0]); } +/* --------------------------------------------------------------------------------------------- */ + static gboolean str_ascii_iscombiningmark (const char *text) { @@ -127,6 +163,8 @@ str_ascii_iscombiningmark (const char *text) return FALSE; } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_toupper (const char *text, char **out, size_t * remain) { @@ -139,6 +177,8 @@ str_ascii_toupper (const char *text, char **out, size_t * remain) return 1; } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_tolower (const char *text, char **out, size_t * remain) { @@ -151,18 +191,24 @@ str_ascii_tolower (const char *text, char **out, size_t * remain) return 1; } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_length (const char *text) { return strlen (text); } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_length2 (const char *text, int size) { return (size >= 0) ? min (strlen (text), (gsize) size) : strlen (text); } +/* --------------------------------------------------------------------------------------------- */ + static gchar * str_ascii_conv_gerror_message (GError * mcerror, const char *def_msg) { @@ -173,6 +219,8 @@ str_ascii_conv_gerror_message (GError * mcerror, const char *def_msg) return g_strdup (def_msg != NULL ? def_msg : ""); } +/* --------------------------------------------------------------------------------------------- */ + static estr_t str_ascii_vfs_convert_to (GIConv coder, const char *string, int size, GString * buffer) { @@ -181,6 +229,8 @@ str_ascii_vfs_convert_to (GIConv coder, const char *string, int size, GString * return ESTR_SUCCESS; } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_ascii_term_form (const char *text) { @@ -205,6 +255,8 @@ str_ascii_term_form (const char *text) return result; } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_ascii_fit_to_term (const char *text, int width, align_crt_t just_mode) { @@ -313,6 +365,8 @@ str_ascii_fit_to_term (const char *text, int width, align_crt_t just_mode) return result; } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_ascii_term_trim (const char *text, int width) { @@ -362,18 +416,24 @@ str_ascii_term_trim (const char *text, int width) return result; } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_term_width2 (const char *text, size_t length) { return (length != (size_t) (-1)) ? min (strlen (text), length) : strlen (text); } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_term_width1 (const char *text) { return str_ascii_term_width2 (text, (size_t) (-1)); } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_term_char_width (const char *text) { @@ -381,6 +441,8 @@ str_ascii_term_char_width (const char *text) return 1; } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_ascii_term_substring (const char *text, int start, int width) { @@ -414,6 +476,8 @@ str_ascii_term_substring (const char *text, int start, int width) return result; } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_ascii_trunc (const char *text, int width) { @@ -466,6 +530,8 @@ str_ascii_trunc (const char *text, int width) return result; } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_offset_to_pos (const char *text, size_t length) { @@ -473,6 +539,8 @@ str_ascii_offset_to_pos (const char *text, size_t length) return (int) length; } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_column_to_pos (const char *text, size_t pos) { @@ -480,6 +548,8 @@ str_ascii_column_to_pos (const char *text, size_t pos) return (int) pos; } +/* --------------------------------------------------------------------------------------------- */ + static char * str_ascii_create_search_needle (const char *needle, int case_sen) { @@ -487,6 +557,8 @@ str_ascii_create_search_needle (const char *needle, int case_sen) return (char *) needle; } +/* --------------------------------------------------------------------------------------------- */ + static void str_ascii_release_search_needle (char *needle, int case_sen) { @@ -495,6 +567,8 @@ str_ascii_release_search_needle (char *needle, int case_sen) } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_ascii_search_first (const char *text, const char *search, int case_sen) { @@ -523,6 +597,8 @@ str_ascii_search_first (const char *text, const char *search, int case_sen) return match; } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_ascii_search_last (const char *text, const char *search, int case_sen) { @@ -551,30 +627,40 @@ str_ascii_search_last (const char *text, const char *search, int case_sen) return match; } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_compare (const char *t1, const char *t2) { return strcmp (t1, t2); } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_ncompare (const char *t1, const char *t2) { return strncmp (t1, t2, min (strlen (t1), strlen (t2))); } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_casecmp (const char *t1, const char *t2) { return g_ascii_strcasecmp (t1, t2); } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_ncasecmp (const char *t1, const char *t2) { return g_ascii_strncasecmp (t1, t2, min (strlen (t1), strlen (t2))); } +/* --------------------------------------------------------------------------------------------- */ + static void str_ascii_fix_string (char *text) { @@ -582,6 +668,8 @@ str_ascii_fix_string (char *text) text[0] = ((unsigned char) text[0] < 128) ? text[0] : '?'; } +/* --------------------------------------------------------------------------------------------- */ + static char * str_ascii_create_key (const char *text, int case_sen) { @@ -589,12 +677,16 @@ str_ascii_create_key (const char *text, int case_sen) return (char *) text; } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_key_collate (const char *t1, const char *t2, int case_sen) { return (case_sen) ? strcmp (t1, t2) : g_ascii_strcasecmp (t1, t2); } +/* --------------------------------------------------------------------------------------------- */ + static void str_ascii_release_key (char *key, int case_sen) { @@ -602,6 +694,8 @@ str_ascii_release_key (char *key, int case_sen) (void) case_sen; } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_prefix (const char *text, const char *prefix) { @@ -613,6 +707,8 @@ str_ascii_prefix (const char *text, const char *prefix) return result; } +/* --------------------------------------------------------------------------------------------- */ + static int str_ascii_caseprefix (const char *text, const char *prefix) { @@ -624,6 +720,10 @@ str_ascii_caseprefix (const char *text, const char *prefix) return result; } +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + struct str_class str_ascii_init (void) { @@ -679,3 +779,5 @@ str_ascii_init (void) return result; } + +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/strutil/strutilutf8.c b/lib/strutil/strutilutf8.c index 177dca253..ac1dde6f1 100644 --- a/lib/strutil/strutilutf8.c +++ b/lib/strutil/strutilutf8.c @@ -34,8 +34,36 @@ /* using function for utf-8 from glib */ +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +struct utf8_tool +{ + char *actual; + size_t remain; + const char *cheked; + int ident; + gboolean compose; +}; + +struct term_form +{ + char text[BUF_MEDIUM * 6]; + size_t width; + gboolean compose; +}; + +/*** file scope variables ************************************************************************/ + static const char replch[] = "\xEF\xBF\xBD"; +/* --------------------------------------------------------------------------------------------- */ +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + static gboolean str_unichar_iscombiningmark (gunichar uni) { @@ -46,18 +74,24 @@ str_unichar_iscombiningmark (gunichar uni) || (type == G_UNICODE_ENCLOSING_MARK) || (type == G_UNICODE_NON_SPACING_MARK); } +/* --------------------------------------------------------------------------------------------- */ + static void str_utf8_insert_replace_char (GString * buffer) { g_string_append (buffer, replch); } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_is_valid_string (const char *text) { return g_utf8_validate (text, -1, NULL); } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_is_valid_char (const char *ch, size_t size) { @@ -72,18 +106,24 @@ str_utf8_is_valid_char (const char *ch, size_t size) } } +/* --------------------------------------------------------------------------------------------- */ + static void str_utf8_cnext_char (const char **text) { (*text) = g_utf8_next_char (*text); } +/* --------------------------------------------------------------------------------------------- */ + static void str_utf8_cprev_char (const char **text) { (*text) = g_utf8_prev_char (*text); } +/* --------------------------------------------------------------------------------------------- */ + static void str_utf8_cnext_char_safe (const char **text) { @@ -93,6 +133,8 @@ str_utf8_cnext_char_safe (const char **text) (*text)++; } +/* --------------------------------------------------------------------------------------------- */ + static void str_utf8_cprev_char_safe (const char **text) { @@ -107,6 +149,8 @@ str_utf8_cprev_char_safe (const char **text) (*text)--; } +/* --------------------------------------------------------------------------------------------- */ + static void str_utf8_fix_string (char *text) { @@ -125,6 +169,8 @@ str_utf8_fix_string (char *text) } } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_isspace (const char *text) { @@ -134,6 +180,8 @@ str_utf8_isspace (const char *text) return g_unichar_isspace (uni); } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_ispunct (const char *text) { @@ -143,6 +191,8 @@ str_utf8_ispunct (const char *text) return g_unichar_ispunct (uni); } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_isalnum (const char *text) { @@ -152,6 +202,8 @@ str_utf8_isalnum (const char *text) return g_unichar_isalnum (uni); } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_isdigit (const char *text) { @@ -161,6 +213,8 @@ str_utf8_isdigit (const char *text) return g_unichar_isdigit (uni); } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_isprint (const char *ch) { @@ -170,6 +224,8 @@ str_utf8_isprint (const char *ch) return g_unichar_isprint (uni); } +/* --------------------------------------------------------------------------------------------- */ + static gboolean str_utf8_iscombiningmark (const char *ch) { @@ -179,6 +235,8 @@ str_utf8_iscombiningmark (const char *ch) return str_unichar_iscombiningmark (uni); } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_cnext_noncomb_char (const char **text) { @@ -195,6 +253,8 @@ str_utf8_cnext_noncomb_char (const char **text) return count; } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_cprev_noncomb_char (const char **text, const char *begin) { @@ -211,6 +271,8 @@ str_utf8_cprev_noncomb_char (const char **text, const char *begin) return count; } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_toupper (const char *text, char **out, size_t * remain) { @@ -232,6 +294,8 @@ str_utf8_toupper (const char *text, char **out, size_t * remain) return 1; } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_tolower (const char *text, char **out, size_t * remain) { @@ -253,6 +317,8 @@ str_utf8_tolower (const char *text, char **out, size_t * remain) return 1; } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_length (const char *text) { @@ -278,6 +344,8 @@ str_utf8_length (const char *text) return result; } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_length2 (const char *text, int size) { @@ -306,6 +374,8 @@ str_utf8_length2 (const char *text, int size) return result; } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_length_noncomb (const char *text) { @@ -321,16 +391,22 @@ str_utf8_length_noncomb (const char *text) return result; } -/* - static void - str_utf8_questmark_sustb (char **string, size_t * left, GString * buffer) - { - char *next = g_utf8_next_char (*string); - (*left) -= next - (*string); - (*string) = next; - g_string_append_c (buffer, '?'); - } - */ +/* --------------------------------------------------------------------------------------------- */ + +#if 0 +static void +str_utf8_questmark_sustb (char **string, size_t * left, GString * buffer) +{ + char *next; + + next = g_utf8_next_char (*string); + (*left) -= next - (*string); + (*string) = next; + g_string_append_c (buffer, '?'); +} +#endif + +/* --------------------------------------------------------------------------------------------- */ static gchar * str_utf8_conv_gerror_message (GError * mcerror, const char *def_msg) @@ -341,6 +417,8 @@ str_utf8_conv_gerror_message (GError * mcerror, const char *def_msg) return g_strdup (def_msg != NULL ? def_msg : ""); } +/* --------------------------------------------------------------------------------------------- */ + static estr_t str_utf8_vfs_convert_to (GIConv coder, const char *string, int size, GString * buffer) { @@ -354,15 +432,10 @@ str_utf8_vfs_convert_to (GIConv coder, const char *string, int size, GString * b return result; } -struct term_form -{ - char text[BUF_MEDIUM * 6]; - size_t width; - gboolean compose; -}; +/* --------------------------------------------------------------------------------------------- */ +/* utility function, that makes string valid in utf8 and all characters printable + * return width of string too */ -/* utiliti function, that make string valid in utf8 and all characters printable - * return width of string too*/ static const struct term_form * str_utf8_make_make_term_form (const char *text, size_t length) { @@ -434,6 +507,8 @@ str_utf8_make_make_term_form (const char *text, size_t length) return &result; } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_utf8_term_form (const char *text) { @@ -455,16 +530,9 @@ str_utf8_term_form (const char *text) return result; } -struct utf8_tool -{ - char *actual; - size_t remain; - const char *cheked; - int ident; - gboolean compose; -}; +/* --------------------------------------------------------------------------------------------- */ +/* utility function, that copies all characters from checked to actual */ -/* utiliti function, that copy all characters from cheked to actual */ static gboolean utf8_tool_copy_chars_to_end (struct utf8_tool *tool) { @@ -489,8 +557,10 @@ utf8_tool_copy_chars_to_end (struct utf8_tool *tool) return TRUE; } -/* utiliti function, that copy characters from cheked to actual until ident is +/* --------------------------------------------------------------------------------------------- */ +/* utility function, that copies characters from checked to actual until ident is * smaller than to_ident */ + static gboolean utf8_tool_copy_chars_to (struct utf8_tool *tool, int to_ident) { @@ -527,7 +597,9 @@ utf8_tool_copy_chars_to (struct utf8_tool *tool, int to_ident) return TRUE; } -/* utiliti function, add count spaces to actual */ +/* --------------------------------------------------------------------------------------------- */ +/* utility function, adds count spaces to actual */ + static int utf8_tool_insert_space (struct utf8_tool *tool, int count) { @@ -542,7 +614,9 @@ utf8_tool_insert_space (struct utf8_tool *tool, int count) return 1; } -/* utiliti function, add one characters to actual */ +/* --------------------------------------------------------------------------------------------- */ +/* utility function, adds one characters to actual */ + static int utf8_tool_insert_char (struct utf8_tool *tool, char ch) { @@ -555,8 +629,10 @@ utf8_tool_insert_char (struct utf8_tool *tool, char ch) return 1; } -/* utiliti function, thah skip characters from cheked until ident is greater or +/* --------------------------------------------------------------------------------------------- */ +/* utility function, thah skips characters from checked until ident is greater or * equal to to_ident */ + static gboolean utf8_tool_skip_chars_to (struct utf8_tool *tool, int to_ident) { @@ -584,6 +660,8 @@ utf8_tool_skip_chars_to (struct utf8_tool *tool, int to_ident) return TRUE; } +/* --------------------------------------------------------------------------------------------- */ + static void utf8_tool_compose (char *buffer, size_t size) { @@ -594,6 +672,8 @@ utf8_tool_compose (char *buffer, size_t size) g_free (composed); } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_utf8_fit_to_term (const char *text, int width, align_crt_t just_mode) { @@ -665,6 +745,8 @@ str_utf8_fit_to_term (const char *text, int width, align_crt_t just_mode) return result; } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_utf8_term_trim (const char *text, int width) { @@ -710,6 +792,8 @@ str_utf8_term_trim (const char *text, int width) return result; } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_term_width2 (const char *text, size_t length) { @@ -719,12 +803,16 @@ str_utf8_term_width2 (const char *text, size_t length) return result->width; } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_term_width1 (const char *text) { return str_utf8_term_width2 (text, (size_t) (-1)); } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_term_char_width (const char *text) { @@ -734,6 +822,8 @@ str_utf8_term_char_width (const char *text) return (str_unichar_iscombiningmark (uni)) ? 0 : ((g_unichar_iswide (uni)) ? 2 : 1); } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_utf8_term_substring (const char *text, int start, int width) { @@ -763,6 +853,8 @@ str_utf8_term_substring (const char *text, int start, int width) return result; } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_utf8_trunc (const char *text, int width) { @@ -796,6 +888,8 @@ str_utf8_trunc (const char *text, int width) return result; } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_offset_to_pos (const char *text, size_t length) { @@ -814,6 +908,8 @@ str_utf8_offset_to_pos (const char *text, size_t length) } } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_column_to_pos (const char *text, size_t pos) { @@ -857,6 +953,8 @@ str_utf8_column_to_pos (const char *text, size_t pos) return result; } +/* --------------------------------------------------------------------------------------------- */ + static char * str_utf8_create_search_needle (const char *needle, int case_sen) { @@ -875,6 +973,8 @@ str_utf8_create_search_needle (const char *needle, int case_sen) return result; } +/* --------------------------------------------------------------------------------------------- */ + static void str_utf8_release_search_needle (char *needle, int case_sen) { @@ -882,6 +982,8 @@ str_utf8_release_search_needle (char *needle, int case_sen) g_free (needle); } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_utf8_search_first (const char *text, const char *search, int case_sen) { @@ -924,6 +1026,8 @@ str_utf8_search_first (const char *text, const char *search, int case_sen) return result; } +/* --------------------------------------------------------------------------------------------- */ + static const char * str_utf8_search_last (const char *text, const char *search, int case_sen) { @@ -965,6 +1069,8 @@ str_utf8_search_last (const char *text, const char *search, int case_sen) return result; } +/* --------------------------------------------------------------------------------------------- */ + static char * str_utf8_normalize (const char *text) { @@ -1008,6 +1114,8 @@ str_utf8_normalize (const char *text) return result; } +/* --------------------------------------------------------------------------------------------- */ + static char * str_utf8_casefold_normalize (const char *text) { @@ -1057,6 +1165,8 @@ str_utf8_casefold_normalize (const char *text) return result; } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_compare (const char *t1, const char *t2) { @@ -1074,6 +1184,8 @@ str_utf8_compare (const char *t1, const char *t2) return result; } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_ncompare (const char *t1, const char *t2) { @@ -1094,6 +1206,8 @@ str_utf8_ncompare (const char *t1, const char *t2) return result; } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_casecmp (const char *t1, const char *t2) { @@ -1111,6 +1225,8 @@ str_utf8_casecmp (const char *t1, const char *t2) return result; } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_ncasecmp (const char *t1, const char *t2) { @@ -1131,6 +1247,8 @@ str_utf8_ncasecmp (const char *t1, const char *t2) return result; } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_prefix (const char *text, const char *prefix) { @@ -1166,6 +1284,8 @@ str_utf8_prefix (const char *text, const char *prefix) return result; } +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_caseprefix (const char *text, const char *prefix) { @@ -1201,6 +1321,8 @@ str_utf8_caseprefix (const char *text, const char *prefix) return result; } +/* --------------------------------------------------------------------------------------------- */ + static char * str_utf8_create_key_gen (const char *text, int case_sen, gchar * (*keygen) (const gchar * text, gssize size)) @@ -1273,12 +1395,16 @@ str_utf8_create_key_gen (const char *text, int case_sen, return result; } +/* --------------------------------------------------------------------------------------------- */ + static char * str_utf8_create_key (const char *text, int case_sen) { return str_utf8_create_key_gen (text, case_sen, g_utf8_collate_key); } +/* --------------------------------------------------------------------------------------------- */ + #ifdef MC__USE_STR_UTF8_CREATE_KEY_FOR_FILENAME static char * str_utf8_create_key_for_filename (const char *text, int case_sen) @@ -1287,6 +1413,8 @@ str_utf8_create_key_for_filename (const char *text, int case_sen) } #endif +/* --------------------------------------------------------------------------------------------- */ + static int str_utf8_key_collate (const char *t1, const char *t2, int case_sen) { @@ -1294,6 +1422,8 @@ str_utf8_key_collate (const char *t1, const char *t2, int case_sen) return strcmp (t1, t2); } +/* --------------------------------------------------------------------------------------------- */ + static void str_utf8_release_key (char *key, int case_sen) { @@ -1301,6 +1431,10 @@ str_utf8_release_key (char *key, int case_sen) g_free (key); } +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + struct str_class str_utf8_init (void) { @@ -1362,3 +1496,5 @@ str_utf8_init (void) return result; } + +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/strutil/strverscmp.c b/lib/strutil/strverscmp.c index 5c5570717..54578c085 100644 --- a/lib/strutil/strverscmp.c +++ b/lib/strutil/strverscmp.c @@ -32,6 +32,10 @@ #include "lib/strutil.h" +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + /* states: S_N: normal, S_I: comparing integral part, S_F: comparing fractionnal parts, S_Z: idem but with leading Zeroes only */ #define S_N 0x0 @@ -43,12 +47,21 @@ #define CMP 2 #define LEN 3 +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/* --------------------------------------------------------------------------------------------- */ +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ /* Compare S1 and S2 as strings holding indices/version numbers, returning less than, equal to or greater than zero if S1 is less than, equal to or greater than S2 (for more info, see the texinfo doc). */ - int str_verscmp (const char *s1, const char *s2) { @@ -120,5 +133,6 @@ str_verscmp (const char *s1, const char *s2) return state; } #endif /* HAVE_STRVERSCMP */ - } + +/* --------------------------------------------------------------------------------------------- */ -- 2.11.4.GIT