2011-10-15 14:56:47 +04:00
|
|
|
/*
|
|
|
|
ASCII strings utilities
|
2009-04-14 14:29:01 +04:00
|
|
|
|
2018-01-01 09:54:11 +03:00
|
|
|
Copyright (C) 2007-2018
|
2014-02-12 10:33:10 +04:00
|
|
|
Free Software Foundation, Inc.
|
2011-10-15 14:56:47 +04:00
|
|
|
|
|
|
|
Written by:
|
|
|
|
Rostislav Benes, 2007
|
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-10-15 14:56:47 +04:00
|
|
|
This file is part of the Midnight Commander.
|
|
|
|
|
|
|
|
The Midnight Commander is free software: you can redistribute it
|
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation, either version 3 of the License,
|
|
|
|
or (at your option) any later version.
|
2009-04-14 14:29:01 +04:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander is distributed in the hope that it will be useful,
|
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
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2011-10-15 14:56:47 +04:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
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-04-09 13:56:43 +04:00
|
|
|
|
2009-04-24 02:47:22 +04:00
|
|
|
#include <config.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
|
|
|
|
|
|
|
#include <ctype.h>
|
2013-04-09 13:56:43 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2010-01-20 18:11:52 +03:00
|
|
|
#include "lib/global.h"
|
2010-01-21 15:17:26 +03:00
|
|
|
#include "lib/strutil.h"
|
2009-04-14 14:29:01 +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
|
|
|
/* using g_ascii function from glib
|
2015-06-20 21:40:26 +03:00
|
|
|
* on terminal are showed only ascii characters (lower than 0x80)
|
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-14 14:29:01 +04:00
|
|
|
|
2015-06-20 21:40:26 +03:00
|
|
|
/*** global variables ****************************************************************************/
|
|
|
|
|
|
|
|
/*** file scope macro definitions ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope type declarations ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
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
|
|
|
static const char replch = '?';
|
|
|
|
|
2015-06-20 21:40:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** file scope 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
|
|
|
static void
|
2009-04-14 14:29:01 +04:00
|
|
|
str_ascii_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
|
|
|
{
|
2009-04-14 14:29:01 +04:00
|
|
|
g_string_append_c (buffer, replch);
|
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
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2018-01-21 11:04:25 +03:00
|
|
|
static gboolean
|
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_ascii_is_valid_string (const char *text)
|
|
|
|
{
|
2009-04-24 02:47:22 +04:00
|
|
|
(void) text;
|
2018-01-21 11:04:25 +03:00
|
|
|
return TRUE;
|
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
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-04-14 14:29:01 +04:00
|
|
|
static int
|
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_ascii_is_valid_char (const char *ch, size_t size)
|
|
|
|
{
|
2009-04-24 02:47:22 +04:00
|
|
|
(void) ch;
|
|
|
|
(void) 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 1;
|
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static void
|
|
|
|
str_ascii_cnext_char (const char **text)
|
|
|
|
{
|
|
|
|
(*text)++;
|
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static void
|
|
|
|
str_ascii_cprev_char (const char **text)
|
|
|
|
{
|
|
|
|
(*text)--;
|
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-04-14 14:29:01 +04:00
|
|
|
static int
|
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_ascii_cnext_noncomb_char (const char **text)
|
|
|
|
{
|
2013-07-12 20:50:26 +04:00
|
|
|
if (*text[0] == '\0')
|
2010-11-08 13:21:45 +03:00
|
|
|
return 0;
|
2013-07-12 20:50:26 +04:00
|
|
|
|
|
|
|
(*text)++;
|
|
|
|
return 1;
|
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
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-04-14 14:29:01 +04:00
|
|
|
static int
|
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_ascii_cprev_noncomb_char (const char **text, const char *begin)
|
|
|
|
{
|
2013-07-12 20:50:26 +04:00
|
|
|
if ((*text) == begin)
|
2010-11-08 13:21:45 +03:00
|
|
|
return 0;
|
2013-07-12 20:50:26 +04:00
|
|
|
|
|
|
|
(*text)--;
|
|
|
|
return 1;
|
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
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2018-01-21 11:04:25 +03:00
|
|
|
static gboolean
|
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_ascii_isspace (const char *text)
|
|
|
|
{
|
|
|
|
return g_ascii_isspace ((gchar) text[0]);
|
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2018-01-21 11:04:25 +03:00
|
|
|
static gboolean
|
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_ascii_ispunct (const char *text)
|
|
|
|
{
|
2009-04-14 14:29:01 +04:00
|
|
|
return g_ascii_ispunct ((gchar) text[0]);
|
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
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2018-01-21 11:04:25 +03:00
|
|
|
static gboolean
|
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_ascii_isalnum (const char *text)
|
|
|
|
{
|
|
|
|
return g_ascii_isalnum ((gchar) text[0]);
|
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2018-01-21 11:04:25 +03:00
|
|
|
static gboolean
|
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_ascii_isdigit (const char *text)
|
|
|
|
{
|
|
|
|
return g_ascii_isdigit ((gchar) text[0]);
|
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2018-01-21 11:04:25 +03:00
|
|
|
static gboolean
|
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_ascii_isprint (const char *text)
|
|
|
|
{
|
|
|
|
return g_ascii_isprint ((gchar) text[0]);
|
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2012-11-18 13:28:57 +04:00
|
|
|
static gboolean
|
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_ascii_iscombiningmark (const char *text)
|
|
|
|
{
|
2009-04-24 02:47:22 +04:00
|
|
|
(void) text;
|
2012-11-18 13:28:57 +04:00
|
|
|
return FALSE;
|
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
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static int
|
2009-04-14 14:29:01 +04:00
|
|
|
str_ascii_toupper (const char *text, 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
|
|
|
{
|
2009-04-14 14:29:01 +04:00
|
|
|
if (*remain <= 1)
|
2018-01-21 11:04:25 +03:00
|
|
|
return FALSE;
|
2013-07-12 20:50:26 +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
|
|
|
(*out)[0] = (char) g_ascii_toupper ((gchar) text[0]);
|
|
|
|
(*out)++;
|
|
|
|
(*remain)--;
|
2018-01-21 11:04:25 +03:00
|
|
|
return TRUE;
|
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
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2018-01-21 11:04:25 +03:00
|
|
|
static gboolean
|
2009-04-14 14:29:01 +04:00
|
|
|
str_ascii_tolower (const char *text, 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
|
|
|
{
|
2009-04-14 14:29:01 +04:00
|
|
|
if (*remain <= 1)
|
2018-01-21 11:04:25 +03:00
|
|
|
return FALSE;
|
2013-07-12 20:50:26 +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
|
|
|
(*out)[0] = (char) g_ascii_tolower ((gchar) text[0]);
|
|
|
|
(*out)++;
|
|
|
|
(*remain)--;
|
2018-01-21 11:04:25 +03:00
|
|
|
return TRUE;
|
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
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static int
|
|
|
|
str_ascii_length (const char *text)
|
|
|
|
{
|
|
|
|
return strlen (text);
|
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static int
|
|
|
|
str_ascii_length2 (const char *text, int size)
|
|
|
|
{
|
2016-04-07 10:52:04 +03:00
|
|
|
return (size >= 0) ? MIN (strlen (text), (gsize) size) : strlen (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
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-04-29 20:08:33 +04:00
|
|
|
static gchar *
|
2014-07-15 16:53:06 +04:00
|
|
|
str_ascii_conv_gerror_message (GError * mcerror, const char *def_msg)
|
2009-04-29 20:08:33 +04:00
|
|
|
{
|
|
|
|
/* the same as str_utf8_conv_gerror_message() */
|
2014-07-15 16:53:06 +04:00
|
|
|
if (mcerror != NULL)
|
|
|
|
return g_strdup (mcerror->message);
|
2009-04-29 20:08:33 +04:00
|
|
|
|
|
|
|
return g_strdup (def_msg != NULL ? def_msg : "");
|
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-04-22 20:35:32 +04:00
|
|
|
static estr_t
|
2010-11-08 13:21:45 +03:00
|
|
|
str_ascii_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
|
|
|
{
|
2009-04-24 02:47:22 +04:00
|
|
|
(void) coder;
|
2009-04-14 14:29:01 +04:00
|
|
|
g_string_append_len (buffer, string, size);
|
2009-04-22 20:35:32 +04:00
|
|
|
return ESTR_SUCCESS;
|
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
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static const char *
|
|
|
|
str_ascii_term_form (const char *text)
|
|
|
|
{
|
|
|
|
static char result[BUF_MEDIUM];
|
|
|
|
char *actual;
|
|
|
|
size_t remain;
|
|
|
|
size_t length;
|
|
|
|
size_t pos = 0;
|
2009-04-14 14:29:01 +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
|
|
|
actual = result;
|
|
|
|
remain = sizeof (result);
|
|
|
|
length = strlen (text);
|
2009-04-14 14:29:01 +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
|
|
|
/* go throw all characters and check, if they are ascii and printable */
|
2009-04-14 14:29:01 +04:00
|
|
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
|
|
|
{
|
2010-11-08 13:21:45 +03:00
|
|
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
|
|
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
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-14 14:29:01 +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
|
|
|
actual[0] = '\0';
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static const char *
|
2009-04-24 20:01:06 +04:00
|
|
|
str_ascii_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
|
|
|
{
|
|
|
|
static char result[BUF_MEDIUM];
|
|
|
|
char *actual;
|
|
|
|
size_t remain;
|
2013-07-12 20:50:26 +04:00
|
|
|
int ident = 0;
|
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
|
|
|
size_t length;
|
|
|
|
size_t pos = 0;
|
2009-04-14 14:29:01 +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
|
|
|
length = strlen (text);
|
|
|
|
actual = result;
|
2009-04-14 14:29:01 +04:00
|
|
|
remain = sizeof (result);
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
if ((int) length <= width)
|
2009-04-14 14:29:01 +04:00
|
|
|
{
|
2010-11-08 13:21:45 +03:00
|
|
|
switch (HIDE_FIT (just_mode))
|
|
|
|
{
|
|
|
|
case J_CENTER_LEFT:
|
|
|
|
case J_CENTER:
|
|
|
|
ident = (width - length) / 2;
|
|
|
|
break;
|
|
|
|
case J_RIGHT:
|
|
|
|
ident = width - length;
|
|
|
|
break;
|
2015-04-19 13:57:38 +03:00
|
|
|
default:
|
|
|
|
break;
|
2010-11-08 13:21:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* add space before text */
|
|
|
|
if ((int) remain <= ident)
|
|
|
|
goto finally;
|
|
|
|
memset (actual, ' ', ident);
|
|
|
|
actual += ident;
|
|
|
|
remain -= ident;
|
|
|
|
|
|
|
|
/* copy all characters */
|
|
|
|
for (; pos < (gsize) length && remain > 1; pos++, actual++, remain--)
|
|
|
|
{
|
|
|
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
|
|
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add space after text */
|
|
|
|
if (width - length - ident > 0)
|
|
|
|
{
|
|
|
|
if (remain <= width - length - ident)
|
|
|
|
goto finally;
|
|
|
|
memset (actual, ' ', width - length - ident);
|
|
|
|
actual += width - length - ident;
|
|
|
|
}
|
2009-04-14 14:29:01 +04:00
|
|
|
}
|
2013-07-12 20:50:26 +04:00
|
|
|
else if (IS_FIT (just_mode))
|
2009-04-14 14:29:01 +04:00
|
|
|
{
|
2013-07-12 20:50:26 +04:00
|
|
|
/* copy prefix of text, that is not wider than width / 2 */
|
|
|
|
for (; pos + 1 <= (gsize) width / 2 && remain > 1; actual++, pos++, remain--)
|
2010-11-08 13:21:45 +03:00
|
|
|
{
|
2013-07-12 20:50:26 +04:00
|
|
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
|
|
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
|
|
|
}
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2013-07-12 20:50:26 +04:00
|
|
|
if (remain <= 1)
|
|
|
|
goto finally;
|
|
|
|
actual[0] = '~';
|
|
|
|
actual++;
|
|
|
|
remain--;
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2013-07-12 20:50:26 +04:00
|
|
|
pos += length - width + 1;
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2013-07-12 20:50:26 +04:00
|
|
|
/* copy suffix of text */
|
|
|
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
|
|
|
{
|
|
|
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
|
|
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
2010-11-08 13:21:45 +03:00
|
|
|
}
|
2013-07-12 20:50:26 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (HIDE_FIT (just_mode))
|
2010-11-08 13:21:45 +03:00
|
|
|
{
|
2013-07-12 20:50:26 +04:00
|
|
|
case J_CENTER:
|
|
|
|
ident = (length - width) / 2;
|
|
|
|
break;
|
|
|
|
case J_RIGHT:
|
|
|
|
ident = length - width;
|
|
|
|
break;
|
2015-04-19 13:57:38 +03:00
|
|
|
default:
|
|
|
|
break;
|
2013-07-12 20:50:26 +04:00
|
|
|
}
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2013-07-12 20:50:26 +04:00
|
|
|
/* copy substring text, substring start from ident and take width
|
|
|
|
* characters from text */
|
|
|
|
pos += ident;
|
|
|
|
for (; pos < (gsize) (ident + width) && remain > 1; pos++, actual++, remain--)
|
|
|
|
{
|
|
|
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
|
|
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
2010-11-08 13:21:45 +03:00
|
|
|
}
|
2013-07-12 20:50:26 +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
|
|
|
}
|
2013-07-12 20:50:26 +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
|
|
|
finally:
|
2014-04-20 18:24:58 +04:00
|
|
|
if (actual >= result + sizeof (result))
|
|
|
|
actual = result + sizeof (result) - 1;
|
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
|
|
|
actual[0] = '\0';
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static const char *
|
2009-04-14 14:29:01 +04:00
|
|
|
str_ascii_term_trim (const char *text, int width)
|
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
|
|
|
{
|
|
|
|
static char result[BUF_MEDIUM];
|
|
|
|
size_t remain;
|
|
|
|
char *actual;
|
|
|
|
size_t length;
|
2009-04-14 14:29:01 +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
|
|
|
length = strlen (text);
|
|
|
|
actual = result;
|
|
|
|
remain = sizeof (result);
|
2009-04-14 14:29:01 +04:00
|
|
|
|
2011-07-21 14:06:26 +04:00
|
|
|
if (width > 0)
|
2009-04-14 14:29:01 +04:00
|
|
|
{
|
2013-10-15 10:34:04 +04:00
|
|
|
size_t pos;
|
|
|
|
|
2013-07-12 20:50:26 +04:00
|
|
|
if (width >= (int) length)
|
2010-11-08 13:21:45 +03:00
|
|
|
{
|
2013-07-12 20:50:26 +04:00
|
|
|
/* copy all characters */
|
2013-10-15 10:34:04 +04:00
|
|
|
for (pos = 0; pos < length && remain > 1; pos++, actual++, remain--)
|
2011-07-21 14:06:26 +04:00
|
|
|
{
|
2013-07-12 20:50:26 +04:00
|
|
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
|
|
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
2011-07-21 14:06:26 +04:00
|
|
|
}
|
2010-11-08 13:21:45 +03:00
|
|
|
}
|
2013-07-12 20:50:26 +04:00
|
|
|
else if (width <= 3)
|
|
|
|
{
|
|
|
|
memset (actual, '.', width);
|
|
|
|
actual += width;
|
|
|
|
}
|
2010-11-08 13:21:45 +03:00
|
|
|
else
|
|
|
|
{
|
2013-07-12 20:50:26 +04:00
|
|
|
memset (actual, '.', 3);
|
|
|
|
actual += 3;
|
|
|
|
remain -= 3;
|
|
|
|
|
|
|
|
/* copy suffix of text */
|
2013-10-15 10:34:04 +04:00
|
|
|
for (pos = length - width + 3; pos < length && remain > 1; pos++, actual++, remain--)
|
2010-11-08 13:21:45 +03:00
|
|
|
{
|
|
|
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
|
|
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
|
|
|
}
|
|
|
|
}
|
2009-04-14 14:29:01 +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
|
|
|
actual[0] = '\0';
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static int
|
|
|
|
str_ascii_term_width2 (const char *text, size_t length)
|
|
|
|
{
|
2016-04-07 10:52:04 +03:00
|
|
|
return (length != (size_t) (-1)) ? MIN (strlen (text), length) : strlen (text);
|
2009-04-14 14:29:01 +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
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static int
|
|
|
|
str_ascii_term_width1 (const char *text)
|
|
|
|
{
|
2009-04-14 14:29:01 +04:00
|
|
|
return str_ascii_term_width2 (text, (size_t) (-1));
|
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static int
|
|
|
|
str_ascii_term_char_width (const char *text)
|
|
|
|
{
|
2009-04-24 02:47:22 +04:00
|
|
|
(void) 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 1;
|
2009-04-14 14:29:01 +04:00
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static const char *
|
|
|
|
str_ascii_term_substring (const char *text, int start, int width)
|
|
|
|
{
|
|
|
|
static char result[BUF_MEDIUM];
|
|
|
|
size_t remain;
|
|
|
|
char *actual;
|
|
|
|
size_t length;
|
2009-04-14 14:29:01 +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
|
|
|
actual = result;
|
|
|
|
remain = sizeof (result);
|
|
|
|
length = strlen (text);
|
2009-04-14 14:29:01 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
if (start < (int) length)
|
2009-04-14 14:29:01 +04:00
|
|
|
{
|
2013-10-15 10:34:04 +04:00
|
|
|
size_t pos;
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* copy at most width characters from text from start */
|
2013-10-15 10:34:04 +04:00
|
|
|
for (pos = start; pos < length && width > 0 && remain > 1;
|
|
|
|
pos++, width--, actual++, remain--)
|
2010-11-08 13:21:45 +03:00
|
|
|
{
|
|
|
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
|
|
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
|
|
|
}
|
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-14 14:29:01 +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
|
|
|
/* if text is shorter then width, add space to the end */
|
2009-04-14 14:29:01 +04:00
|
|
|
for (; width > 0 && remain > 1; actual++, remain--, width--)
|
2010-11-08 13:21:45 +03:00
|
|
|
actual[0] = ' ';
|
2009-04-14 14:29:01 +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
|
|
|
actual[0] = '\0';
|
|
|
|
return result;
|
2009-04-14 14:29:01 +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
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static const char *
|
|
|
|
str_ascii_trunc (const char *text, int width)
|
|
|
|
{
|
|
|
|
static char result[MC_MAXPATHLEN];
|
|
|
|
int remain;
|
|
|
|
char *actual;
|
|
|
|
size_t pos = 0;
|
|
|
|
size_t length;
|
2009-04-14 14:29:01 +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
|
|
|
actual = result;
|
|
|
|
remain = sizeof (result);
|
|
|
|
length = strlen (text);
|
2009-04-14 14:29:01 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
if ((int) length > width)
|
2009-04-14 14:29:01 +04:00
|
|
|
{
|
2010-11-08 13:21:45 +03:00
|
|
|
/* copy prefix of text */
|
|
|
|
for (; pos + 1 <= (gsize) width / 2 && remain > 1; actual++, pos++, remain--)
|
|
|
|
{
|
|
|
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
|
|
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (remain <= 1)
|
|
|
|
goto finally;
|
|
|
|
actual[0] = '~';
|
|
|
|
actual++;
|
|
|
|
remain--;
|
|
|
|
|
|
|
|
pos += length - width + 1;
|
|
|
|
|
|
|
|
/* copy suffix of text */
|
|
|
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
|
|
|
{
|
|
|
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
|
|
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
|
|
|
}
|
2009-04-14 14:29:01 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-08 13:21:45 +03:00
|
|
|
/* copy all characters */
|
|
|
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
|
|
|
{
|
|
|
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
|
|
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
finally:
|
|
|
|
actual[0] = '\0';
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static int
|
|
|
|
str_ascii_offset_to_pos (const char *text, size_t length)
|
|
|
|
{
|
2009-04-24 02:47:22 +04:00
|
|
|
(void) text;
|
2009-04-14 14:29:01 +04:00
|
|
|
return (int) 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
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static int
|
|
|
|
str_ascii_column_to_pos (const char *text, size_t pos)
|
|
|
|
{
|
2009-04-24 02:47:22 +04:00
|
|
|
(void) text;
|
2010-11-08 13:21:45 +03:00
|
|
|
return (int) pos;
|
2009-04-14 14:29:01 +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
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static char *
|
2018-01-20 10:55:37 +03:00
|
|
|
str_ascii_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
|
|
|
{
|
2009-04-24 02:47:22 +04:00
|
|
|
(void) case_sen;
|
2009-04-14 14:29:01 +04:00
|
|
|
return (char *) needle;
|
|
|
|
}
|
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
|
|
|
|
2015-06-20 21:40:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-04-14 14:29:01 +04:00
|
|
|
static void
|
2018-01-20 10:55:37 +03:00
|
|
|
str_ascii_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
|
|
|
{
|
2009-04-24 02:47:22 +04:00
|
|
|
(void) case_sen;
|
|
|
|
(void) needle;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static const char *
|
2018-01-20 10:55:37 +03:00
|
|
|
str_ascii_search_first (const char *text, const char *search, 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
|
|
|
{
|
|
|
|
char *fold_text;
|
|
|
|
char *fold_search;
|
|
|
|
const char *match;
|
2009-04-14 14:29:01 +04:00
|
|
|
|
2018-01-20 10:55:37 +03:00
|
|
|
fold_text = case_sen ? (char *) text : g_ascii_strdown (text, -1);
|
|
|
|
fold_search = case_sen ? (char *) search : g_ascii_strdown (search, -1);
|
2009-04-14 14:29:01 +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
|
|
|
match = g_strstr_len (fold_text, -1, fold_search);
|
2009-04-14 14:29:01 +04:00
|
|
|
if (match != NULL)
|
|
|
|
{
|
2013-10-15 10:34:04 +04:00
|
|
|
size_t offset;
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
offset = match - fold_text;
|
|
|
|
match = text + offset;
|
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-14 14:29:01 +04:00
|
|
|
|
|
|
|
if (!case_sen)
|
|
|
|
{
|
2010-11-08 13:21:45 +03:00
|
|
|
g_free (fold_text);
|
|
|
|
g_free (fold_search);
|
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-14 14:29:01 +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 match;
|
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static const char *
|
2018-01-20 10:55:37 +03:00
|
|
|
str_ascii_search_last (const char *text, const char *search, 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
|
|
|
{
|
|
|
|
char *fold_text;
|
|
|
|
char *fold_search;
|
|
|
|
const char *match;
|
2009-04-14 14:29:01 +04:00
|
|
|
|
2018-01-20 10:55:37 +03:00
|
|
|
fold_text = case_sen ? (char *) text : g_ascii_strdown (text, -1);
|
|
|
|
fold_search = case_sen ? (char *) search : g_ascii_strdown (search, -1);
|
2009-04-14 14:29:01 +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
|
|
|
match = g_strrstr_len (fold_text, -1, fold_search);
|
2009-04-14 14:29:01 +04:00
|
|
|
if (match != NULL)
|
|
|
|
{
|
2013-10-15 10:34:04 +04:00
|
|
|
size_t offset;
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
offset = match - fold_text;
|
|
|
|
match = text + offset;
|
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-14 14:29:01 +04:00
|
|
|
|
|
|
|
if (!case_sen)
|
|
|
|
{
|
2010-11-08 13:21:45 +03:00
|
|
|
g_free (fold_text);
|
|
|
|
g_free (fold_search);
|
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-14 14:29:01 +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 match;
|
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static int
|
|
|
|
str_ascii_compare (const char *t1, const char *t2)
|
|
|
|
{
|
|
|
|
return strcmp (t1, t2);
|
2009-04-14 14:29:01 +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
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static int
|
|
|
|
str_ascii_ncompare (const char *t1, const char *t2)
|
|
|
|
{
|
2016-04-07 10:52:04 +03:00
|
|
|
return strncmp (t1, t2, MIN (strlen (t1), strlen (t2)));
|
2009-04-14 14:29:01 +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
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static int
|
|
|
|
str_ascii_casecmp (const char *t1, const char *t2)
|
|
|
|
{
|
|
|
|
return g_ascii_strcasecmp (t1, t2);
|
2009-04-14 14:29:01 +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
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static int
|
|
|
|
str_ascii_ncasecmp (const char *t1, const char *t2)
|
|
|
|
{
|
2016-04-07 10:52:04 +03:00
|
|
|
return g_ascii_strncasecmp (t1, t2, MIN (strlen (t1), strlen (t2)));
|
2009-04-14 14:29:01 +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
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static void
|
|
|
|
str_ascii_fix_string (char *text)
|
|
|
|
{
|
2009-04-14 14:29:01 +04:00
|
|
|
for (; text[0] != '\0'; text++)
|
2010-11-08 13:21:45 +03:00
|
|
|
text[0] = ((unsigned char) text[0] < 128) ? text[0] : '?';
|
2009-04-14 14:29:01 +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
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static char *
|
2018-01-20 10:55:37 +03:00
|
|
|
str_ascii_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
|
|
|
{
|
2009-04-24 02:47:22 +04:00
|
|
|
(void) case_sen;
|
2009-04-14 14:29:01 +04:00
|
|
|
return (char *) text;
|
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static int
|
2018-01-20 10:55:37 +03:00
|
|
|
str_ascii_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
|
|
|
{
|
2018-01-20 10:55:37 +03:00
|
|
|
return case_sen ? strcmp (t1, t2) : g_ascii_strcasecmp (t1, t2);
|
2009-04-14 14:29:01 +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
|
|
|
|
2015-06-20 21:40:26 +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
|
|
|
static void
|
2018-01-20 10:55:37 +03:00
|
|
|
str_ascii_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
|
|
|
{
|
2009-04-24 02:47:22 +04:00
|
|
|
(void) key;
|
|
|
|
(void) case_sen;
|
2009-04-14 14:29:01 +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
|
|
|
|
2015-06-20 21:40:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-04-14 14:29:01 +04:00
|
|
|
static int
|
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_ascii_prefix (const char *text, const char *prefix)
|
|
|
|
{
|
|
|
|
int result;
|
2013-07-12 20:50:26 +04:00
|
|
|
|
2009-04-14 14:29:01 +04:00
|
|
|
for (result = 0; text[result] != '\0' && prefix[result] != '\0'
|
2010-11-08 13:21:45 +03:00
|
|
|
&& text[result] == prefix[result]; result++);
|
2013-07-12 20:50:26 +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 result;
|
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-04-14 14:29:01 +04:00
|
|
|
static int
|
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_ascii_caseprefix (const char *text, const char *prefix)
|
|
|
|
{
|
|
|
|
int result;
|
2013-07-12 20:50:26 +04:00
|
|
|
|
2009-04-14 14:29:01 +04:00
|
|
|
for (result = 0; text[result] != '\0' && prefix[result] != '\0'
|
2010-11-08 13:21:45 +03:00
|
|
|
&& g_ascii_toupper (text[result]) == g_ascii_toupper (prefix[result]); result++);
|
2013-07-12 20:50:26 +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 result;
|
|
|
|
}
|
|
|
|
|
2015-06-20 21:40:26 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** 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
|
|
|
struct str_class
|
2009-10-30 04:12:04 +03:00
|
|
|
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
|
|
|
{
|
|
|
|
struct str_class result;
|
2009-04-14 14:29:01 +04:00
|
|
|
|
2009-04-29 20:08:33 +04:00
|
|
|
result.conv_gerror_message = str_ascii_conv_gerror_message;
|
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
|
|
|
result.vfs_convert_to = str_ascii_vfs_convert_to;
|
|
|
|
result.insert_replace_char = str_ascii_insert_replace_char;
|
|
|
|
result.is_valid_string = str_ascii_is_valid_string;
|
2009-04-14 14:29:01 +04:00
|
|
|
result.is_valid_char = str_ascii_is_valid_char;
|
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
|
|
|
result.cnext_char = str_ascii_cnext_char;
|
|
|
|
result.cprev_char = str_ascii_cprev_char;
|
|
|
|
result.cnext_char_safe = str_ascii_cnext_char;
|
|
|
|
result.cprev_char_safe = str_ascii_cprev_char;
|
|
|
|
result.cnext_noncomb_char = str_ascii_cnext_noncomb_char;
|
|
|
|
result.cprev_noncomb_char = str_ascii_cprev_noncomb_char;
|
2012-12-12 10:47:47 +04:00
|
|
|
result.char_isspace = str_ascii_isspace;
|
|
|
|
result.char_ispunct = str_ascii_ispunct;
|
|
|
|
result.char_isalnum = str_ascii_isalnum;
|
|
|
|
result.char_isdigit = str_ascii_isdigit;
|
|
|
|
result.char_isprint = str_ascii_isprint;
|
|
|
|
result.char_iscombiningmark = str_ascii_iscombiningmark;
|
|
|
|
result.char_toupper = str_ascii_toupper;
|
|
|
|
result.char_tolower = str_ascii_tolower;
|
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
|
|
|
result.length = str_ascii_length;
|
|
|
|
result.length2 = str_ascii_length2;
|
|
|
|
result.length_noncomb = str_ascii_length;
|
|
|
|
result.fix_string = str_ascii_fix_string;
|
|
|
|
result.term_form = str_ascii_term_form;
|
|
|
|
result.fit_to_term = str_ascii_fit_to_term;
|
|
|
|
result.term_trim = str_ascii_term_trim;
|
|
|
|
result.term_width2 = str_ascii_term_width2;
|
|
|
|
result.term_width1 = str_ascii_term_width1;
|
|
|
|
result.term_char_width = str_ascii_term_char_width;
|
|
|
|
result.term_substring = str_ascii_term_substring;
|
|
|
|
result.trunc = str_ascii_trunc;
|
|
|
|
result.offset_to_pos = str_ascii_offset_to_pos;
|
|
|
|
result.column_to_pos = str_ascii_column_to_pos;
|
|
|
|
result.create_search_needle = str_ascii_create_search_needle;
|
|
|
|
result.release_search_needle = str_ascii_release_search_needle;
|
|
|
|
result.search_first = str_ascii_search_first;
|
|
|
|
result.search_last = str_ascii_search_last;
|
|
|
|
result.compare = str_ascii_compare;
|
|
|
|
result.ncompare = str_ascii_ncompare;
|
|
|
|
result.casecmp = str_ascii_casecmp;
|
|
|
|
result.ncasecmp = str_ascii_ncasecmp;
|
|
|
|
result.prefix = str_ascii_prefix;
|
|
|
|
result.caseprefix = str_ascii_caseprefix;
|
|
|
|
result.create_key = str_ascii_create_key;
|
|
|
|
result.create_key_for_filename = str_ascii_create_key;
|
|
|
|
result.key_collate = str_ascii_key_collate;
|
|
|
|
result.release_key = str_ascii_release_key;
|
2009-04-14 14:29:01 +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 result;
|
|
|
|
}
|
2015-06-20 21:40:26 +03:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|