File: unicode_wcwidth.c

package info (click to toggle)
maildrop 2.2.0-3.1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 14,668 kB
  • ctags: 4,761
  • sloc: ansic: 62,043; sh: 10,513; cpp: 10,062; perl: 2,807; makefile: 832
file content (29 lines) | stat: -rw-r--r-- 413 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "unicode_config.h"
#include "unicode.h"

#include "eastasianwidth.h"

#include <stdlib.h>

int unicode_wcwidth(unicode_char c)
{
	size_t b=0;
	size_t e=sizeof(unicode_wcwidth_tab)/sizeof(unicode_wcwidth_tab[0]);

	while (b < e)
	{
		size_t n=b + (e-b)/2;

		if (c >= unicode_wcwidth_tab[n][0])
		{
			if (c <= unicode_wcwidth_tab[n][1])
				return 2;
			b=n+1;
		}
		else
		{
			e=n;
		}
	}
	return 1;
}