172cf60a5SOliver Tappe/* Determine display width of Unicode character.
272cf60a5SOliver Tappe Copyright (C) 2001-2002, 2006-2010 Free Software Foundation, Inc.
372cf60a5SOliver Tappe Written by Bruno Haible <bruno@clisp.org>, 2002.
472cf60a5SOliver Tappe
572cf60a5SOliver Tappe This program is free software: you can redistribute it and/or modify it
672cf60a5SOliver Tappe under the terms of the GNU Lesser General Public License as published
772cf60a5SOliver Tappe by the Free Software Foundation; either version 3 of the License, or
872cf60a5SOliver Tappe (at your option) any later version.
972cf60a5SOliver Tappe
1072cf60a5SOliver Tappe This program is distributed in the hope that it will be useful,
1172cf60a5SOliver Tappe but WITHOUT ANY WARRANTY; without even the implied warranty of
1272cf60a5SOliver Tappe MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1372cf60a5SOliver Tappe Lesser General Public License for more details.
1472cf60a5SOliver Tappe
1572cf60a5SOliver Tappe You should have received a copy of the GNU Lesser General Public License
1672cf60a5SOliver Tappe along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
1772cf60a5SOliver Tappe
1872cf60a5SOliver Tappe#include <locale.h>
193aeed660SJérôme Duval#include <strings.h>
2072cf60a5SOliver Tappe#include <wchar.h>
2172cf60a5SOliver Tappe
2272cf60a5SOliver Tappe
2372cf60a5SOliver Tappe/*
2472cf60a5SOliver Tappe * Non-spacing attribute table.
2572cf60a5SOliver Tappe * Consists of:
2672cf60a5SOliver Tappe * - Non-spacing characters; generated from PropList.txt or
2772cf60a5SOliver Tappe *   "grep '^[^;]*;[^;]*;[^;]*;[^;]*;NSM;' UnicodeData.txt"
2872cf60a5SOliver Tappe * - Format control characters; generated from
2972cf60a5SOliver Tappe *   "grep '^[^;]*;[^;]*;Cf;' UnicodeData.txt"
3072cf60a5SOliver Tappe * - Zero width characters; generated from
3172cf60a5SOliver Tappe *   "grep '^[^;]*;ZERO WIDTH ' UnicodeData.txt"
3272cf60a5SOliver Tappe */
3372cf60a5SOliver Tappestatic const unsigned char nonspacing_table_data[26 * 64] = {
3472cf60a5SOliver Tappe	/* 0x0000-0x01ff */
3572cf60a5SOliver Tappe	0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, /* 0x0000-0x003f */
3672cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* 0x0040-0x007f */
3772cf60a5SOliver Tappe	0xff, 0xff, 0xff, 0xff, 0x00, 0x20, 0x00, 0x00, /* 0x0080-0x00bf */
3872cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00c0-0x00ff */
3972cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0100-0x013f */
4072cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0140-0x017f */
4172cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0180-0x01bf */
4272cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x01c0-0x01ff */
4372cf60a5SOliver Tappe	/* 0x0200-0x03ff */
4472cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0200-0x023f */
4572cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0240-0x027f */
4672cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0280-0x02bf */
4772cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x02c0-0x02ff */
4872cf60a5SOliver Tappe	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x0300-0x033f */
4972cf60a5SOliver Tappe	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, /* 0x0340-0x037f */
5072cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0380-0x03bf */
5172cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x03c0-0x03ff */
5272cf60a5SOliver Tappe	/* 0x0400-0x05ff */
5372cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0400-0x043f */
5472cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0440-0x047f */
5572cf60a5SOliver Tappe	0xf8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0480-0x04bf */
5672cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x04c0-0x04ff */
5772cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0500-0x053f */
5872cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0540-0x057f */
5972cf60a5SOliver Tappe	0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xbf, /* 0x0580-0x05bf */
6072cf60a5SOliver Tappe	0xb6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x05c0-0x05ff */
6172cf60a5SOliver Tappe	/* 0x0600-0x07ff */
6272cf60a5SOliver Tappe	0x0f, 0x00, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, /* 0x0600-0x063f */
6372cf60a5SOliver Tappe	0x00, 0xf8, 0xff, 0x7f, 0x00, 0x00, 0x01, 0x00, /* 0x0640-0x067f */
6472cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0680-0x06bf */
6572cf60a5SOliver Tappe	0x00, 0x00, 0xc0, 0xff, 0x9f, 0x3d, 0x00, 0x00, /* 0x06c0-0x06ff */
6672cf60a5SOliver Tappe	0x00, 0x80, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, /* 0x0700-0x073f */
6772cf60a5SOliver Tappe	0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0740-0x077f */
6872cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x01, 0x00, /* 0x0780-0x07bf */
6972cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x0f, 0x00, /* 0x07c0-0x07ff */
7072cf60a5SOliver Tappe	/* 0x0800-0x09ff */
7172cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0800-0x083f */
7272cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0840-0x087f */
7372cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0880-0x08bf */
7472cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08c0-0x08ff */
7572cf60a5SOliver Tappe	0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0900-0x093f */
7672cf60a5SOliver Tappe	0xfe, 0x21, 0x1e, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0940-0x097f */
7772cf60a5SOliver Tappe	0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0980-0x09bf */
7872cf60a5SOliver Tappe	0x1e, 0x20, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x09c0-0x09ff */
7972cf60a5SOliver Tappe	/* 0x0a00-0x0bff */
8072cf60a5SOliver Tappe	0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0a00-0x0a3f */
8172cf60a5SOliver Tappe	0x86, 0x39, 0x02, 0x00, 0x00, 0x00, 0x23, 0x00, /* 0x0a40-0x0a7f */
8272cf60a5SOliver Tappe	0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0a80-0x0abf */
8372cf60a5SOliver Tappe	0xbe, 0x21, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0ac0-0x0aff */
8472cf60a5SOliver Tappe	0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, /* 0x0b00-0x0b3f */
8572cf60a5SOliver Tappe	0x1e, 0x20, 0x40, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0b40-0x0b7f */
8672cf60a5SOliver Tappe	0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0b80-0x0bbf */
8772cf60a5SOliver Tappe	0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0bc0-0x0bff */
8872cf60a5SOliver Tappe	/* 0x0c00-0x0dff */
8972cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, /* 0x0c00-0x0c3f */
9072cf60a5SOliver Tappe	0xc1, 0x3d, 0x60, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0c40-0x0c7f */
9172cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0c80-0x0cbf */
9272cf60a5SOliver Tappe	0x00, 0x30, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0cc0-0x0cff */
9372cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0d00-0x0d3f */
9472cf60a5SOliver Tappe	0x1e, 0x20, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0d40-0x0d7f */
9572cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0d80-0x0dbf */
9672cf60a5SOliver Tappe	0x00, 0x04, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0dc0-0x0dff */
9772cf60a5SOliver Tappe	/* 0x0e00-0x0fff */
9872cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x07, /* 0x0e00-0x0e3f */
9972cf60a5SOliver Tappe	0x80, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0e40-0x0e7f */
10072cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x1b, /* 0x0e80-0x0ebf */
10172cf60a5SOliver Tappe	0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0ec0-0x0eff */
10272cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0xa0, 0x02, /* 0x0f00-0x0f3f */
10372cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x7f, /* 0x0f40-0x0f7f */
10472cf60a5SOliver Tappe	0xdf, 0x00, 0xff, 0xfe, 0xff, 0xff, 0xff, 0x1f, /* 0x0f80-0x0fbf */
10572cf60a5SOliver Tappe	0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0fc0-0x0fff */
10672cf60a5SOliver Tappe	/* 0x1000-0x11ff */
10772cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xfd, 0x66, /* 0x1000-0x103f */
10872cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0xc3, 0x01, 0x00, 0x1e, 0x00, /* 0x1040-0x107f */
10972cf60a5SOliver Tappe	0x64, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1080-0x10bf */
11072cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10c0-0x10ff */
11172cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1100-0x113f */
11272cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1140-0x117f */
11372cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1180-0x11bf */
11472cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11c0-0x11ff */
11572cf60a5SOliver Tappe	/* 0x1200-0x13ff */
11672cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1200-0x123f */
11772cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1240-0x127f */
11872cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1280-0x12bf */
11972cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x12c0-0x12ff */
12072cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1300-0x133f */
12172cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, /* 0x1340-0x137f */
12272cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1380-0x13bf */
12372cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x13c0-0x13ff */
12472cf60a5SOliver Tappe	/* 0x1600-0x17ff */
12572cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1600-0x163f */
12672cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1640-0x167f */
12772cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1680-0x16bf */
12872cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x16c0-0x16ff */
12972cf60a5SOliver Tappe	0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x1c, 0x00, /* 0x1700-0x173f */
13072cf60a5SOliver Tappe	0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, /* 0x1740-0x177f */
13172cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x3f, /* 0x1780-0x17bf */
13272cf60a5SOliver Tappe	0x40, 0xfe, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x00, /* 0x17c0-0x17ff */
13372cf60a5SOliver Tappe	/* 0x1800-0x19ff */
13472cf60a5SOliver Tappe	0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1800-0x183f */
13572cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1840-0x187f */
13672cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, /* 0x1880-0x18bf */
13772cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18c0-0x18ff */
13872cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x87, 0x01, 0x04, 0x0e, /* 0x1900-0x193f */
13972cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1940-0x197f */
14072cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1980-0x19bf */
14172cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x19c0-0x19ff */
14272cf60a5SOliver Tappe	/* 0x1a00-0x1bff */
14372cf60a5SOliver Tappe	0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, /* 0x1a00-0x1a3f */
14472cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1a40-0x1a7f */
14572cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1a80-0x1abf */
14672cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1ac0-0x1aff */
14772cf60a5SOliver Tappe	0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x17, /* 0x1b00-0x1b3f */
14872cf60a5SOliver Tappe	0x04, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x0f, 0x00, /* 0x1b40-0x1b7f */
14972cf60a5SOliver Tappe	0x03, 0x00, 0x00, 0x00, 0x3c, 0x03, 0x00, 0x00, /* 0x1b80-0x1bbf */
15072cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1bc0-0x1bff */
15172cf60a5SOliver Tappe	/* 0x1c00-0x1dff */
15272cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xcf, 0x00, /* 0x1c00-0x1c3f */
15372cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1c40-0x1c7f */
15472cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1c80-0x1cbf */
15572cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1cc0-0x1cff */
15672cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d00-0x1d3f */
15772cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d40-0x1d7f */
15872cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d80-0x1dbf */
15972cf60a5SOliver Tappe	0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xc0, /* 0x1dc0-0x1dff */
16072cf60a5SOliver Tappe	/* 0x2000-0x21ff */
16172cf60a5SOliver Tappe	0x00, 0xf8, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, /* 0x2000-0x203f */
16272cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x1f, 0xfc, 0x00, 0x00, /* 0x2040-0x207f */
16372cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2080-0x20bf */
16472cf60a5SOliver Tappe	0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, /* 0x20c0-0x20ff */
16572cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2100-0x213f */
16672cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2140-0x217f */
16772cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2180-0x21bf */
16872cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x21c0-0x21ff */
16972cf60a5SOliver Tappe	/* 0x2c00-0x2dff */
17072cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2c00-0x2c3f */
17172cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2c40-0x2c7f */
17272cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2c80-0x2cbf */
17372cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2cc0-0x2cff */
17472cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2d00-0x2d3f */
17572cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2d40-0x2d7f */
17672cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2d80-0x2dbf */
17772cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, /* 0x2dc0-0x2dff */
17872cf60a5SOliver Tappe	/* 0x3000-0x31ff */
17972cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, /* 0x3000-0x303f */
18072cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x3040-0x307f */
18172cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, /* 0x3080-0x30bf */
18272cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30c0-0x30ff */
18372cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x3100-0x313f */
18472cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x3140-0x317f */
18572cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x3180-0x31bf */
18672cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x31c0-0x31ff */
18772cf60a5SOliver Tappe	/* 0xa600-0xa7ff */
18872cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa600-0xa63f */
18972cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x30, /* 0xa640-0xa67f */
19072cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa680-0xa6bf */
19172cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa6c0-0xa6ff */
19272cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa700-0xa73f */
19372cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa740-0xa77f */
19472cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa780-0xa7bf */
19572cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa7c0-0xa7ff */
19672cf60a5SOliver Tappe	/* 0xa800-0xa9ff */
19772cf60a5SOliver Tappe	0x44, 0x08, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, /* 0xa800-0xa83f */
19872cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa840-0xa87f */
19972cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa880-0xa8bf */
20072cf60a5SOliver Tappe	0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8c0-0xa8ff */
20172cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0xc0, 0x3f, 0x00, 0x00, /* 0xa900-0xa93f */
20272cf60a5SOliver Tappe	0x80, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa940-0xa97f */
20372cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa980-0xa9bf */
20472cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa9c0-0xa9ff */
20572cf60a5SOliver Tappe	/* 0xaa00-0xabff */
20672cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x66, 0x00, /* 0xaa00-0xaa3f */
20772cf60a5SOliver Tappe	0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xaa40-0xaa7f */
20872cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xaa80-0xaabf */
20972cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xaac0-0xaaff */
21072cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xab00-0xab3f */
21172cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xab40-0xab7f */
21272cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xab80-0xabbf */
21372cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xabc0-0xabff */
21472cf60a5SOliver Tappe	/* 0xfa00-0xfbff */
21572cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfa00-0xfa3f */
21672cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfa40-0xfa7f */
21772cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfa80-0xfabf */
21872cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfac0-0xfaff */
21972cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, /* 0xfb00-0xfb3f */
22072cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfb40-0xfb7f */
22172cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfb80-0xfbbf */
22272cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfbc0-0xfbff */
22372cf60a5SOliver Tappe	/* 0xfe00-0xffff */
22472cf60a5SOliver Tappe	0xff, 0xff, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, /* 0xfe00-0xfe3f */
22572cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfe40-0xfe7f */
22672cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfe80-0xfebf */
22772cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* 0xfec0-0xfeff */
22872cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xff00-0xff3f */
22972cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xff40-0xff7f */
23072cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xff80-0xffbf */
23172cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, /* 0xffc0-0xffff */
23272cf60a5SOliver Tappe	/* 0x10000-0x101ff */
23372cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10000-0x1003f */
23472cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10040-0x1007f */
23572cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10080-0x100bf */
23672cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x100c0-0x100ff */
23772cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10100-0x1013f */
23872cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10140-0x1017f */
23972cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10180-0x101bf */
24072cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, /* 0x101c0-0x101ff */
24172cf60a5SOliver Tappe	/* 0x10a00-0x10bff */
24272cf60a5SOliver Tappe	0x6e, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, /* 0x10a00-0x10a3f */
24372cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10a40-0x10a7f */
24472cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10a80-0x10abf */
24572cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10ac0-0x10aff */
24672cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10b00-0x10b3f */
24772cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10b40-0x10b7f */
24872cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10b80-0x10bbf */
24972cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10bc0-0x10bff */
25072cf60a5SOliver Tappe	/* 0x1d000-0x1d1ff */
25172cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d000-0x1d03f */
25272cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d040-0x1d07f */
25372cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d080-0x1d0bf */
25472cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d0c0-0x1d0ff */
25572cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d100-0x1d13f */
25672cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0xf8, /* 0x1d140-0x1d17f */
25772cf60a5SOliver Tappe	0xe7, 0x0f, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, /* 0x1d180-0x1d1bf */
25872cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d1c0-0x1d1ff */
25972cf60a5SOliver Tappe	/* 0x1d200-0x1d3ff */
26072cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d200-0x1d23f */
26172cf60a5SOliver Tappe	0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d240-0x1d27f */
26272cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d280-0x1d2bf */
26372cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d2c0-0x1d2ff */
26472cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d300-0x1d33f */
26572cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d340-0x1d37f */
26672cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d380-0x1d3bf */
26772cf60a5SOliver Tappe	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00  /* 0x1d3c0-0x1d3ff */
26872cf60a5SOliver Tappe};
26972cf60a5SOliver Tappe
27072cf60a5SOliver Tappe
27172cf60a5SOliver Tappestatic const signed char nonspacing_table_ind[240] = {
27272cf60a5SOliver Tappe	0, 1, 2, 3, 4, 5, 6, 7,			/* 0x0000-0x0fff */
27372cf60a5SOliver Tappe	8, 9, -1, 10, 11, 12, 13, -1,   /* 0x1000-0x1fff */
27472cf60a5SOliver Tappe	14, -1, -1, -1, -1, -1, 15, -1, /* 0x2000-0x2fff */
27572cf60a5SOliver Tappe	16, -1, -1, -1, -1, -1, -1, -1, /* 0x3000-0x3fff */
27672cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0x4000-0x4fff */
27772cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0x5000-0x5fff */
27872cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0x6000-0x6fff */
27972cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0x7000-0x7fff */
28072cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0x8000-0x8fff */
28172cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0x9000-0x9fff */
28272cf60a5SOliver Tappe	-1, -1, -1, 17, 18, 19, -1, -1, /* 0xa000-0xafff */
28372cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0xb000-0xbfff */
28472cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0xc000-0xcfff */
28572cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0xd000-0xdfff */
28672cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0xe000-0xefff */
28772cf60a5SOliver Tappe	-1, -1, -1, -1, -1, 20, -1, 21, /* 0xf000-0xffff */
28872cf60a5SOliver Tappe	22, -1, -1, -1, -1, 23, -1, -1, /* 0x10000-0x10fff */
28972cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0x11000-0x11fff */
29072cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0x12000-0x12fff */
29172cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0x13000-0x13fff */
29272cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0x14000-0x14fff */
29372cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0x15000-0x15fff */
29472cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0x16000-0x16fff */
29572cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0x17000-0x17fff */
29672cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0x18000-0x18fff */
29772cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0x19000-0x19fff */
29872cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0x1a000-0x1afff */
29972cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0x1b000-0x1bfff */
30072cf60a5SOliver Tappe	-1, -1, -1, -1, -1, -1, -1, -1, /* 0x1c000-0x1cfff */
30172cf60a5SOliver Tappe	24, 25, -1, -1, -1, -1, -1, -1	/* 0x1d000-0x1dfff */
30272cf60a5SOliver Tappe};
30372cf60a5SOliver Tappe
30472cf60a5SOliver Tappe
30572cf60a5SOliver Tappestatic int
30672cf60a5SOliver Tappeis_legacy_cjk_encoding(const char* encoding)
30772cf60a5SOliver Tappe{
30872cf60a5SOliver Tappe	return
30972cf60a5SOliver Tappe		/* Legacy Japanese encodings */
31072cf60a5SOliver Tappe		strcasecmp(encoding, "EUC-JP") == 0
31172cf60a5SOliver Tappe		/* Legacy Chinese encodings */
31272cf60a5SOliver Tappe		|| strcasecmp(encoding, "GB2312") == 0
31372cf60a5SOliver Tappe		|| strcasecmp(encoding, "GBK") == 0
31472cf60a5SOliver Tappe		|| strcasecmp(encoding, "EUC-TW") == 0
31572cf60a5SOliver Tappe		|| strcasecmp(encoding, "BIG5") == 0
31672cf60a5SOliver Tappe		/* Legacy Korean encodings */
31772cf60a5SOliver Tappe		|| strcasecmp(encoding, "EUC-KR") == 0
31872cf60a5SOliver Tappe		|| strcasecmp(encoding, "CP949") == 0
31972cf60a5SOliver Tappe		|| strcasecmp(encoding, "JOHAB") == 0;
32072cf60a5SOliver Tappe}
32172cf60a5SOliver Tappe
32272cf60a5SOliver Tappe
32372cf60a5SOliver Tappeint
32472cf60a5SOliver Tappewcwidth(wchar_t uc)
32572cf60a5SOliver Tappe{
32672cf60a5SOliver Tappe	/* Test for non-spacing or control character.  */
32772cf60a5SOliver Tappe	if ((uc >> 9) < 240) {
32872cf60a5SOliver Tappe		int ind = nonspacing_table_ind[uc >> 9];
32972cf60a5SOliver Tappe		if (ind >= 0)
33072cf60a5SOliver Tappe			if ((nonspacing_table_data[64 * ind + ((uc >> 3) & 63)] >> (uc & 7))
33172cf60a5SOliver Tappe				& 1) {
33272cf60a5SOliver Tappe				if (uc > 0 && uc < 0xa0)
33372cf60a5SOliver Tappe					return -1;
33472cf60a5SOliver Tappe				else
33572cf60a5SOliver Tappe					return 0;
33672cf60a5SOliver Tappe			}
33772cf60a5SOliver Tappe	} else if ((uc >> 9) == (0xe0000 >> 9)) {
33872cf60a5SOliver Tappe		if (uc >= 0xe0100) {
33972cf60a5SOliver Tappe			if (uc <= 0xe01ef)
34072cf60a5SOliver Tappe				return 0;
34172cf60a5SOliver Tappe		} else {
34272cf60a5SOliver Tappe			if (uc >= 0xe0020 ? uc <= 0xe007f : uc == 0xe0001)
34372cf60a5SOliver Tappe				return 0;
34472cf60a5SOliver Tappe		}
34572cf60a5SOliver Tappe	}
34672cf60a5SOliver Tappe	/* Test for double-width character.
34772cf60a5SOliver Tappe	 * Generated from "grep '^[^;]\{4,5\};[WF]' EastAsianWidth.txt"
34872cf60a5SOliver Tappe	 * and            "grep '^[^;]\{4,5\};[^WF]' EastAsianWidth.txt"
34972cf60a5SOliver Tappe	 */
35072cf60a5SOliver Tappe	if (uc >= 0x1100
35172cf60a5SOliver Tappe		&& ((uc < 0x1160)							/* Hangul Jamo */
35272cf60a5SOliver Tappe			|| (uc >= 0x2329 && uc < 0x232b)		/* Angle Brackets */
35372cf60a5SOliver Tappe			|| (uc >= 0x2e80 && uc < 0xa4d0			/* CJK ... Yi */
35472cf60a5SOliver Tappe				&& !(uc == 0x303f) && !(uc >= 0x4dc0 && uc < 0x4e00))
35572cf60a5SOliver Tappe			|| (uc >= 0xac00 && uc < 0xd7a4)		/* Hangul Syllables */
35672cf60a5SOliver Tappe			|| (uc >= 0xf900 && uc < 0xfb00)		/* CJK Compatibility Ideographs */
35772cf60a5SOliver Tappe			|| (uc >= 0xfe10 && uc < 0xfe20)		/* Presentation Forms for Vertical */
35872cf60a5SOliver Tappe			|| (uc >= 0xfe30 && uc < 0xfe70)		/* CJK Compatibility Forms */
35972cf60a5SOliver Tappe			|| (uc >= 0xff00 && uc < 0xff61)		/* Fullwidth Forms */
36072cf60a5SOliver Tappe			|| (uc >= 0xffe0 && uc < 0xffe7)		/* Fullwidth Signs */
36172cf60a5SOliver Tappe			|| (uc >= 0x20000 && uc <= 0x2a6d6)		/* CJK */
36272cf60a5SOliver Tappe			|| (uc >= 0x2f800 && uc <= 0x2fa1d)))	/* CJK Compatibility Ideographs */
36372cf60a5SOliver Tappe		return 2;
36472cf60a5SOliver Tappe
36572cf60a5SOliver Tappe	/* In ancient CJK encodings, Cyrillic and most other characters are
36672cf60a5SOliver Tappe	 double-width as well.  */
36772cf60a5SOliver Tappe	if (uc >= 0x00A1 && uc < 0xFF61 && uc != 0x20A9) {
36872cf60a5SOliver Tappe		char* encoding = setlocale(LC_CTYPE, NULL);
36972cf60a5SOliver Tappe		if (is_legacy_cjk_encoding(encoding))
37072cf60a5SOliver Tappe			return 2;
37172cf60a5SOliver Tappe	}
37272cf60a5SOliver Tappe
37372cf60a5SOliver Tappe	return 1;
37472cf60a5SOliver Tappe}
375