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
|
|
|
/* 8bit strings utilities
|
|
|
|
Copyright (C) 2007 Free Software Foundation, Inc.
|
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
|
|
|
Written 2007 by:
|
|
|
|
Rostislav Benes
|
|
|
|
|
|
|
|
The file_date routine is mostly from GNU's fileutils package,
|
|
|
|
written by Richard Stallman and David MacKenzie.
|
|
|
|
|
|
|
|
This program 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 2 of the License, or
|
|
|
|
(at your option) any later version.
|
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
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
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
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "global.h"
|
|
|
|
#include "strutil.h"
|
|
|
|
|
|
|
|
/* functions for singlebyte encodings, all characters have width 1
|
|
|
|
* using standard system functions
|
|
|
|
* there are only small differences between functions in strutil8bit.c
|
|
|
|
* and strutilascii.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const char replch = '?';
|
|
|
|
|
2009-05-21 01:49:01 +04:00
|
|
|
/*
|
|
|
|
* Inlines to equalize 'char' signedness for single 'char' encodings.
|
|
|
|
* Instead of writing
|
|
|
|
* isspace((unsigned char)c);
|
|
|
|
* you can write
|
|
|
|
* char_isspace(c);
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DECLARE_CTYPE_WRAPPER(func_name) \
|
|
|
|
static inline int char_##func_name(char c) \
|
|
|
|
{ \
|
|
|
|
return func_name((int)(unsigned char)c); \
|
|
|
|
}
|
|
|
|
|
|
|
|
DECLARE_CTYPE_WRAPPER(isalnum)
|
|
|
|
DECLARE_CTYPE_WRAPPER(isalpha)
|
|
|
|
DECLARE_CTYPE_WRAPPER(isascii)
|
|
|
|
DECLARE_CTYPE_WRAPPER(isblank)
|
|
|
|
DECLARE_CTYPE_WRAPPER(iscntrl)
|
|
|
|
DECLARE_CTYPE_WRAPPER(isdigit)
|
|
|
|
DECLARE_CTYPE_WRAPPER(isgraph)
|
|
|
|
DECLARE_CTYPE_WRAPPER(islower)
|
|
|
|
DECLARE_CTYPE_WRAPPER(isprint)
|
|
|
|
DECLARE_CTYPE_WRAPPER(ispunct)
|
|
|
|
DECLARE_CTYPE_WRAPPER(isspace)
|
|
|
|
DECLARE_CTYPE_WRAPPER(isupper)
|
|
|
|
DECLARE_CTYPE_WRAPPER(isxdigit)
|
|
|
|
DECLARE_CTYPE_WRAPPER(toupper)
|
|
|
|
DECLARE_CTYPE_WRAPPER(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
|
|
|
static void
|
2009-04-14 14:29:01 +04:00
|
|
|
str_8bit_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
|
|
|
}
|
|
|
|
|
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_8bit_is_valid_string (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
|
|
|
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_8bit_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
str_8bit_cnext_char (const char **text)
|
|
|
|
{
|
|
|
|
(*text)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
str_8bit_cprev_char (const char **text)
|
|
|
|
{
|
|
|
|
(*text)--;
|
|
|
|
}
|
|
|
|
|
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_8bit_cnext_noncomb_char (const char **text)
|
|
|
|
{
|
2009-04-14 14:29:01 +04:00
|
|
|
if (*text[0] != '\0')
|
|
|
|
{
|
|
|
|
(*text)++;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 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
|
|
|
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_8bit_cprev_noncomb_char (const char **text, const char *begin)
|
|
|
|
{
|
2009-04-14 14:29:01 +04:00
|
|
|
if ((*text) != begin)
|
|
|
|
{
|
|
|
|
(*text)--;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 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
|
|
|
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_8bit_isspace (const char *text)
|
|
|
|
{
|
2009-05-21 01:49:01 +04:00
|
|
|
return char_isspace (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
|
|
|
}
|
|
|
|
|
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_8bit_ispunct (const char *text)
|
|
|
|
{
|
2009-05-21 01:49:01 +04:00
|
|
|
return char_ispunct (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
|
|
|
}
|
|
|
|
|
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_8bit_isalnum (const char *text)
|
|
|
|
{
|
2009-05-21 01:49:01 +04:00
|
|
|
return char_isalnum (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
|
|
|
}
|
|
|
|
|
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_8bit_isdigit (const char *text)
|
|
|
|
{
|
2009-05-21 01:49:01 +04:00
|
|
|
return char_isdigit (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
|
|
|
}
|
|
|
|
|
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_8bit_isprint (const char *text)
|
|
|
|
{
|
2009-05-21 01:49:01 +04:00
|
|
|
return char_isprint (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
|
|
|
}
|
|
|
|
|
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_8bit_iscombiningmark (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 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-04-14 14:29:01 +04:00
|
|
|
str_8bit_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)
|
|
|
|
return 0;
|
2009-05-21 01:49:01 +04:00
|
|
|
(*out)[0] = char_toupper (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
|
|
|
(*out)++;
|
|
|
|
(*remain)--;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-04-14 14:29:01 +04:00
|
|
|
str_8bit_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)
|
|
|
|
return 0;
|
2009-05-21 01:49:01 +04:00
|
|
|
(*out)[0] = char_tolower (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
|
|
|
(*out)++;
|
|
|
|
(*remain)--;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
str_8bit_length (const char *text)
|
|
|
|
{
|
|
|
|
return strlen (text);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
str_8bit_length2 (const char *text, int size)
|
|
|
|
{
|
2009-04-24 02:47:22 +04: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
|
|
|
}
|
|
|
|
|
2009-04-29 20:08:33 +04:00
|
|
|
static gchar *
|
|
|
|
str_8bit_conv_gerror_message (GError *error, const char *def_msg)
|
|
|
|
{
|
|
|
|
GIConv conv;
|
|
|
|
gchar *ret;
|
|
|
|
|
|
|
|
/* glib messages are in UTF-8 charset */
|
|
|
|
conv = str_crt_conv_from ("UTF-8");
|
|
|
|
|
|
|
|
if (conv == INVALID_CONV)
|
|
|
|
ret = g_strdup (def_msg != NULL ? def_msg : "");
|
|
|
|
else {
|
|
|
|
GString *buf;
|
|
|
|
|
|
|
|
buf = g_string_new ("");
|
|
|
|
|
|
|
|
if (str_convert (conv, error->message, buf) != ESTR_FAILURE) {
|
|
|
|
ret = buf->str;
|
|
|
|
g_string_free (buf, FALSE);
|
|
|
|
} else {
|
|
|
|
ret = g_strdup (def_msg != NULL ? def_msg : "");
|
|
|
|
g_string_free (buf, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
str_close_conv (conv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-04-22 20:35:32 +04:00
|
|
|
static estr_t
|
2009-04-15 13:22:34 +04:00
|
|
|
str_8bit_vfs_convert_to (GIConv coder, const char *string,
|
2009-04-14 14:29:01 +04:00
|
|
|
int size, GString * buffer)
|
|
|
|
{
|
2009-04-22 20:35:32 +04:00
|
|
|
estr_t result;
|
2009-04-14 14:29:01 +04:00
|
|
|
|
|
|
|
if (coder == str_cnv_not_convert)
|
|
|
|
{
|
|
|
|
g_string_append_len (buffer, string, size);
|
2009-04-22 20:35:32 +04:00
|
|
|
result = 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
|
|
|
}
|
2009-04-14 14:29:01 +04:00
|
|
|
else
|
|
|
|
result = str_nconvert (coder, (char *) string, size, 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
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
str_8bit_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
|
|
|
|
|
|
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
|
|
|
{
|
2009-05-21 01:49:01 +04:00
|
|
|
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
2009-04-24 20:01:06 +04:00
|
|
|
str_8bit_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;
|
|
|
|
int ident;
|
|
|
|
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);
|
|
|
|
|
2009-04-24 02:47:22 +04:00
|
|
|
if ((int)length <= width)
|
2009-04-14 14:29:01 +04:00
|
|
|
{
|
|
|
|
ident = 0;
|
|
|
|
switch (HIDE_FIT (just_mode))
|
|
|
|
{
|
|
|
|
case J_CENTER_LEFT:
|
|
|
|
case J_CENTER:
|
|
|
|
ident = (width - length) / 2;
|
|
|
|
break;
|
|
|
|
case J_RIGHT:
|
|
|
|
ident = width - length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-04-24 02:47:22 +04:00
|
|
|
if ((int)remain <= ident)
|
2009-04-14 14:29:01 +04:00
|
|
|
goto finally;
|
|
|
|
memset (actual, ' ', ident);
|
|
|
|
actual += ident;
|
|
|
|
remain -= ident;
|
|
|
|
|
|
|
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
|
|
|
{
|
2009-05-21 01:49:01 +04:00
|
|
|
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
2009-04-14 14:29:01 +04:00
|
|
|
}
|
|
|
|
if (width - length - ident > 0)
|
|
|
|
{
|
|
|
|
if (remain <= width - length - ident)
|
|
|
|
goto finally;
|
|
|
|
memset (actual, ' ', width - length - ident);
|
|
|
|
actual += width - length - ident;
|
|
|
|
remain -= width - length - ident;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (IS_FIT (just_mode))
|
|
|
|
{
|
2009-04-24 02:47:22 +04:00
|
|
|
for (; pos + 1 <= (gsize)width / 2 && remain > 1;
|
2009-04-14 14:29:01 +04:00
|
|
|
actual++, pos++, remain--)
|
|
|
|
{
|
|
|
|
|
2009-05-21 01:49:01 +04:00
|
|
|
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
2009-04-14 14:29:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (remain <= 1)
|
|
|
|
goto finally;
|
|
|
|
actual[0] = '~';
|
|
|
|
actual++;
|
|
|
|
remain--;
|
|
|
|
|
|
|
|
pos += length - width + 1;
|
|
|
|
|
|
|
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
|
|
|
{
|
2009-05-21 01:49:01 +04:00
|
|
|
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
2009-04-14 14:29:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ident = 0;
|
|
|
|
switch (HIDE_FIT (just_mode))
|
|
|
|
{
|
|
|
|
case J_CENTER:
|
|
|
|
ident = (length - width) / 2;
|
|
|
|
break;
|
|
|
|
case J_RIGHT:
|
|
|
|
ident = length - width;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos += ident;
|
2009-04-24 02:47:22 +04:00
|
|
|
for (; pos < (gsize)(ident + width) && remain > 1;
|
2009-04-14 14:29:01 +04:00
|
|
|
pos++, actual++, remain--)
|
|
|
|
{
|
|
|
|
|
2009-05-21 01:49:01 +04:00
|
|
|
actual[0] = char_isprint (text[pos]) ? text[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
|
|
|
}
|
|
|
|
finally:
|
|
|
|
actual[0] = '\0';
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
2009-04-14 14:29:01 +04:00
|
|
|
str_8bit_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 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
|
|
|
length = strlen (text);
|
|
|
|
actual = result;
|
|
|
|
remain = sizeof (result);
|
2009-04-14 14:29:01 +04:00
|
|
|
|
2009-04-24 02:47:22 +04:00
|
|
|
if (width < (int)length)
|
2009-04-14 14:29:01 +04:00
|
|
|
{
|
|
|
|
if (width <= 3)
|
|
|
|
{
|
|
|
|
memset (actual, '.', width);
|
|
|
|
actual += width;
|
|
|
|
remain -= width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memset (actual, '.', 3);
|
|
|
|
actual += 3;
|
|
|
|
remain -= 3;
|
|
|
|
|
|
|
|
pos += length - width + 3;
|
|
|
|
|
|
|
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
|
|
|
{
|
2009-05-21 01:49:01 +04:00
|
|
|
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
2009-04-14 14:29:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
|
|
|
{
|
2009-05-21 01:49:01 +04:00
|
|
|
actual[0] = char_isprint (text[pos]) ? text[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
|
|
|
actual[0] = '\0';
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
str_8bit_term_width2 (const char *text, size_t length)
|
|
|
|
{
|
2009-04-14 14:29:01 +04:00
|
|
|
return (length != (size_t) (-1))
|
|
|
|
? min (strlen (text), length) : 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
|
|
|
|
|
|
|
static int
|
|
|
|
str_8bit_term_width1 (const char *text)
|
|
|
|
{
|
2009-04-14 14:29:01 +04:00
|
|
|
return str_8bit_term_width2 (text, (size_t) (-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
|
|
|
static int
|
|
|
|
str_8bit_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
|
|
|
}
|
|
|
|
|
|
|
|
static 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
|
|
|
str_8bit_msg_term_size (const char *text, int *lines, int *columns)
|
|
|
|
{
|
|
|
|
|
2009-04-24 02:47:22 +04:00
|
|
|
char *p, *tmp;
|
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 *q;
|
|
|
|
char c = '\0';
|
|
|
|
int width;
|
|
|
|
|
2009-04-24 02:47:22 +04:00
|
|
|
(*lines) = 1;
|
|
|
|
(*columns) = 0;
|
|
|
|
tmp = g_strdup ((char *)text);
|
2009-04-24 12:40:00 +04:00
|
|
|
p = tmp;
|
2009-04-14 14:29:01 +04:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
q = strchr (p, '\n');
|
|
|
|
if (q != NULL)
|
|
|
|
{
|
|
|
|
c = q[0];
|
|
|
|
q[0] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
width = str_8bit_term_width1 (p);
|
|
|
|
if (width > (*columns))
|
|
|
|
(*columns) = width;
|
|
|
|
|
|
|
|
if (q == NULL)
|
|
|
|
break;
|
|
|
|
q[0] = c;
|
|
|
|
p = q + 1;
|
|
|
|
(*lines)++;
|
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
|
|
|
}
|
|
|
|
g_free (tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
str_8bit_term_substring (const char *text, int start, int width)
|
|
|
|
{
|
|
|
|
static char result[BUF_MEDIUM];
|
|
|
|
size_t 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
|
|
|
|
2009-04-24 02:47:22 +04:00
|
|
|
if (start < (int)length)
|
2009-04-14 14:29:01 +04:00
|
|
|
{
|
|
|
|
pos += start;
|
|
|
|
for (; pos < length && width > 0 && remain > 1;
|
|
|
|
pos++, width--, actual++, remain--)
|
|
|
|
{
|
|
|
|
|
2009-05-21 01:49:01 +04:00
|
|
|
actual[0] = char_isprint (text[pos]) ? text[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
|
|
|
}
|
2009-04-14 14:29:01 +04:00
|
|
|
|
|
|
|
for (; width > 0 && remain > 1; actual++, remain--, width--)
|
|
|
|
{
|
|
|
|
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;
|
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
|
|
|
|
|
|
|
static const char *
|
|
|
|
str_8bit_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
|
|
|
|
2009-04-24 02:47:22 +04:00
|
|
|
if ((int)length > width)
|
2009-04-14 14:29:01 +04:00
|
|
|
{
|
2009-04-24 02:47:22 +04:00
|
|
|
for (; pos + 1 <= (gsize)width / 2 && remain > 1; actual++, pos++, remain--)
|
2009-04-14 14:29:01 +04:00
|
|
|
{
|
2009-05-21 01:49:01 +04:00
|
|
|
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
2009-04-14 14:29:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (remain <= 1)
|
|
|
|
goto finally;
|
|
|
|
actual[0] = '~';
|
|
|
|
actual++;
|
|
|
|
remain--;
|
|
|
|
|
|
|
|
pos += length - width + 1;
|
|
|
|
|
|
|
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
|
|
|
{
|
2009-05-21 01:49:01 +04:00
|
|
|
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
2009-04-14 14:29:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
|
|
|
{
|
2009-05-21 01:49:01 +04:00
|
|
|
actual[0] = char_isprint (text[pos]) ? text[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
|
|
|
}
|
|
|
|
|
|
|
|
finally:
|
|
|
|
actual[0] = '\0';
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
str_8bit_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
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
str_8bit_column_to_pos (const char *text, size_t pos)
|
|
|
|
{
|
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 (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
|
|
|
|
|
|
|
static char *
|
|
|
|
str_8bit_create_search_needle (const char *needle, int case_sen)
|
|
|
|
{
|
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
|
|
|
|
2009-04-14 14:29:01 +04:00
|
|
|
static 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
|
|
|
str_8bit_release_search_needle (char *needle, int case_sen)
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
str_8bit_search_first (const char *text, const char *search, int case_sen)
|
|
|
|
{
|
|
|
|
char *fold_text;
|
|
|
|
char *fold_search;
|
|
|
|
const char *match;
|
|
|
|
size_t offsset;
|
2009-04-14 14:29:01 +04:00
|
|
|
|
|
|
|
fold_text = (case_sen) ? (char *) text : g_strdown (g_strdup (text));
|
2009-04-18 16:38:36 +04:00
|
|
|
fold_search = (case_sen) ? (char *) search : g_strdown (g_strdup (search));
|
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)
|
|
|
|
{
|
|
|
|
offsset = match - fold_text;
|
|
|
|
match = text + offsset;
|
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)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
str_8bit_search_last (const char *text, const char *search, int case_sen)
|
|
|
|
{
|
|
|
|
char *fold_text;
|
|
|
|
char *fold_search;
|
|
|
|
const char *match;
|
|
|
|
size_t offsset;
|
2009-04-14 14:29:01 +04:00
|
|
|
|
|
|
|
fold_text = (case_sen) ? (char *) text : g_strdown (g_strdup (text));
|
2009-04-18 16:38:36 +04:00
|
|
|
fold_search = (case_sen) ? (char *) search : g_strdown (g_strdup (search));
|
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)
|
|
|
|
{
|
|
|
|
offsset = match - fold_text;
|
|
|
|
match = text + offsset;
|
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)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
str_8bit_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
|
|
|
|
|
|
|
static int
|
|
|
|
str_8bit_ncompare (const char *t1, const char *t2)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
static int
|
|
|
|
str_8bit_casecmp (const char *t1, const char *t2)
|
|
|
|
{
|
|
|
|
return g_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
|
|
|
|
|
|
|
static int
|
|
|
|
str_8bit_ncasecmp (const char *t1, const char *t2)
|
|
|
|
{
|
|
|
|
return g_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
|
|
|
|
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_8bit_prefix (const char *text, const char *prefix)
|
|
|
|
{
|
|
|
|
int result;
|
2009-04-14 14:29:01 +04:00
|
|
|
for (result = 0; text[result] != '\0' && prefix[result] != '\0'
|
|
|
|
&& text[result] == prefix[result]; result++);
|
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;
|
|
|
|
}
|
|
|
|
|
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_8bit_caseprefix (const char *text, const char *prefix)
|
|
|
|
{
|
|
|
|
int result;
|
2009-04-14 14:29:01 +04:00
|
|
|
for (result = 0; text[result] != '\0' && prefix[result] != '\0'
|
2009-05-21 01:49:01 +04:00
|
|
|
&& char_toupper (text[result]) == char_toupper (prefix[result]); result++);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
str_8bit_fix_string (char *text)
|
|
|
|
{
|
2009-04-24 02:47:22 +04:00
|
|
|
(void) 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
|
|
|
|
|
|
|
static char *
|
2009-04-14 14:29:01 +04:00
|
|
|
str_8bit_create_key (const char *text, int 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-14 14:29:01 +04:00
|
|
|
return (case_sen) ? (char *) text : g_strdown (g_strdup (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
|
|
|
static int
|
|
|
|
str_8bit_key_collate (const char *t1, const char *t2, int case_sen)
|
|
|
|
{
|
2009-04-14 14:29:01 +04:00
|
|
|
if (case_sen)
|
|
|
|
return strcmp (t1, t2);
|
|
|
|
else
|
|
|
|
return strcoll (t1, t2);
|
|
|
|
}
|
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_8bit_release_key (char *key, int case_sen)
|
|
|
|
{
|
2009-04-14 14:29:01 +04:00
|
|
|
if (!case_sen)
|
|
|
|
g_free (key);
|
|
|
|
}
|
patches by Rostislav Beneš: mc-01-api
add functions for working with strings
some functions are implemented directlu in strutil.c, others have ascii, 8bit
or utf-8 variant. (8bit means singlebyte encodings, where all characters have
width one). Mc autodetects terminal encoding at start and chooses right
variant. If does not know terminal encoding, chooses ascii variant.
contains functions:
1. for translation strings and growing strings
2. for working with characters (next char, prev char, length in
characters, isspace, isalnum, ...)
3. prepeare for display, replace invalid characters with questionmark,
unprintable with dot, left / right / center align
4. comparing strings
in future all string function from util should be moved into strutil, some
function from util have new variant in strutil.
2008-12-29 01:46:37 +03:00
|
|
|
|
|
|
|
struct str_class
|
2009-10-30 04:12:04 +03:00
|
|
|
str_8bit_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_8bit_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_8bit_vfs_convert_to;
|
|
|
|
result.insert_replace_char = str_8bit_insert_replace_char;
|
|
|
|
result.is_valid_string = str_8bit_is_valid_string;
|
2009-04-14 14:29:01 +04:00
|
|
|
result.is_valid_char = str_8bit_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_8bit_cnext_char;
|
|
|
|
result.cprev_char = str_8bit_cprev_char;
|
|
|
|
result.cnext_char_safe = str_8bit_cnext_char;
|
|
|
|
result.cprev_char_safe = str_8bit_cprev_char;
|
|
|
|
result.cnext_noncomb_char = str_8bit_cnext_noncomb_char;
|
|
|
|
result.cprev_noncomb_char = str_8bit_cprev_noncomb_char;
|
|
|
|
result.isspace = str_8bit_isspace;
|
|
|
|
result.ispunct = str_8bit_ispunct;
|
|
|
|
result.isalnum = str_8bit_isalnum;
|
|
|
|
result.isdigit = str_8bit_isdigit;
|
|
|
|
result.isprint = str_8bit_isprint;
|
|
|
|
result.iscombiningmark = str_8bit_iscombiningmark;
|
|
|
|
result.toupper = str_8bit_toupper;
|
|
|
|
result.tolower = str_8bit_tolower;
|
|
|
|
result.length = str_8bit_length;
|
|
|
|
result.length2 = str_8bit_length2;
|
|
|
|
result.length_noncomb = str_8bit_length;
|
|
|
|
result.fix_string = str_8bit_fix_string;
|
|
|
|
result.term_form = str_8bit_term_form;
|
|
|
|
result.fit_to_term = str_8bit_fit_to_term;
|
|
|
|
result.term_trim = str_8bit_term_trim;
|
|
|
|
result.term_width2 = str_8bit_term_width2;
|
|
|
|
result.term_width1 = str_8bit_term_width1;
|
|
|
|
result.term_char_width = str_8bit_term_char_width;
|
|
|
|
result.msg_term_size = str_8bit_msg_term_size;
|
|
|
|
result.term_substring = str_8bit_term_substring;
|
|
|
|
result.trunc = str_8bit_trunc;
|
|
|
|
result.offset_to_pos = str_8bit_offset_to_pos;
|
|
|
|
result.column_to_pos = str_8bit_column_to_pos;
|
|
|
|
result.create_search_needle = str_8bit_create_search_needle;
|
|
|
|
result.release_search_needle = str_8bit_release_search_needle;
|
|
|
|
result.search_first = str_8bit_search_first;
|
|
|
|
result.search_last = str_8bit_search_last;
|
|
|
|
result.compare = str_8bit_compare;
|
|
|
|
result.ncompare = str_8bit_ncompare;
|
|
|
|
result.casecmp = str_8bit_casecmp;
|
|
|
|
result.ncasecmp = str_8bit_ncasecmp;
|
|
|
|
result.prefix = str_8bit_prefix;
|
|
|
|
result.caseprefix = str_8bit_caseprefix;
|
|
|
|
result.create_key = str_8bit_create_key;
|
|
|
|
result.create_key_for_filename = str_8bit_create_key;
|
|
|
|
result.key_collate = str_8bit_key_collate;
|
|
|
|
result.release_key = str_8bit_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;
|
|
|
|
}
|