1 /* 2 * Copyright 2010-2011, Oliver Tappe, zooey@hirschkaefer.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _LOCALE_BACKEND_H 6 #define _LOCALE_BACKEND_H 7 8 9 #include <SupportDefs.h> 10 11 #include <time.h> 12 #include <wctype.h> 13 14 15 struct lconv; 16 struct lc_time_t; 17 struct locale_data; // glibc 18 19 20 namespace BPrivate { 21 namespace Libroot { 22 23 24 struct LocaleCtypeDataBridge { 25 const unsigned short** addrOfClassInfoTable; 26 const int** addrOfToLowerTable; 27 const int** addrOfToUpperTable; 28 29 const unsigned short* posixClassInfo; 30 const int* posixToLowerMap; 31 const int* posixToUpperMap; 32 33 LocaleCtypeDataBridge(); 34 35 void setMbCurMax(unsigned short mbCurMax); 36 }; 37 38 39 struct LocaleMessagesDataBridge { 40 const char** posixLanginfo; 41 42 LocaleMessagesDataBridge(); 43 }; 44 45 46 struct LocaleMonetaryDataBridge { 47 const struct lconv* posixLocaleConv; 48 49 LocaleMonetaryDataBridge(); 50 }; 51 52 53 struct LocaleNumericDataBridge { 54 private: 55 // struct used by glibc to store numeric locale data 56 struct GlibcNumericLocale { 57 const char* name; 58 const char* filedata; 59 off_t filesize; 60 int mmaped; 61 unsigned int usage_count; 62 int use_translit; 63 const char *options; 64 unsigned int nstrings; 65 union locale_data_value 66 { 67 const uint32_t* wstr; 68 const char* string; 69 unsigned int word; 70 } 71 values[6]; 72 }; 73 locale_data* originalGlibcLocale; 74 75 public: 76 const struct lconv* posixLocaleConv; 77 GlibcNumericLocale glibcNumericLocale; 78 79 LocaleNumericDataBridge(); 80 ~LocaleNumericDataBridge(); 81 }; 82 83 84 struct LocaleTimeDataBridge { 85 const struct lc_time_t* posixLCTimeInfo; 86 87 LocaleTimeDataBridge(); 88 }; 89 90 91 struct TimeConversionDataBridge { 92 int* addrOfDaylight; 93 long* addrOfTimezone; 94 char** addrOfTZName; 95 96 TimeConversionDataBridge(); 97 }; 98 99 100 struct LocaleDataBridge { 101 LocaleCtypeDataBridge ctypeDataBridge; 102 LocaleMessagesDataBridge messagesDataBridge; 103 LocaleMonetaryDataBridge monetaryDataBridge; 104 LocaleNumericDataBridge numericDataBridge; 105 LocaleTimeDataBridge timeDataBridge; 106 TimeConversionDataBridge timeConversionDataBridge; 107 const char** posixLanginfo; 108 109 LocaleDataBridge(); 110 }; 111 112 113 class LocaleBackend { 114 public: 115 LocaleBackend(); 116 virtual ~LocaleBackend(); 117 118 virtual const char* SetLocale(int category, const char* locale) = 0; 119 virtual const struct lconv* LocaleConv() = 0; 120 virtual const struct lc_time_t* LCTimeInfo() = 0; 121 122 virtual int IsWCType(wint_t wc, wctype_t charClass) = 0; 123 virtual status_t ToWCTrans(wint_t wc, wctrans_t transition, 124 wint_t& result) = 0; 125 126 virtual status_t MultibyteToWchar(wchar_t* wcOut, const char* mb, 127 size_t mbLength, mbstate_t* mbState, 128 size_t& lengthOut) = 0; 129 virtual status_t MultibyteStringToWchar(wchar_t* wcDest, 130 size_t wcDestLength, const char** mbSource, 131 size_t mbSourceLength, mbstate_t* mbState, 132 size_t& lengthOut) = 0; 133 virtual status_t WcharToMultibyte(char* mbOut, wchar_t wc, 134 mbstate_t* mbState, size_t& lengthOut) = 0; 135 virtual status_t WcharStringToMultibyte(char* mbDest, 136 size_t mbDestLength, 137 const wchar_t** wcSource, 138 size_t wcSourceLength, mbstate_t* mbState, 139 size_t& lengthOut) = 0; 140 141 virtual const char* GetLanginfo(int index) = 0; 142 143 virtual status_t Strcoll(const char* a, const char* b, 144 int& out) = 0; 145 virtual status_t Strxfrm(char* out, const char* in, size_t size, 146 size_t& outSize) = 0; 147 virtual status_t Wcscoll(const wchar_t* a, const wchar_t* b, 148 int& out) = 0; 149 virtual status_t Wcsxfrm(wchar_t* out, const wchar_t* in, 150 size_t outSize, size_t& requiredSize) = 0; 151 152 virtual status_t TZSet(const char* timeZoneID, 153 const char* tz) = 0; 154 virtual status_t Localtime(const time_t* inTime, 155 struct tm* tmOut) = 0; 156 virtual status_t Gmtime(const time_t* inTime, 157 struct tm* tmOut) = 0; 158 virtual status_t Mktime(struct tm* inOutTm, time_t& timeOut) = 0; 159 160 virtual status_t Timegm(struct tm* inOutTm, time_t& timeOut) = 0; 161 162 virtual void Initialize(LocaleDataBridge* dataBridge) = 0; 163 164 static status_t LoadBackend(); 165 }; 166 167 168 extern LocaleBackend* gLocaleBackend; 169 170 171 } // namespace Libroot 172 } // namespace BPrivate 173 174 175 #endif // _LOCALE_BACKEND_H 176