xref: /haiku/headers/private/libroot/locale/ICUCategoryData.h (revision 21258e2674226d6aa732321b6f8494841895af5f)
1 /*
2  * Copyright 2010-2011, Oliver Tappe, zooey@hirschkaefer.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _ICU_CATEGORY_DATA_H
6 #define _ICU_CATEGORY_DATA_H
7 
8 #include <pthread.h>
9 
10 #include <unicode/locid.h>
11 #include <unicode/unistr.h>
12 
13 #include <SupportDefs.h>
14 
15 #include "ICUThreadLocalStorageValue.h"
16 
17 
18 namespace BPrivate {
19 namespace Libroot {
20 
21 
22 class ICUCategoryData {
23 public:
24 								ICUCategoryData(pthread_key_t tlsKey);
25 	virtual 					~ICUCategoryData();
26 
27 	virtual	status_t			SetTo(const U_NAMESPACE_QUALIFIER Locale&
28 										locale,
29 									const char* posixLocaleName);
30 	virtual	status_t			SetToPosix();
31 
32 			const char*			PosixLocaleName()
33 									{ return fPosixLocaleName; }
34 
35 			const U_NAMESPACE_QUALIFIER Locale&	ICULocale() const;
36 
37 protected:
38 			status_t			_ConvertUnicodeStringToLocaleconvEntry(
39 									const U_NAMESPACE_QUALIFIER UnicodeString&
40 										string,
41 									char* destination, int destinationSize,
42 									const char* defaultValue = "");
43 
44 			status_t			_GetConverter(UConverter*& converterOut);
45 
46 	static	const uint16		skMaxPosixLocaleNameLen = 128;
47 	static	const size_t		skLCBufSize = 16;
48 
49 			pthread_key_t		fThreadLocalStorageKey;
50 			U_NAMESPACE_QUALIFIER Locale	fLocale;
51 			char				fPosixLocaleName[skMaxPosixLocaleNameLen];
52 			char				fGivenCharset[UCNV_MAX_CONVERTER_NAME_LENGTH];
53 
54 private:
55  			status_t			_SetupConverter();
56 };
57 
58 
59 inline
60 const U_NAMESPACE_QUALIFIER Locale&
61 ICUCategoryData::ICULocale() const
62 {
63 	return fLocale;
64 }
65 
66 
67 }	// namespace Libroot
68 }	// namespace BPrivate
69 
70 
71 #endif	// _ICU_CATEGORY_DATA_H
72