xref: /haiku/headers/private/libroot/locale/ICULocaleBackend.h (revision 7bbfd0ff4956fd50e18cfb6f6f994f3f9446d77d)
1 /*
2  * Copyright 2010-2011, Oliver Tappe, zooey@hirschkaefer.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _ICU_LOCALE_BACKEND_H
6 #define _ICU_LOCALE_BACKEND_H
7 
8 
9 #include "LocaleBackend.h"
10 
11 #include <locale.h>
12 #include <pthread.h>
13 #include <timelocal.h>
14 
15 #include "ICUCollateData.h"
16 #include "ICUCtypeData.h"
17 #include "ICUMessagesData.h"
18 #include "ICUMonetaryData.h"
19 #include "ICUNumericData.h"
20 #include "ICUTimeConversion.h"
21 #include "ICUTimeData.h"
22 
23 
24 namespace BPrivate {
25 namespace Libroot {
26 
27 
28 class ICULocaleBackend : public LocaleBackend {
29 public:
30 								ICULocaleBackend();
31 	virtual						~ICULocaleBackend();
32 
33 	virtual void				Initialize(LocaleDataBridge* dataBridge);
34 
35 	virtual	const char*			SetLocale(int category,
36 									const char* posixLocaleName);
37 	virtual	const struct lconv*	LocaleConv();
38 	virtual	const struct lc_time_t*	LCTimeInfo();
39 
40 	virtual	int					IsWCType(wint_t wc, wctype_t charClass);
41 	virtual	status_t			ToWCTrans(wint_t wc, wctrans_t transition,
42 									wint_t& result);
43 
44 	virtual status_t			MultibyteToWchar(wchar_t* wcOut, const char* mb,
45 									size_t mbLength, mbstate_t* mbState,
46 									size_t& lengthOut);
47 	virtual status_t			MultibyteStringToWchar(wchar_t* wcDest,
48 									size_t wcDestLength, const char** mbSource,
49 									size_t mbSourceLength, mbstate_t* mbState,
50 									size_t& lengthOut);
51 	virtual status_t			WcharToMultibyte(char* mbOut, wchar_t wc,
52 									mbstate_t* mbState, size_t& lengthOut);
53 	virtual status_t			WcharStringToMultibyte(char* mbDest,
54 									size_t mbDestLength,
55 									const wchar_t** wcSource,
56 									size_t wcSourceLength, mbstate_t* mbState,
57 									size_t& lengthOut);
58 
59 	virtual	const char*			GetLanginfo(int index);
60 
61 	virtual	status_t			Strcoll(const char* a, const char* b, int& out);
62 	virtual status_t			Strxfrm(char* out, const char* in, size_t size,
63 									size_t& outSize);
64 	virtual	status_t			Wcscoll(const wchar_t* a, const wchar_t* b,
65 									int& out);
66 	virtual status_t			Wcsxfrm(wchar_t* out, const wchar_t* in,
67 									size_t outSize, size_t& requiredSize);
68 
69 	virtual status_t			TZSet(const char* timeZoneID, const char* tz);
70 	virtual	status_t			Localtime(const time_t* inTime,
71 									struct tm* tmOut);
72 	virtual status_t			Gmtime(const time_t* inTime, struct tm* tmOut);
73 
74 	virtual status_t			Mktime(struct tm* inOutTm, time_t& timeOut);
75 
76 	virtual status_t			Timegm(struct tm* inOutTm, time_t& timeOut);
77 
78 private:
79 			const char*			_QueryLocale(int category);
80 			const char*			_SetPosixLocale(int category);
81 
82 	static	pthread_key_t		_CreateThreadLocalStorageKey();
83 	static	void 				_DestroyThreadLocalStorageValue(void* value);
84 
85 			// buffer for locale names (up to one per category)
86 			char				fLocaleDescription[1024];
87 
88 			// data containers
89 			struct lconv 	 	fLocaleConv;
90 			struct lc_time_t 	fLCTimeInfo;
91 
92 			//
93 			pthread_key_t		fThreadLocalStorageKey;
94 
95 			// these work on the data containers above
96 			ICUCollateData		fCollateData;
97 			ICUCtypeData		fCtypeData;
98 			ICUMessagesData		fMessagesData;
99 			ICUMonetaryData		fMonetaryData;
100 			ICUNumericData		fNumericData;
101 			ICUTimeData			fTimeData;
102 			ICUTimeConversion	fTimeConversion;
103 
104 			// static posix langinfo data
105 			const char**		fPosixLanginfo;
106 };
107 
108 
109 }	// namespace Libroot
110 }	// namespace BPrivate
111 
112 
113 #endif	// _ICU_LOCALE_BACKEND_H
114