xref: /haiku/headers/private/libroot/locale/ICUCtypeData.h (revision 1bad1ff34a3e132a8816d2ac7ba9722d3a5249a9)
1 /*
2  * Copyright 2010-2011, Oliver Tappe, zooey@hirschkaefer.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _ICU_CTYPE_DATA_H
6 #define _ICU_CTYPE_DATA_H
7 
8 
9 #include "ICUCategoryData.h"
10 #include "LocaleBackend.h"
11 
12 
13 namespace BPrivate {
14 namespace Libroot {
15 
16 
17 class ICUCtypeData : public ICUCategoryData {
18 	typedef	ICUCategoryData		inherited;
19 public:
20 								ICUCtypeData(pthread_key_t tlsKey);
21 	virtual 					~ICUCtypeData();
22 
23 			void				Initialize(LocaleCtypeDataBridge* dataBridge);
24 
25 	virtual	status_t			SetTo(const U_NAMESPACE_QUALIFIER Locale&
26 										locale,
27 									const char* posixLocaleName);
28 	virtual	status_t			SetToPosix();
29 
30 			int					IsWCType(wint_t wc, wctype_t charClass);
31 			status_t			ToWCTrans(wint_t wc, wctrans_t transition,
32 									wint_t& result);
33 
34 			status_t			MultibyteToWchar(wchar_t* wcOut, const char* mb,
35 									size_t mbLength, mbstate_t* mbState,
36 									size_t& lengthOut);
37 			status_t			MultibyteStringToWchar(wchar_t* wcDest,
38 									size_t wcDestLength, const char** mbSource,
39 									size_t mbSourceLength, mbstate_t* mbState,
40 									size_t& lengthOut);
41 			status_t			WcharToMultibyte(char* mbOut, wchar_t wc,
42 									mbstate_t* mbState, size_t& lengthOut);
43 			status_t			WcharStringToMultibyte(char* mbDest,
44 									size_t mbDestLength,
45 									const wchar_t** wcSource,
46 									size_t wcSourceLength, mbstate_t* mbState,
47 									size_t& lengthOut);
48 
49 			const char*			GetLanginfo(int index);
50 
51 private:
52 			status_t			_GetConverterForMbState(mbstate_t* mbState,
53 									UConverter*& converterOut);
54 
55 			status_t			_DropConverterFromMbState(mbstate_t* mbState);
56 
57 			/*
58 			 * The following arrays have 384 elements where the elements at
59 			 * index -128..-2 mirror the elements at index 128..255 (to protect
60 			 * against invocations of ctype macros with negative character
61 			 * values).
62 			 * The element at index -1 is a dummy element containing the
63 			 * neutral/identity value used when the array is accessed as in
64 			 * 'isblank(EOF)' (i.e. with index -1).
65 			 */
66 			unsigned short		fClassInfo[384];
67 			int					fToLowerMap[384];
68 			int					fToUpperMap[384];
69 
70 			LocaleCtypeDataBridge*	fDataBridge;
71 };
72 
73 
74 }	// namespace Libroot
75 }	// namespace BPrivate
76 
77 
78 #endif	// _ICU_CTYPE_DATA_H
79