1 /*
2 Copyright (C) 2004-2017,2018 John E. Davis
3
4 This file is part of the S-Lang Library.
5
6 The S-Lang Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
10
11 The S-Lang Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 USA.
20 */
21 #include "slinclud.h"
22 #include <ctype.h>
23
24 #include "slang.h"
25 #include "_slang.h"
26
27 #define DEFINE_PSLWC_WIDTH_TABLE
28 #include "slwcwidth.h"
29
30 static int Width_Flags = 0;
SLwchar_wcwidth(SLwchar_Type ch)31 int SLwchar_wcwidth (SLwchar_Type ch)
32 {
33 int w;
34
35 SL_WIDTH_ALOOKUP(w,ch);
36
37 if ((w == 1) || (w == 4))
38 return w;
39
40 if (Width_Flags & SLWCWIDTH_SINGLE_WIDTH)
41 return 1;
42
43 if (w == 3)
44 {
45 if (Width_Flags & SLWCWIDTH_CJK_LEGACY)
46 w = 2;
47 else
48 w = 1;
49 }
50 return w;
51 }
52
SLwchar_set_wcwidth_flags(int flags)53 int SLwchar_set_wcwidth_flags (int flags)
54 {
55 int oflags = Width_Flags;
56 Width_Flags = flags;
57 return oflags;
58 }
59