File: unicode_wcwidth.c

package info (click to toggle)
courier-authlib 0.63.0-6
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 17,720 kB
  • sloc: ansic: 60,549; sh: 10,525; perl: 3,503; makefile: 1,042; cpp: 284
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;
}