CXXR (C++ R) API
rlocale.h
1 /*CXXR $Id: rlocale.h 1348 2013-02-25 17:49:03Z arr $
2  *CXXR
3  *CXXR This file is part of CXXR, a project to refactor the R interpreter
4  *CXXR into C++. It may consist in whole or in part of program code and
5  *CXXR documentation taken from the R project itself, incorporated into
6  *CXXR CXXR (and possibly MODIFIED) under the terms of the GNU General Public
7  *CXXR Licence.
8  *CXXR
9  *CXXR CXXR is Copyright (C) 2008-13 Andrew R. Runnalls, subject to such other
10  *CXXR copyrights and copyright restrictions as may be stated below.
11  *CXXR
12  *CXXR CXXR is not part of the R project, and bugs and other issues should
13  *CXXR not be reported via r-bugs or other R project channels; instead refer
14  *CXXR to the CXXR website.
15  *CXXR */
16 
17 /*
18  * R : A Computer Language for Statistical Data Analysis
19  * Copyright (C) 2005-6 The R Core Team
20  *
21  * This program is free software; you can redistribute it and/or modify
22  * it under the terms of the GNU General Public License as published by
23  * the Free Software Foundation; either version 2 of the License, or
24  * (at your option) any later version.
25  *
26  * This program is distributed in the hope that it will be useful,
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29  * GNU General Public License for more details.
30  *
31  * You should have received a copy of the GNU General Public License
32  * along with this program; if not, a copy is available at
33  * http://www.r-project.org/Licenses/
34  */
35 
36 
37 /* This file was contributed by Ei-ji Nakama.
38  * See also the comments in src/main/rlocale.c.
39  */
40 
41 #ifndef R_LOCALE_H
42 #define R_LOCALE_H
43 
44 #ifndef NO_C_HEADERS
45 #include <wchar.h>
46 #include <ctype.h>
47 #include <wctype.h>
48 #endif
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 extern const char *locale2charset(const char *);
55 
56 /*
57  * Windows CJK
58  * In Unicode, there is not a rule about character width.
59  * A letter of breadth is used in a CJK (China, Japan, Korea,
60  * Taiwan, Hong Kong, and Singapore) area, and there are a
61  * letter and a standard (character width is not still prescribed)
62  * of a cord in a country.
63  * Letter width is a problem of a font, but it is a rule route
64  * besides a alphanumeric character that use a breadth letter.
65  * It is generally defined as a breadth letter for a font such
66  * as Japanese.
67  * - Win32
68 
69  * Attempted explanation by BDR
70  * The display widths of characters are not prescribed in Unicode.
71  * Double-width characters are used in the CJK area: their width can
72  * be font-specific, with different fonts in use in different parts
73  * of the CJK area. The tables supplied in many OSes and by Marcus
74  * Kuhn are not do not take the exact locale into account. The
75  * tables supplied in rlocale_data.h allow different widths for
76  * different parts of the CJK area, and also where needed different
77  * widths on Windows. (The Windows differences are in zh_CN, and
78  * apply to European characters.)
79  *
80  */
81 extern int Ri18n_wcwidth(wchar_t);
82 extern int Ri18n_wcswidth (const wchar_t *, size_t);
83 
84 /* Mac OSX CJK and WindowXP(Japanese)
85  * iswctypes of MacOSX calls isctypes. no i18n.
86  * For example, iswprint of Windows does not accept a macron of
87  * Japanese "a-ru" of R as a letter.
88  * Therefore Japanese "Buraian.Ripuri-" of "Brian Ripley" is
89  * shown of hex-string.:-)
90  * We define alternatives to be used if
91  * defined(Win32) || defined(__APPLE_CC__) || defined(_AIX)
92  */
93 extern wctype_t Ri18n_wctype(const char *);
94 extern int Ri18n_iswctype(wint_t, wctype_t);
95 
96 #ifndef IN_RLOCALE_C
97 /* We want to avoid these redefinitions in rlocale.c itself */
98 #undef iswupper
99 #undef iswlower
100 #undef iswalpha
101 #undef iswdigit
102 #undef iswxdigit
103 #undef iswspace
104 #undef iswprint
105 #undef iswgraph
106 #undef iswblank
107 #undef iswcntrl
108 #undef iswpunct
109 #undef iswalnum
110 #undef wctype
111 #undef iswctype
112 
113 #define iswupper(__x) Ri18n_iswctype(__x, Ri18n_wctype("upper"))
114 #define iswlower(__x) Ri18n_iswctype(__x, Ri18n_wctype("lower"))
115 #define iswalpha(__x) Ri18n_iswctype(__x, Ri18n_wctype("alpha"))
116 #define iswdigit(__x) Ri18n_iswctype(__x, Ri18n_wctype("digit"))
117 #define iswxdigit(__x) Ri18n_iswctype(__x, Ri18n_wctype("xdigit"))
118 #define iswspace(__x) Ri18n_iswctype(__x, Ri18n_wctype("space"))
119 #define iswprint(__x) Ri18n_iswctype(__x, Ri18n_wctype("print"))
120 #define iswgraph(__x) Ri18n_iswctype(__x, Ri18n_wctype("graph"))
121 #define iswblank(__x) Ri18n_iswctype(__x, Ri18n_wctype("blank"))
122 #define iswcntrl(__x) Ri18n_iswctype(__x, Ri18n_wctype("cntrl"))
123 #define iswpunct(__x) Ri18n_iswctype(__x, Ri18n_wctype("punct"))
124 #define iswalnum(__x) Ri18n_iswctype(__x, Ri18n_wctype("alnum"))
125 #define wctype(__x) Ri18n_wctype(__x)
126 #define iswctype(__x,__y) Ri18n_iswctype(__x,__y)
127 #endif
128 
129 #ifdef __cplusplus
130 }
131 #endif
132 #endif /* R_LOCALE_H */