Пример #1
0
static const char *
str_utf8_trunc (const char *text, int width)
{
    static char result[MC_MAXPATHLEN * 6 * 2];
    const struct term_form *pre_form;
    struct utf8_tool tool;

    pre_form = str_utf8_make_make_term_form (text, (size_t) (-1));

    tool.cheked = pre_form->text;
    tool.actual = result;
    tool.remain = sizeof (result);
    tool.compose = 0;

    if (pre_form->width > (gsize)width)
    {
	tool.ident = 0;
	utf8_tool_copy_chars_to (&tool, width / 2);
	utf8_tool_insert_char (&tool, '~');

	tool.ident = 0;
	utf8_tool_skip_chars_to (&tool, pre_form->width - width + 1);
	utf8_tool_copy_chars_to_end (&tool);
    }
    else
    {
	utf8_tool_copy_chars_to_end (&tool);
    }

    tool.actual[0] = '\0';
    if (tool.compose)
	utf8_tool_compose (result, sizeof (result));
    return result;
}
Пример #2
0
static const char *
str_utf8_term_substring (const char *text, int start, int width)
{
    static char result[BUF_MEDIUM * 6];
    const struct term_form *pre_form;
    struct utf8_tool tool;

    pre_form = str_utf8_make_make_term_form (text, (size_t) (-1));

    tool.cheked = pre_form->text;
    tool.actual = result;
    tool.remain = sizeof (result);
    tool.compose = 0;

    tool.ident = -start;
    utf8_tool_skip_chars_to (&tool, 0);
    if (tool.ident < 0)
	tool.ident = 0;
    utf8_tool_insert_space (&tool, tool.ident);

    utf8_tool_copy_chars_to (&tool, width);
    utf8_tool_insert_space (&tool, width - tool.ident);

    tool.actual[0] = '\0';
    if (tool.compose)
	utf8_tool_compose (result, sizeof (result));
    return result;
}
Пример #3
0
static const char *
str_utf8_term_trim (const char *text, int width)
{
    static char result[BUF_MEDIUM * 6];
    const struct term_form *pre_form;
    struct utf8_tool tool;

    if (width < 1)
    {
        result[0] = '\0';
        return result;
    }

    pre_form = str_utf8_make_make_term_form (text, (size_t) (-1));

    tool.cheked = pre_form->text;
    tool.actual = result;
    tool.remain = sizeof (result);
    tool.compose = 0;

    if ((gsize) width < pre_form->width)
    {
        if (width <= 3)
        {
            memset (tool.actual, '.', width);
            tool.actual += width;
            tool.remain -= width;
        }
        else
        {
            memset (tool.actual, '.', 3);
            tool.actual += 3;
            tool.remain -= 3;

            tool.ident = 0;
            utf8_tool_skip_chars_to (&tool, pre_form->width - width + 3);
            utf8_tool_copy_chars_to_end (&tool);
        }
    }
    else
    {
        utf8_tool_copy_chars_to_end (&tool);
    }

    tool.actual[0] = '\0';
    if (tool.compose)
        utf8_tool_compose (result, sizeof (result));
    return result;
}
Пример #4
0
static const char *
str_utf8_fit_to_term (const char *text, int width, align_crt_t just_mode)
{
    static char result[BUF_MEDIUM * 6];
    const struct term_form *pre_form;
    struct utf8_tool tool;

    pre_form = str_utf8_make_make_term_form (text, (size_t) (-1));
    tool.cheked = pre_form->text;
    tool.actual = result;
    tool.remain = sizeof (result);
    tool.compose = 0;

    if (pre_form->width <= (gsize)width)
    {
	tool.ident = 0;
	switch (HIDE_FIT (just_mode))
	{
	case J_CENTER_LEFT:
	case J_CENTER:
	    tool.ident = (width - pre_form->width) / 2;
	    break;
	case J_RIGHT:
	    tool.ident = width - pre_form->width;
	    break;
	}

	utf8_tool_insert_space (&tool, tool.ident);
	utf8_tool_copy_chars_to_end (&tool);
	utf8_tool_insert_space (&tool, width - pre_form->width - tool.ident);
    }
    else
    {
	if (IS_FIT (just_mode))
	{
	    tool.ident = 0;
	    utf8_tool_copy_chars_to (&tool, width / 2);
	    utf8_tool_insert_char (&tool, '~');

	    tool.ident = 0;
	    utf8_tool_skip_chars_to (&tool, pre_form->width - width + 1);
	    utf8_tool_copy_chars_to_end (&tool);
	    utf8_tool_insert_space (&tool,
				    width - (pre_form->width - tool.ident +
					     1));
	}
	else
	{
	    tool.ident = 0;
	    switch (HIDE_FIT (just_mode))
	    {
	    case J_CENTER:
		tool.ident = (width - pre_form->width) / 2;
		break;
	    case J_RIGHT:
		tool.ident = width - pre_form->width;
		break;
	    }

	    utf8_tool_skip_chars_to (&tool, 0);
	    utf8_tool_insert_space (&tool, tool.ident);
	    utf8_tool_copy_chars_to (&tool, width);
	    utf8_tool_insert_space (&tool, width - tool.ident);
	}
    }

    tool.actual[0] = '\0';
    if (tool.compose)
	utf8_tool_compose (result, sizeof (result));
    return result;
}