2010-07-24 03:13:00 +04:00
|
|
|
/*
|
2011-11-23 22:55:34 +04:00
|
|
|
* Copyright 2010-2011, Oliver Tappe, zooey@hirschkaefer.de.
|
2010-07-24 03:13:00 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef _LOCALE_BACKEND_H
|
|
|
|
#define _LOCALE_BACKEND_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <SupportDefs.h>
|
|
|
|
|
2010-08-17 01:14:23 +04:00
|
|
|
#include <time.h>
|
2010-07-24 03:13:00 +04:00
|
|
|
#include <wctype.h>
|
|
|
|
|
|
|
|
|
|
|
|
struct lconv;
|
|
|
|
struct lc_time_t;
|
2010-09-12 21:24:38 +04:00
|
|
|
struct locale_data; // glibc
|
2010-07-24 03:13:00 +04:00
|
|
|
|
|
|
|
|
|
|
|
namespace BPrivate {
|
2010-11-22 16:06:36 +03:00
|
|
|
namespace Libroot {
|
2010-07-24 03:13:00 +04:00
|
|
|
|
|
|
|
|
|
|
|
struct LocaleCtypeDataBridge {
|
|
|
|
const unsigned short** addrOfClassInfoTable;
|
|
|
|
const int** addrOfToLowerTable;
|
|
|
|
const int** addrOfToUpperTable;
|
|
|
|
|
|
|
|
const unsigned short* posixClassInfo;
|
|
|
|
const int* posixToLowerMap;
|
|
|
|
const int* posixToUpperMap;
|
|
|
|
|
|
|
|
LocaleCtypeDataBridge();
|
2011-11-22 20:32:39 +04:00
|
|
|
|
|
|
|
void setMbCurMax(unsigned short mbCurMax);
|
2010-07-24 03:13:00 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct LocaleMessagesDataBridge {
|
|
|
|
const char** posixLanginfo;
|
|
|
|
|
|
|
|
LocaleMessagesDataBridge();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct LocaleMonetaryDataBridge {
|
|
|
|
const struct lconv* posixLocaleConv;
|
|
|
|
|
|
|
|
LocaleMonetaryDataBridge();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct LocaleNumericDataBridge {
|
2010-09-12 21:24:38 +04:00
|
|
|
private:
|
|
|
|
// struct used by glibc to store numeric locale data
|
|
|
|
struct GlibcNumericLocale {
|
|
|
|
const char* name;
|
|
|
|
const char* filedata;
|
|
|
|
off_t filesize;
|
|
|
|
int mmaped;
|
|
|
|
unsigned int usage_count;
|
|
|
|
int use_translit;
|
|
|
|
const char *options;
|
|
|
|
unsigned int nstrings;
|
|
|
|
union locale_data_value
|
|
|
|
{
|
|
|
|
const uint32_t* wstr;
|
|
|
|
const char* string;
|
|
|
|
unsigned int word;
|
|
|
|
}
|
|
|
|
values[6];
|
|
|
|
};
|
|
|
|
locale_data* originalGlibcLocale;
|
|
|
|
|
|
|
|
public:
|
2010-07-24 03:13:00 +04:00
|
|
|
const struct lconv* posixLocaleConv;
|
2010-09-12 21:24:38 +04:00
|
|
|
GlibcNumericLocale glibcNumericLocale;
|
2010-07-24 03:13:00 +04:00
|
|
|
|
|
|
|
LocaleNumericDataBridge();
|
2010-09-12 21:24:38 +04:00
|
|
|
~LocaleNumericDataBridge();
|
2010-07-24 03:13:00 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct LocaleTimeDataBridge {
|
|
|
|
const struct lc_time_t* posixLCTimeInfo;
|
|
|
|
|
|
|
|
LocaleTimeDataBridge();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-08-17 01:14:23 +04:00
|
|
|
struct TimeConversionDataBridge {
|
|
|
|
int* addrOfDaylight;
|
|
|
|
long* addrOfTimezone;
|
|
|
|
char** addrOfTZName;
|
|
|
|
|
|
|
|
TimeConversionDataBridge();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-07-24 03:13:00 +04:00
|
|
|
struct LocaleDataBridge {
|
|
|
|
LocaleCtypeDataBridge ctypeDataBridge;
|
|
|
|
LocaleMessagesDataBridge messagesDataBridge;
|
|
|
|
LocaleMonetaryDataBridge monetaryDataBridge;
|
|
|
|
LocaleNumericDataBridge numericDataBridge;
|
|
|
|
LocaleTimeDataBridge timeDataBridge;
|
2010-08-17 01:14:23 +04:00
|
|
|
TimeConversionDataBridge timeConversionDataBridge;
|
2010-07-24 03:13:00 +04:00
|
|
|
const char** posixLanginfo;
|
|
|
|
|
|
|
|
LocaleDataBridge();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class LocaleBackend {
|
|
|
|
public:
|
|
|
|
LocaleBackend();
|
|
|
|
virtual ~LocaleBackend();
|
|
|
|
|
|
|
|
virtual const char* SetLocale(int category, const char* locale) = 0;
|
|
|
|
virtual const struct lconv* LocaleConv() = 0;
|
|
|
|
virtual const struct lc_time_t* LCTimeInfo() = 0;
|
|
|
|
|
|
|
|
virtual int IsWCType(wint_t wc, wctype_t charClass) = 0;
|
|
|
|
virtual status_t ToWCTrans(wint_t wc, wctrans_t transition,
|
|
|
|
wint_t& result) = 0;
|
|
|
|
|
2011-11-22 21:17:58 +04:00
|
|
|
virtual status_t MultibyteToWchar(wchar_t* wcOut, const char* mb,
|
|
|
|
size_t mbLength, mbstate_t* mbState,
|
|
|
|
size_t& lengthOut) = 0;
|
2011-12-07 21:20:34 +04:00
|
|
|
virtual status_t MultibyteStringToWchar(wchar_t* wcDest,
|
|
|
|
size_t wcDestLength, const char** mbSource,
|
|
|
|
size_t mbSourceLength, mbstate_t* mbState,
|
|
|
|
size_t& lengthOut) = 0;
|
2011-11-22 21:17:58 +04:00
|
|
|
virtual status_t WcharToMultibyte(char* mbOut, wchar_t wc,
|
|
|
|
mbstate_t* mbState, size_t& lengthOut) = 0;
|
2011-12-12 15:18:16 +04:00
|
|
|
virtual status_t WcharStringToMultibyte(char* mbDest,
|
|
|
|
size_t mbDestLength,
|
|
|
|
const wchar_t** wcSource,
|
|
|
|
size_t wcSourceLength, mbstate_t* mbState,
|
|
|
|
size_t& lengthOut) = 0;
|
2011-11-22 21:17:58 +04:00
|
|
|
|
2010-07-24 03:13:00 +04:00
|
|
|
virtual const char* GetLanginfo(int index) = 0;
|
|
|
|
|
|
|
|
virtual status_t Strcoll(const char* a, const char* b,
|
|
|
|
int& out) = 0;
|
|
|
|
virtual status_t Strxfrm(char* out, const char* in, size_t size,
|
|
|
|
size_t& outSize) = 0;
|
2012-01-08 00:47:31 +04:00
|
|
|
virtual status_t Wcscoll(const wchar_t* a, const wchar_t* b,
|
|
|
|
int& out) = 0;
|
|
|
|
virtual status_t Wcsxfrm(wchar_t* out, const wchar_t* in,
|
|
|
|
size_t size, size_t& outSize) = 0;
|
2010-07-24 03:13:00 +04:00
|
|
|
|
2010-11-13 04:13:38 +03:00
|
|
|
virtual status_t TZSet(const char* timeZoneID,
|
|
|
|
const char* tz) = 0;
|
2010-08-17 01:14:23 +04:00
|
|
|
virtual status_t Localtime(const time_t* inTime,
|
|
|
|
struct tm* tmOut) = 0;
|
|
|
|
virtual status_t Gmtime(const time_t* inTime,
|
|
|
|
struct tm* tmOut) = 0;
|
|
|
|
virtual status_t Mktime(struct tm* inOutTm, time_t& timeOut) = 0;
|
|
|
|
|
2010-07-24 03:13:00 +04:00
|
|
|
virtual void Initialize(LocaleDataBridge* dataBridge) = 0;
|
|
|
|
|
|
|
|
static status_t LoadBackend();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
extern LocaleBackend* gLocaleBackend;
|
|
|
|
|
|
|
|
|
2010-11-22 16:06:36 +03:00
|
|
|
} // namespace Libroot
|
2010-07-24 03:13:00 +04:00
|
|
|
} // namespace BPrivate
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _LOCALE_BACKEND_H
|