patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
#ifndef MC_STRUTIL_H
|
|
|
|
#define MC_STRUTIL_H
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
#include "lib/global.h" /* include glib.h */
|
2009-04-19 17:45:10 +04:00
|
|
|
|
2010-11-10 22:28:42 +03:00
|
|
|
#include <sys/types.h>
|
2013-02-28 16:55:51 +04:00
|
|
|
#include <inttypes.h>
|
2010-11-10 22:28:42 +03:00
|
|
|
#include <string.h>
|
|
|
|
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
/* Header file for strutil.c, strutilascii.c, strutil8bit.c, strutilutf8.c.
|
|
|
|
* There are two sort of functions:
|
|
|
|
* 1. functions for working with growing strings and conversion strings between
|
|
|
|
* different encodings.
|
|
|
|
* (implemented directly in strutil.c)
|
|
|
|
* 2. functions, that hide differences between encodings derived from ASCII.
|
|
|
|
* (implemented separately in strutilascii.c, strutil8bit.c, strutilutf8.c)
|
|
|
|
* documentation is made for UTF-8 version of functions.
|
|
|
|
*/
|
2010-11-08 13:21:45 +03:00
|
|
|
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
/* invalid strings
|
|
|
|
* function, that works with invalid strings are marked with "I"
|
|
|
|
* in documentation
|
|
|
|
* invalid bytes of string are handled as one byte characters with width 1, they
|
2024-10-05 19:55:01 +03:00
|
|
|
* are displayed as question marks, I-marked comparing functions try to keep
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
* the original value of these bytes.
|
|
|
|
*/
|
2010-11-08 13:21:45 +03:00
|
|
|
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
/* combining characters
|
2024-10-05 19:55:01 +03:00
|
|
|
* displaying: all handled as zero with characters, expect combing character
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
* at the begin of string, this character has with one (space add before),
|
|
|
|
* so str_term_width is not good for computing width of singles characters
|
Fix various typos in the source code (closes MidnightCommander/mc#177).
Found via `codespell -S
po,doc,./misc/syntax,./src/vfs/extfs/helpers/README.it -L
parm,rouge,sav,ect,vie,te,dum,clen,wee,dynamc,childs,ths,fo,nin,unx,nd,iif,iterm,ser,makrs,wil`
Co-authored-by: Yury V. Zaytsev <yury@shurup.com>
Signed-off-by: Kian-Meng Ang <kianmeng@cpan.org>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2023-01-10 06:02:52 +03:00
|
|
|
* (never return zero, expect empty string)
|
2024-10-05 19:55:01 +03:00
|
|
|
* for compatibility are strings composed before displaying
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
* comparing: comparing decompose all string before comparing, n-compare
|
|
|
|
* functions do not work as is usual, because same strings do not have to be
|
|
|
|
* same length in UTF-8. So they return 0 if one string is prefix of the other
|
|
|
|
* one.
|
|
|
|
* str_prefix is used to determine, how many characters from one string are
|
|
|
|
* prefix in second string. However, str_prefix return number of characters in
|
|
|
|
* decompose form. (used in do_search (screen.c))
|
|
|
|
*/
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** typedefs(not structures) and defined constants **********************************************/
|
|
|
|
|
|
|
|
#define IS_FIT(x) ((x) & 0x0010)
|
|
|
|
#define MAKE_FIT(x) ((x) | 0x0010)
|
|
|
|
#define HIDE_FIT(x) ((x) & 0x000f)
|
|
|
|
|
|
|
|
#define INVALID_CONV ((GIConv) (-1))
|
|
|
|
|
|
|
|
/*** enums ***************************************************************************************/
|
|
|
|
|
2009-04-22 20:35:32 +04:00
|
|
|
/* results of conversion function
|
|
|
|
*/
|
2010-11-08 13:21:45 +03:00
|
|
|
typedef enum
|
|
|
|
{
|
2024-09-06 10:55:26 +03:00
|
|
|
/* Success means, that the conversion has been finished successfully
|
2010-11-08 13:21:45 +03:00
|
|
|
*/
|
2009-04-22 20:35:32 +04:00
|
|
|
ESTR_SUCCESS = 0,
|
2024-09-06 10:55:26 +03:00
|
|
|
/* Problem means, that not every character was successfully converted (some are
|
|
|
|
* replaced with question marks). So it is impossible to convert string back.
|
2010-11-08 13:21:45 +03:00
|
|
|
*/
|
2009-04-22 20:35:32 +04:00
|
|
|
ESTR_PROBLEM = 1,
|
2024-09-06 10:55:26 +03:00
|
|
|
/* Failure means, that the conversion is not possible (example: wrong encoding
|
|
|
|
* of the input string)
|
2010-11-08 13:21:45 +03:00
|
|
|
*/
|
2009-04-22 20:35:32 +04:00
|
|
|
ESTR_FAILURE = 2
|
|
|
|
} estr_t;
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
2009-04-24 20:01:06 +04:00
|
|
|
/* alignment strings on terminal
|
|
|
|
*/
|
2010-11-08 13:21:45 +03:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
J_LEFT = 0x01,
|
|
|
|
J_RIGHT = 0x02,
|
|
|
|
J_CENTER = 0x03,
|
2009-04-24 20:01:06 +04:00
|
|
|
/* if there is enough space for string on terminal,
|
2024-09-06 10:55:26 +03:00
|
|
|
* string is centered otherwise is aligned to the left */
|
2010-11-08 13:21:45 +03:00
|
|
|
J_CENTER_LEFT = 0x04,
|
2024-09-06 10:55:26 +03:00
|
|
|
/* fit alignment: if string is too long, truncate with '~' */
|
2010-11-08 13:21:45 +03:00
|
|
|
J_LEFT_FIT = 0x11,
|
|
|
|
J_RIGHT_FIT = 0x12,
|
|
|
|
J_CENTER_FIT = 0x13,
|
|
|
|
J_CENTER_LEFT_FIT = 0x14
|
2009-04-24 20:01:06 +04:00
|
|
|
} align_crt_t;
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
2013-02-28 16:55:51 +04:00
|
|
|
/* string-to-integer parsing results
|
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
LONGINT_OK = 0,
|
|
|
|
|
|
|
|
/* These two values can be ORed together, to indicate that both errors occurred. */
|
|
|
|
LONGINT_OVERFLOW = 1,
|
|
|
|
LONGINT_INVALID_SUFFIX_CHAR = 2,
|
|
|
|
|
|
|
|
LONGINT_INVALID_SUFFIX_CHAR_WITH_OVERFLOW = (LONGINT_INVALID_SUFFIX_CHAR | LONGINT_OVERFLOW),
|
|
|
|
LONGINT_INVALID = 4
|
|
|
|
} strtol_error_t;
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
2009-04-24 02:47:22 +04:00
|
|
|
/* all functions in str_class must be defined for every encoding */
|
2010-11-08 13:21:45 +03:00
|
|
|
struct str_class
|
|
|
|
{
|
2018-01-21 11:04:25 +03:00
|
|
|
/* *INDENT-OFF* */
|
2010-11-08 13:21:45 +03:00
|
|
|
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);
|
2021-05-16 13:56:44 +03:00
|
|
|
gboolean (*is_valid_string) (const char *text);
|
|
|
|
/*I*/ int (*is_valid_char) (const char *ch, size_t size);
|
|
|
|
/*I*/ void (*cnext_char) (const char **text);
|
|
|
|
void (*cprev_char) (const char **text);
|
|
|
|
void (*cnext_char_safe) (const char **text);
|
|
|
|
/*I*/ void (*cprev_char_safe) (const char **text);
|
2010-11-08 13:21:45 +03:00
|
|
|
/*I*/ int (*cnext_noncomb_char) (const char **text);
|
|
|
|
/*I*/ int (*cprev_noncomb_char) (const char **text, const char *begin);
|
2021-05-16 13:56:44 +03:00
|
|
|
/*I*/ gboolean (*char_isspace) (const char *ch);
|
|
|
|
/*I*/ gboolean (*char_ispunct) (const char *ch);
|
|
|
|
/*I*/ gboolean (*char_isalnum) (const char *ch);
|
|
|
|
/*I*/ gboolean (*char_isdigit) (const char *ch);
|
|
|
|
/*I*/ gboolean (*char_isprint) (const char *ch);
|
|
|
|
/*I*/ gboolean (*char_iscombiningmark) (const char *ch);
|
|
|
|
/*I*/ int (*length) (const char *text);
|
|
|
|
/*I*/ int (*length2) (const char *text, int size);
|
|
|
|
/*I*/ int (*length_noncomb) (const char *text);
|
|
|
|
/*I*/ gboolean (*char_toupper) (const char *ch, char **out, size_t * remain);
|
|
|
|
gboolean (*char_tolower) (const char *ch, char **out, size_t * remain);
|
|
|
|
void (*fix_string) (char *text);
|
|
|
|
/*I*/ const char *(*term_form) (const char *text);
|
|
|
|
/*I*/ const char *(*fit_to_term) (const char *text, int width, align_crt_t just_mode);
|
2010-11-08 13:21:45 +03:00
|
|
|
/*I*/ const char *(*term_trim) (const char *text, int width);
|
2021-05-16 13:56:44 +03:00
|
|
|
/*I*/ const char *(*term_substring) (const char *text, int start, int width);
|
|
|
|
/*I*/ int (*term_width1) (const char *text);
|
|
|
|
/*I*/ int (*term_width2) (const char *text, size_t length);
|
|
|
|
/*I*/ int (*term_char_width) (const char *length);
|
|
|
|
/*I*/ const char *(*trunc) (const char *length, int width);
|
|
|
|
/*I*/ int (*offset_to_pos) (const char *text, size_t length);
|
|
|
|
/*I*/ int (*column_to_pos) (const char *text, size_t pos);
|
|
|
|
/*I*/ char *(*create_search_needle) (const char *needle, gboolean case_sen);
|
|
|
|
void (*release_search_needle) (char *needle, gboolean case_sen);
|
|
|
|
const char *(*search_first) (const char *text, const char *needle, gboolean case_sen);
|
|
|
|
const char *(*search_last) (const char *text, const char *needle, gboolean case_sen);
|
|
|
|
int (*compare) (const char *t1, const char *t2);
|
|
|
|
/*I*/ int (*ncompare) (const char *t1, const char *t2);
|
|
|
|
/*I*/ int (*casecmp) (const char *t1, const char *t2);
|
|
|
|
/*I*/ int (*ncasecmp) (const char *t1, const char *t2);
|
|
|
|
/*I*/ int (*prefix) (const char *text, const char *prefix);
|
|
|
|
/*I*/ int (*caseprefix) (const char *text, const char *prefix);
|
2018-01-20 10:55:37 +03:00
|
|
|
/*I*/ char *(*create_key) (const char *text, gboolean case_sen);
|
|
|
|
/*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);
|
2018-01-21 11:04:25 +03:00
|
|
|
/* *INDENT-ON* */
|
|
|
|
};
|
2010-11-08 13:21:45 +03:00
|
|
|
|
|
|
|
/*** global variables defined in .c file *********************************************************/
|
|
|
|
|
Fix various typos in the source code (closes MidnightCommander/mc#177).
Found via `codespell -S
po,doc,./misc/syntax,./src/vfs/extfs/helpers/README.it -L
parm,rouge,sav,ect,vie,te,dum,clen,wee,dynamc,childs,ths,fo,nin,unx,nd,iif,iterm,ser,makrs,wil`
Co-authored-by: Yury V. Zaytsev <yury@shurup.com>
Signed-off-by: Kian-Meng Ang <kianmeng@cpan.org>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2023-01-10 06:02:52 +03:00
|
|
|
/* standard converters */
|
2010-11-08 13:21:45 +03:00
|
|
|
extern GIConv str_cnv_to_term;
|
|
|
|
extern GIConv str_cnv_from_term;
|
|
|
|
/* from terminal encoding to terminal encoding */
|
|
|
|
extern GIConv str_cnv_not_convert;
|
|
|
|
|
|
|
|
/*** declarations of public functions ************************************************************/
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
2009-10-30 04:12:04 +03:00
|
|
|
struct str_class str_utf8_init (void);
|
|
|
|
struct str_class str_8bit_init (void);
|
|
|
|
struct str_class str_ascii_init (void);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
Fix various typos in the source code (closes MidnightCommander/mc#177).
Found via `codespell -S
po,doc,./misc/syntax,./src/vfs/extfs/helpers/README.it -L
parm,rouge,sav,ect,vie,te,dum,clen,wee,dynamc,childs,ths,fo,nin,unx,nd,iif,iterm,ser,makrs,wil`
Co-authored-by: Yury V. Zaytsev <yury@shurup.com>
Signed-off-by: Kian-Meng Ang <kianmeng@cpan.org>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2023-01-10 06:02:52 +03:00
|
|
|
/* create converter from "from_enc" to terminal encoding
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
* if "from_enc" is not supported return INVALID_CONV
|
|
|
|
*/
|
2021-05-16 13:56:44 +03:00
|
|
|
GIConv str_crt_conv_from (const char *from_enc);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
Fix various typos in the source code (closes MidnightCommander/mc#177).
Found via `codespell -S
po,doc,./misc/syntax,./src/vfs/extfs/helpers/README.it -L
parm,rouge,sav,ect,vie,te,dum,clen,wee,dynamc,childs,ths,fo,nin,unx,nd,iif,iterm,ser,makrs,wil`
Co-authored-by: Yury V. Zaytsev <yury@shurup.com>
Signed-off-by: Kian-Meng Ang <kianmeng@cpan.org>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2023-01-10 06:02:52 +03:00
|
|
|
/* create converter from terminal encoding to "to_enc"
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
* if "to_enc" is not supported return INVALID_CONV
|
|
|
|
*/
|
2021-05-16 13:56:44 +03:00
|
|
|
GIConv str_crt_conv_to (const char *to_enc);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
Fix various typos in the source code (closes MidnightCommander/mc#177).
Found via `codespell -S
po,doc,./misc/syntax,./src/vfs/extfs/helpers/README.it -L
parm,rouge,sav,ect,vie,te,dum,clen,wee,dynamc,childs,ths,fo,nin,unx,nd,iif,iterm,ser,makrs,wil`
Co-authored-by: Yury V. Zaytsev <yury@shurup.com>
Signed-off-by: Kian-Meng Ang <kianmeng@cpan.org>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2023-01-10 06:02:52 +03:00
|
|
|
/* close converter, do not close str_cnv_to_term, str_cnv_from_term,
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
* str_cnv_not_convert
|
|
|
|
*/
|
2021-05-16 13:56:44 +03:00
|
|
|
void str_close_conv (GIConv conv);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* return on of not used buffers (.used == 0) or create new
|
|
|
|
* returned buffer has set .used to 1
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* convert string using coder, result of conversion is appended at end of buffer
|
2009-04-26 09:01:34 +04:00
|
|
|
* return ESTR_SUCCESS if there was no problem.
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
* otherwise return ESTR_PROBLEM or ESTR_FAILURE
|
2010-11-08 13:21:45 +03:00
|
|
|
*/
|
2021-05-16 13:56:44 +03:00
|
|
|
estr_t str_convert (GIConv coder, const char *string, GString * buffer);
|
|
|
|
estr_t str_nconvert (GIConv coder, const char *string, int size, GString * buffer);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
2009-04-29 20:08:33 +04:00
|
|
|
/* convert GError message (which in UTF-8) to terminal charset
|
|
|
|
* def_char is used if result of error->str conversion if ESTR_FAILURE
|
|
|
|
* return new allocated null-terminated string, which is need to be freed
|
|
|
|
* I
|
|
|
|
*/
|
2010-11-08 13:21:45 +03:00
|
|
|
gchar *str_conv_gerror_message (GError * error, const char *def_msg);
|
2009-04-29 20:08:33 +04:00
|
|
|
|
2009-04-26 09:01:34 +04:00
|
|
|
/* return only ESTR_SUCCESS or ESTR_FAILURE, because vfs must be able to convert
|
|
|
|
* result to original string. (so no replace with questionmark)
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
* if coder is str_cnv_from_term or str_cnv_not_convert, string is only copied,
|
|
|
|
* so is possible to show file, that is not valid in terminal encoding
|
2009-04-19 17:45:10 +04:00
|
|
|
*/
|
2021-05-16 13:56:44 +03:00
|
|
|
estr_t str_vfs_convert_from (GIConv coder, const char *string, GString * buffer);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* if coder is str_cnv_to_term or str_cnv_not_convert, string is only copied,
|
2024-10-05 19:55:01 +03:00
|
|
|
* does replace with question mark
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
* I
|
|
|
|
*/
|
2021-05-16 13:56:44 +03:00
|
|
|
estr_t str_vfs_convert_to (GIConv coder, const char *string, int size, GString * buffer);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
2013-06-13 03:29:07 +04:00
|
|
|
/* printf function for str_buffer, append result of printf at the end of buffer
|
2009-04-14 14:29:01 +04:00
|
|
|
*/
|
2015-08-25 15:28:01 +03:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
void str_printf (GString * buffer, const char *format, ...) G_GNUC_PRINTF (2, 3);
|
|
|
|
/* *INDENT-ON* */
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* add standard replacement character in terminal encoding
|
|
|
|
*/
|
2021-05-16 13:56:44 +03:00
|
|
|
void str_insert_replace_char (GString * buffer);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* init strings and set terminal encoding,
|
|
|
|
* if is termenc NULL, detect terminal encoding
|
|
|
|
* create all str_cnv_* and set functions for terminal encoding
|
|
|
|
*/
|
|
|
|
void str_init_strings (const char *termenc);
|
|
|
|
|
|
|
|
/* free all str_buffer and all str_cnv_*
|
|
|
|
*/
|
2009-10-30 04:12:04 +03:00
|
|
|
void str_uninit_strings (void);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* try convert characters in ch to output using conv
|
|
|
|
* ch_size is size of ch, can by (size_t)(-1) (-1 only for ASCII
|
|
|
|
* compatible encoding, for other must be set)
|
2009-04-22 20:35:32 +04:00
|
|
|
* return ESTR_SUCCESS if conversion was successfully,
|
|
|
|
* ESTR_PROBLEM if ch contains only part of characters,
|
|
|
|
* ESTR_FAILURE if conversion is not possible
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
*/
|
2010-11-08 13:21:45 +03:00
|
|
|
estr_t str_translate_char (GIConv conv, const char *ch, size_t ch_size,
|
|
|
|
char *output, size_t out_size);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* test, if text is valid in terminal encoding
|
|
|
|
* I
|
|
|
|
*/
|
2018-01-21 11:04:25 +03:00
|
|
|
gboolean str_is_valid_string (const char *text);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* test, if first char of ch is valid
|
|
|
|
* size, how many bytes characters occupied, could be (size_t)(-1)
|
|
|
|
* return 1 if it is valid, -1 if it is invalid or -2 if it is only part of
|
|
|
|
* multibyte character
|
|
|
|
* I
|
|
|
|
*/
|
2010-11-08 13:21:45 +03:00
|
|
|
int str_is_valid_char (const char *ch, size_t size);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* return next characters after text, do not call on the end of string
|
|
|
|
*/
|
|
|
|
char *str_get_next_char (char *text);
|
|
|
|
const char *str_cget_next_char (const char *text);
|
|
|
|
|
|
|
|
/* return previous characters before text, do not call on the start of strings
|
|
|
|
*/
|
|
|
|
char *str_get_prev_char (char *text);
|
|
|
|
const char *str_cget_prev_char (const char *text);
|
|
|
|
|
|
|
|
/* set text to next characters, do not call on the end of string
|
|
|
|
*/
|
|
|
|
void str_next_char (char **text);
|
|
|
|
void str_cnext_char (const char **text);
|
|
|
|
|
|
|
|
/* set text to previous characters, do not call on the start of strings
|
|
|
|
*/
|
|
|
|
void str_prev_char (char **text);
|
|
|
|
void str_cprev_char (const char **text);
|
|
|
|
|
|
|
|
/* return next characters after text, do not call on the end of string
|
|
|
|
* works with invalid string
|
|
|
|
* I
|
|
|
|
*/
|
|
|
|
char *str_get_next_char_safe (char *text);
|
|
|
|
const char *str_cget_next_char_safe (const char *text);
|
|
|
|
|
|
|
|
/* return previous characters before text, do not call on the start of strings
|
|
|
|
* works with invalid string
|
|
|
|
* I
|
|
|
|
*/
|
|
|
|
char *str_get_prev_char_safe (char *text);
|
|
|
|
const char *str_cget_prev_char_safe (const char *text);
|
|
|
|
|
|
|
|
/* set text to next characters, do not call on the end of string
|
|
|
|
* works with invalid string
|
|
|
|
* I
|
|
|
|
*/
|
|
|
|
void str_next_char_safe (char **text);
|
|
|
|
void str_cnext_char_safe (const char **text);
|
|
|
|
|
|
|
|
/* set text to previous characters, do not call on the start of strings
|
|
|
|
* works with invalid string
|
|
|
|
* I
|
|
|
|
*/
|
|
|
|
void str_prev_char_safe (char **text);
|
|
|
|
void str_cprev_char_safe (const char **text);
|
|
|
|
|
|
|
|
/* set text to next noncombining characters, check the end of text
|
|
|
|
* return how many characters was skipped
|
|
|
|
* works with invalid string
|
|
|
|
* I
|
|
|
|
*/
|
|
|
|
int str_next_noncomb_char (char **text);
|
|
|
|
int str_cnext_noncomb_char (const char **text);
|
|
|
|
|
|
|
|
/* set text to previous noncombining characters, search stop at begin
|
|
|
|
* return how many characters was skipped
|
|
|
|
* works with invalid string
|
|
|
|
* I
|
|
|
|
*/
|
|
|
|
int str_prev_noncomb_char (char **text, const char *begin);
|
|
|
|
int str_cprev_noncomb_char (const char **text, const char *begin);
|
|
|
|
|
|
|
|
/* if first characters in ch is space, tabulator or new lines
|
|
|
|
* I
|
|
|
|
*/
|
2018-01-21 11:04:25 +03:00
|
|
|
gboolean str_isspace (const char *ch);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* if first characters in ch is punctuation or symbol
|
|
|
|
* I
|
|
|
|
*/
|
2018-01-21 11:04:25 +03:00
|
|
|
gboolean str_ispunct (const char *ch);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* if first characters in ch is alphanum
|
|
|
|
* I
|
|
|
|
*/
|
2018-01-21 11:04:25 +03:00
|
|
|
gboolean str_isalnum (const char *ch);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* if first characters in ch is digit
|
|
|
|
* I
|
|
|
|
*/
|
2018-01-21 11:04:25 +03:00
|
|
|
gboolean str_isdigit (const char *ch);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* if first characters in ch is printable
|
|
|
|
* I
|
|
|
|
*/
|
2018-01-21 11:04:25 +03:00
|
|
|
gboolean str_isprint (const char *ch);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* if first characters in ch is a combining mark (only in utf-8)
|
|
|
|
* combining makrs are assumed to be zero width
|
|
|
|
* I
|
|
|
|
*/
|
2012-11-18 13:28:57 +04:00
|
|
|
gboolean str_iscombiningmark (const char *ch);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
Fix various typos in the source code (closes MidnightCommander/mc#177).
Found via `codespell -S
po,doc,./misc/syntax,./src/vfs/extfs/helpers/README.it -L
parm,rouge,sav,ect,vie,te,dum,clen,wee,dynamc,childs,ths,fo,nin,unx,nd,iif,iterm,ser,makrs,wil`
Co-authored-by: Yury V. Zaytsev <yury@shurup.com>
Signed-off-by: Kian-Meng Ang <kianmeng@cpan.org>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2023-01-10 06:02:52 +03:00
|
|
|
/* write lower from of first characters in ch into out
|
2024-10-05 19:55:01 +03:00
|
|
|
* decrease remain by size of returned characters
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
* if out is not big enough, do nothing
|
|
|
|
*/
|
2024-06-01 21:12:14 +03:00
|
|
|
gboolean str_toupper (const char *ch, char **out, size_t *remain);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
Fix various typos in the source code (closes MidnightCommander/mc#177).
Found via `codespell -S
po,doc,./misc/syntax,./src/vfs/extfs/helpers/README.it -L
parm,rouge,sav,ect,vie,te,dum,clen,wee,dynamc,childs,ths,fo,nin,unx,nd,iif,iterm,ser,makrs,wil`
Co-authored-by: Yury V. Zaytsev <yury@shurup.com>
Signed-off-by: Kian-Meng Ang <kianmeng@cpan.org>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2023-01-10 06:02:52 +03:00
|
|
|
/* write upper from of first characters in ch into out
|
2024-10-05 19:55:01 +03:00
|
|
|
* decrease remain by size of returned characters
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
* if out is not big enough, do nothing
|
|
|
|
*/
|
2024-06-01 21:12:14 +03:00
|
|
|
gboolean str_tolower (const char *ch, char **out, size_t *remain);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* return length of text in characters
|
|
|
|
* I
|
|
|
|
*/
|
2010-11-08 13:21:45 +03:00
|
|
|
int str_length (const char *text);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* return length of text in characters, limit to size
|
|
|
|
* I
|
|
|
|
*/
|
2010-11-08 13:21:45 +03:00
|
|
|
int str_length2 (const char *text, int size);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
2009-04-17 12:46:06 +04:00
|
|
|
/* return length of one char
|
|
|
|
* I
|
|
|
|
*/
|
2021-05-16 13:56:44 +03:00
|
|
|
int str_length_char (const char *text);
|
2009-04-17 12:46:06 +04:00
|
|
|
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
/* return length of text in characters, count only noncombining characters
|
|
|
|
* I
|
|
|
|
*/
|
2010-11-08 13:21:45 +03:00
|
|
|
int str_length_noncomb (const char *text);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* replace all invalid characters in text with questionmark
|
|
|
|
* after return, text is valid string in terminal encoding
|
|
|
|
* I
|
|
|
|
*/
|
2010-11-08 13:21:45 +03:00
|
|
|
void str_fix_string (char *text);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* replace all invalid characters in text with questionmark
|
|
|
|
* replace all unprintable characters with '.'
|
|
|
|
* return static allocated string, "text" is not changed
|
|
|
|
* returned string do not need to be freed
|
|
|
|
* I
|
|
|
|
*/
|
2010-11-08 13:21:45 +03:00
|
|
|
const char *str_term_form (const char *text);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* like str_term_form, but text can be alignment to width
|
|
|
|
* alignment is specified in just_mode (J_LEFT, J_LEFT_FIT, ...)
|
|
|
|
* result is completed with spaces to width
|
|
|
|
* I
|
|
|
|
*/
|
2009-04-24 20:01:06 +04:00
|
|
|
const char *str_fit_to_term (const char *text, int width, align_crt_t just_mode);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* like str_term_form, but when text is wider than width, three dots are
|
|
|
|
* inserted at begin and result is completed with suffix of text
|
|
|
|
* no additional spaces are inserted
|
|
|
|
* I
|
|
|
|
*/
|
|
|
|
const char *str_term_trim (const char *text, int width);
|
|
|
|
|
|
|
|
|
|
|
|
/* like str_term_form, but return only specified substring
|
|
|
|
* start - column (position) on terminal, where substring begin
|
|
|
|
* result is completed with spaces to width
|
|
|
|
* I
|
2010-11-08 13:21:45 +03:00
|
|
|
*/
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
const char *str_term_substring (const char *text, int start, int width);
|
|
|
|
|
|
|
|
/* return width, that will be text occupied on terminal
|
|
|
|
* I
|
|
|
|
*/
|
|
|
|
int str_term_width1 (const char *text);
|
|
|
|
|
|
|
|
/* return width, that will be text occupied on terminal
|
|
|
|
* text is limited by length in characters
|
|
|
|
* I
|
|
|
|
*/
|
|
|
|
int str_term_width2 (const char *text, size_t length);
|
|
|
|
|
|
|
|
/* return width, that will be character occupied on terminal
|
|
|
|
* combining characters are always zero width
|
|
|
|
* I
|
|
|
|
*/
|
|
|
|
int str_term_char_width (const char *text);
|
|
|
|
|
|
|
|
/* convert position in characters to position in bytes
|
|
|
|
* I
|
|
|
|
*/
|
2010-11-08 13:21:45 +03:00
|
|
|
int str_offset_to_pos (const char *text, size_t length);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* convert position on terminal to position in characters
|
|
|
|
* I
|
|
|
|
*/
|
|
|
|
int str_column_to_pos (const char *text, size_t pos);
|
|
|
|
|
|
|
|
/* like str_fit_to_term width just_mode = J_LEFT_FIT,
|
|
|
|
* but do not insert additional spaces
|
|
|
|
* I
|
|
|
|
*/
|
|
|
|
const char *str_trunc (const char *text, int width);
|
|
|
|
|
|
|
|
/* create needle, that will be searched in str_search_fist/last,
|
|
|
|
* so needle can be reused
|
|
|
|
* in UTF-8 return normalized form of needle
|
|
|
|
*/
|
2018-01-20 10:55:37 +03:00
|
|
|
char *str_create_search_needle (const char *needle, gboolean case_sen);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* free needle returned by str_create_search_needle
|
|
|
|
*/
|
2018-01-20 10:55:37 +03:00
|
|
|
void str_release_search_needle (char *needle, gboolean case_sen);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* search for first occurrence of search in text
|
|
|
|
*/
|
2018-01-20 10:55:37 +03:00
|
|
|
const char *str_search_first (const char *text, const char *needle, gboolean case_sen);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* search for last occurrence of search in text
|
|
|
|
*/
|
2018-01-20 10:55:37 +03:00
|
|
|
const char *str_search_last (const char *text, const char *needle, gboolean case_sen);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* case sensitive compare two strings
|
|
|
|
* I
|
|
|
|
*/
|
|
|
|
int str_compare (const char *t1, const char *t2);
|
|
|
|
|
|
|
|
/* case sensitive compare two strings
|
|
|
|
* if one string is prefix of the other string, return 0
|
|
|
|
* I
|
|
|
|
*/
|
|
|
|
int str_ncompare (const char *t1, const char *t2);
|
|
|
|
|
|
|
|
/* case insensitive compare two strings
|
|
|
|
* I
|
|
|
|
*/
|
|
|
|
int str_casecmp (const char *t1, const char *t2);
|
|
|
|
|
|
|
|
/* case insensitive compare two strings
|
|
|
|
* if one string is prefix of the other string, return 0
|
|
|
|
* I
|
|
|
|
*/
|
|
|
|
int str_ncasecmp (const char *t1, const char *t2);
|
|
|
|
|
|
|
|
/* return, how many bytes are are same from start in text and prefix
|
2013-07-23 02:16:20 +04:00
|
|
|
* both strings are decomposed before comparing and return value is counted
|
|
|
|
* in decomposed form, too. calling with prefix, prefix, you get size in bytes
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
* of prefix in decomposed form,
|
|
|
|
* I
|
|
|
|
*/
|
|
|
|
int str_prefix (const char *text, const char *prefix);
|
|
|
|
|
|
|
|
/* case insensitive version of str_prefix
|
|
|
|
* I
|
|
|
|
*/
|
|
|
|
int str_caseprefix (const char *text, const char *prefix);
|
|
|
|
|
|
|
|
/* create a key that is used by str_key_collate
|
|
|
|
* I
|
|
|
|
*/
|
2018-01-20 10:55:37 +03:00
|
|
|
char *str_create_key (const char *text, gboolean case_sen);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* create a key that is used by str_key_collate
|
|
|
|
* should aware dot '.' in text
|
|
|
|
* I
|
|
|
|
*/
|
2018-01-20 10:55:37 +03:00
|
|
|
char *str_create_key_for_filename (const char *text, gboolean case_sen);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
/* compare two string using LC_COLLATE, if is possible
|
|
|
|
* if case_sen is set, comparing is case sensitive,
|
|
|
|
* case_sen must be same for str_create_key, str_key_collate and str_release_key
|
|
|
|
* I
|
|
|
|
*/
|
2018-01-20 10:55:37 +03:00
|
|
|
int str_key_collate (const char *t1, const char *t2, gboolean case_sen);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
Fix various typos in the source code (closes MidnightCommander/mc#177).
Found via `codespell -S
po,doc,./misc/syntax,./src/vfs/extfs/helpers/README.it -L
parm,rouge,sav,ect,vie,te,dum,clen,wee,dynamc,childs,ths,fo,nin,unx,nd,iif,iterm,ser,makrs,wil`
Co-authored-by: Yury V. Zaytsev <yury@shurup.com>
Signed-off-by: Kian-Meng Ang <kianmeng@cpan.org>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2023-01-10 06:02:52 +03:00
|
|
|
/* release_key created by str_create_key, only right way to release key
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
* I
|
|
|
|
*/
|
2018-01-20 10:55:37 +03:00
|
|
|
void str_release_key (char *key, gboolean case_sen);
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
2011-04-06 13:01:27 +04:00
|
|
|
/* return TRUE if codeset_name is utf8 or utf-8
|
2009-04-09 18:23:08 +04:00
|
|
|
* I
|
|
|
|
*/
|
2011-04-06 13:01:27 +04:00
|
|
|
gboolean str_isutf8 (const char *codeset_name);
|
2009-04-19 17:45:10 +04:00
|
|
|
|
2009-05-07 13:20:34 +04:00
|
|
|
const char *str_detect_termencoding (void);
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
int str_verscmp (const char *s1, const char *s2);
|
|
|
|
|
2022-02-20 17:06:32 +03:00
|
|
|
/* Like filevercmp, except compare the byte arrays a (of length alen) and b (of length blen)
|
|
|
|
so that a and b can contain '\0', which sorts just before '\1'. But if alen is -1 treat
|
|
|
|
a as a string terminated by '\0', and similarly for blen.
|
2019-02-20 15:39:13 +03:00
|
|
|
*/
|
2022-02-20 17:06:32 +03:00
|
|
|
int filenvercmp (char const *a, ssize_t alen, char const *b, ssize_t blen);
|
2019-02-20 15:39:13 +03:00
|
|
|
|
|
|
|
|
2010-11-13 21:55:13 +03:00
|
|
|
/* return how many lines and columns will text occupy on terminal
|
|
|
|
*/
|
|
|
|
void str_msg_term_size (const char *text, int *lines, int *columns);
|
|
|
|
|
2011-04-26 11:25:10 +04:00
|
|
|
/**
|
2012-08-31 18:05:29 +04:00
|
|
|
* skip first needle's in haystack
|
|
|
|
*
|
|
|
|
* @param haystack pointer to string
|
|
|
|
* @param needle pointer to string
|
|
|
|
* @param skip_count skip first bytes
|
|
|
|
*
|
2012-11-05 17:57:50 +04:00
|
|
|
* @return pointer to skip_count+1 needle (or NULL if not found).
|
2011-04-26 11:25:10 +04:00
|
|
|
*/
|
2012-08-31 18:05:29 +04:00
|
|
|
|
2011-04-26 11:25:10 +04:00
|
|
|
char *strrstr_skip_count (const char *haystack, const char *needle, size_t skip_count);
|
|
|
|
|
2013-01-10 23:44:14 +04:00
|
|
|
char *str_replace_all (const char *haystack, const char *needle, const char *replacement);
|
|
|
|
|
2024-03-31 18:53:59 +03:00
|
|
|
GPtrArray *str_tokenize (const char *string);
|
|
|
|
|
2024-07-21 17:21:59 +03:00
|
|
|
strtol_error_t xstrtoumax (const char *nptr, char **endptr, int base, uintmax_t * val,
|
2013-02-28 16:55:51 +04:00
|
|
|
const char *valid_suffixes);
|
|
|
|
uintmax_t parse_integer (const char *str, gboolean * invalid);
|
|
|
|
|
2024-03-09 14:41:08 +03:00
|
|
|
char *str_escape (const char *src, gsize src_len, const char *escaped_chars,
|
|
|
|
gboolean escape_non_printable);
|
|
|
|
char *str_unescape (const char *src, gsize src_len, const char *unescaped_chars,
|
|
|
|
gboolean unescape_non_printable);
|
|
|
|
char *str_shell_unescape (const char *text);
|
|
|
|
char *str_shell_escape (const char *text);
|
|
|
|
|
|
|
|
char *str_glob_escape (const char *text);
|
|
|
|
char *str_glob_unescape (const char *text);
|
|
|
|
|
|
|
|
char *str_regex_escape (const char *text);
|
|
|
|
char *str_regex_unescape (const char *text);
|
|
|
|
|
|
|
|
gboolean str_is_char_escaped (const char *start, const char *current);
|
|
|
|
|
2013-02-28 16:55:51 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** inline functions ****************************************************************************/
|
2013-02-28 16:55:51 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2010-11-10 22:28:42 +03:00
|
|
|
static inline void
|
|
|
|
str_replace (char *s, char from, char to)
|
|
|
|
{
|
|
|
|
for (; *s != '\0'; s++)
|
|
|
|
{
|
|
|
|
if (*s == from)
|
|
|
|
*s = to;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-28 16:55:51 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2010-11-10 22:28:42 +03:00
|
|
|
/*
|
|
|
|
* strcpy is unsafe on overlapping memory areas, so define memmove-alike
|
|
|
|
* string function.
|
|
|
|
* Have sense only when:
|
|
|
|
* * dest <= src
|
|
|
|
* AND
|
|
|
|
* * dest and str are pointers to one object (as Roland Illig pointed).
|
|
|
|
*
|
|
|
|
* We can't use str*cpy funs here:
|
|
|
|
* http://kerneltrap.org/mailarchive/openbsd-misc/2008/5/27/1951294
|
2012-08-31 18:05:29 +04:00
|
|
|
*
|
|
|
|
* @param dest pointer to string
|
|
|
|
* @param src pointer to string
|
|
|
|
*
|
2012-11-05 17:57:50 +04:00
|
|
|
* @return newly allocated string
|
2012-08-31 18:05:29 +04:00
|
|
|
*
|
2010-11-10 22:28:42 +03:00
|
|
|
*/
|
2012-08-31 18:05:29 +04:00
|
|
|
|
2010-11-10 22:28:42 +03:00
|
|
|
static inline char *
|
|
|
|
str_move (char *dest, const char *src)
|
|
|
|
{
|
|
|
|
size_t n;
|
|
|
|
|
2016-11-03 10:46:11 +03:00
|
|
|
g_assert (dest <= src);
|
2010-11-10 22:28:42 +03:00
|
|
|
|
|
|
|
n = strlen (src) + 1; /* + '\0' */
|
|
|
|
|
|
|
|
return (char *) memmove (dest, src, n);
|
|
|
|
}
|
|
|
|
|
2024-06-12 07:30:23 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/* Compare version strings:
|
|
|
|
|
|
|
|
Compare strings a and b as file names containing version numbers, and return an integer
|
|
|
|
that is negative, zero, or positive depending on whether a compares less than, equal to,
|
|
|
|
or greater than b.
|
|
|
|
|
|
|
|
Use the following version sort algorithm:
|
|
|
|
|
|
|
|
1. Compare the strings' maximal-length non-digit prefixes lexically.
|
|
|
|
If there is a difference return that difference.
|
|
|
|
Otherwise discard the prefixes and continue with the next step.
|
|
|
|
|
|
|
|
2. Compare the strings' maximal-length digit prefixes, using numeric comparison
|
|
|
|
of the numbers represented by each prefix. (Treat an empty prefix as zero; this can
|
|
|
|
happen only at string end.)
|
|
|
|
If there is a difference, return that difference.
|
|
|
|
Otherwise discard the prefixes and continue with the next step.
|
|
|
|
|
|
|
|
3. If both strings are empty, return 0. Otherwise continue with step 1.
|
|
|
|
|
|
|
|
In version sort, lexical comparison is left to right, byte by byte, using the byte's numeric
|
|
|
|
value (0-255), except that:
|
|
|
|
|
|
|
|
1. ASCII letters sort before other bytes.
|
|
|
|
2. A tilde sorts before anything, even an empty string.
|
|
|
|
|
|
|
|
In addition to the version sort rules, the following strings have special priority and sort
|
|
|
|
before all other strings (listed in order):
|
|
|
|
|
|
|
|
1. The empty string.
|
|
|
|
2. ".".
|
|
|
|
3. "..".
|
|
|
|
4. Strings starting with "." sort before other strings.
|
|
|
|
|
|
|
|
Before comparing two strings where both begin with non-".", or where both begin with "."
|
|
|
|
but neither is "." or "..", suffixes matching the C-locale extended regular expression
|
|
|
|
(\.[A-Za-z~][A-Za-z0-9~]*)*$ are removed and the strings compared without them, using version sort
|
|
|
|
without special priority; if they do not compare equal, this comparison result is used and
|
|
|
|
the suffixes are effectively ignored. Otherwise, the entire strings are compared using version sort.
|
|
|
|
When removing a suffix from a nonempty string, remove the maximal-length suffix such that
|
|
|
|
the remaining string is nonempty.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
filevercmp (const char *s1, const char *s2)
|
|
|
|
{
|
|
|
|
return filenvercmp (s1, -1, s2, -1);
|
|
|
|
}
|
|
|
|
|
2013-02-28 16:55:51 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
#endif /* MC_STRUTIL_H */
|