mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
added format_real_length()
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1380 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
4d5da596c9
commit
7ced2beab4
@ -216,11 +216,14 @@ void format_create_dest(TEXT_DEST_REC *dest,
|
|||||||
dest->hilight_bg_color = 0;
|
dest->hilight_bg_color = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return length of text part in string (ie. without % codes) */
|
||||||
int format_get_length(const char *str)
|
int format_get_length(const char *str)
|
||||||
{
|
{
|
||||||
GString *tmp;
|
GString *tmp;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
|
g_return_val_if_fail(str != NULL, 0);
|
||||||
|
|
||||||
tmp = g_string_new(NULL);
|
tmp = g_string_new(NULL);
|
||||||
len = 0;
|
len = 0;
|
||||||
while (*str != '\0') {
|
while (*str != '\0') {
|
||||||
@ -233,17 +236,53 @@ int format_get_length(const char *str)
|
|||||||
|
|
||||||
/* %% or unknown %code, written as-is */
|
/* %% or unknown %code, written as-is */
|
||||||
if (*str != '%')
|
if (*str != '%')
|
||||||
len++;
|
len++;
|
||||||
}
|
}
|
||||||
|
|
||||||
len++;
|
len++;
|
||||||
str++;
|
str++;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_string_free(tmp, TRUE);
|
g_string_free(tmp, TRUE);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return how many characters in `str' must be skipped before `len'
|
||||||
|
characters of text is skipped. Like strip_real_length(), except this
|
||||||
|
handles %codes. */
|
||||||
|
int format_real_length(const char *str, int len)
|
||||||
|
{
|
||||||
|
GString *tmp;
|
||||||
|
const char *start;
|
||||||
|
|
||||||
|
g_return_val_if_fail(str != NULL, 0);
|
||||||
|
g_return_val_if_fail(len >= 0, 0);
|
||||||
|
|
||||||
|
start = str;
|
||||||
|
tmp = g_string_new(NULL);
|
||||||
|
while (*str != '\0' && len > 0) {
|
||||||
|
if (*str == '%' && str[1] != '\0') {
|
||||||
|
str++;
|
||||||
|
if (*str != '%' && format_expand_styles(tmp, *str)) {
|
||||||
|
str++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* %% or unknown %code, written as-is */
|
||||||
|
if (*str != '%') {
|
||||||
|
if (--len == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
len--;
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_string_free(tmp, TRUE);
|
||||||
|
return (int) (str-start);
|
||||||
|
}
|
||||||
|
|
||||||
static char *format_get_text_args(TEXT_DEST_REC *dest,
|
static char *format_get_text_args(TEXT_DEST_REC *dest,
|
||||||
const char *text, char **arglist)
|
const char *text, char **arglist)
|
||||||
{
|
{
|
||||||
|
@ -44,6 +44,10 @@ int format_find_tag(const char *module, const char *tag);
|
|||||||
|
|
||||||
/* Return length of text part in string (ie. without % codes) */
|
/* Return length of text part in string (ie. without % codes) */
|
||||||
int format_get_length(const char *str);
|
int format_get_length(const char *str);
|
||||||
|
/* Return how many characters in `str' must be skipped before `len'
|
||||||
|
characters of text is skipped. Like strip_real_length(), except this
|
||||||
|
handles %codes. */
|
||||||
|
int format_real_length(const char *str, int len);
|
||||||
|
|
||||||
char *format_get_text(const char *module, WINDOW_REC *window,
|
char *format_get_text(const char *module, WINDOW_REC *window,
|
||||||
void *server, const char *target,
|
void *server, const char *target,
|
||||||
|
Loading…
Reference in New Issue
Block a user