link-grammar-5.8.0/link-grammar/print/print-util.c
/**
 * Return the number of characters in the longest initial substring
 * which has a text-column-width of not greater than max_width.
 */
Return the number of characters in the longest initial substring
which has a text-column-width of not greater than max_width.
Return the number of characters in the longest initial substring which has a text - column - width of not greater than max_width .
size_t utf8_chars_in_width(const char *s, size_t max_width)
{
	size_t total_bytes = 0;
	size_t glyph_width = 0;
	int n = 0;
	wchar_t wc;
	do
	{
		total_bytes += n;
		n = mbrtowc(&wc, s+total_bytes, MB_LEN_MAX, NULL);
		if (n == 0) break;
		if (n < 0)
		{
			glyph_width += 2;
			n = 1;
		}
		else
		{
			int gw = mk_wcwidth(wc);
			if (0 <= gw)
				glyph_width += gw;
			else
				glyph_width += 2;
		}
	}
	while (glyph_width <= max_width);
	return total_bytes;
}
size_t utf8_chars_in_width ( const char * s , size_t max_width ) { size_t total_bytes = 0 ; size_t glyph_width = 0 ; int n = 0 ; wchar_t wc ; do { total_bytes += n ; n = mbrtowc ( & wc , s + total_bytes , MB_LEN_MAX , NULL ) ; if ( n == 0 ) break ; if ( n < 0 ) { glyph_width += 2 ; n = 1 ; } else { int gw = mk_wcwidth ( wc ) ; if ( 0 <= gw ) glyph_width += gw ; else glyph_width += 2 ; } } while ( glyph_width <= max_width ) ; return total_bytes ; }
Return the number of characters in the longest initial substring
 which has a text-column-width of not greater than max_width.
Return the number of characters in the longest initial substring which has a text - column - width of not greater than max_width .
// Allow for double-column-wide box-font printing // i.e. box with the hex code inside. // If we are here, it was a valid UTF-8 code point, // but we do not know the width of the corresponding // glyph. Just like above, assume a double-wide box // font will be printed. //printf("N %zu G %zu;", total_bytes, glyph_width); // printf("\n");