* reintegrated posix-locale

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37725 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe
2010-07-23 23:13:00 +00:00
parent b891b0acae
commit a3f665982e
297 changed files with 5900 additions and 46769 deletions
@@ -0,0 +1,53 @@
/*
* Copyright 2010, Oliver Tappe, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef _ICU_CATEGORY_DATA_H
#define _ICU_CATEGORY_DATA_H
#include <unicode/locid.h>
#include <unicode/ucnv.h>
#include <unicode/unistr.h>
#include <SupportDefs.h>
namespace BPrivate {
class ICUCategoryData {
public:
ICUCategoryData();
virtual ~ICUCategoryData();
virtual status_t SetTo(const Locale& locale,
const char* posixLocaleName);
virtual status_t SetToPosix();
const char * PosixLocaleName()
{ return fPosixLocaleName; }
protected:
status_t _ConvertUnicodeStringToLocaleconvEntry(
const UnicodeString& string,
char* destination, int destinationSize,
const char* defaultValue = "");
static const uint16 skMaxPosixLocaleNameLen = 128;
static const size_t skLCBufSize = 16;
Locale fLocale;
UConverter* fConverter;
char fPosixLocaleName[skMaxPosixLocaleNameLen];
char fGivenCharset[UCNV_MAX_CONVERTER_NAME_LENGTH];
private:
status_t _SetupConverter();
};
} // namespace BPrivate
#endif // _ICU_CATEGORY_DATA_H
@@ -0,0 +1,43 @@
/*
* Copyright 2010, Oliver Tappe, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef _ICU_COLLATE_DATA_H
#define _ICU_COLLATE_DATA_H
#include "ICUCategoryData.h"
#include <unicode/coll.h>
namespace BPrivate {
class ICUCollateData : public ICUCategoryData {
typedef ICUCategoryData inherited;
public:
ICUCollateData();
virtual ~ICUCollateData();
virtual status_t SetTo(const Locale& locale,
const char* posixLocaleName);
virtual status_t SetToPosix();
status_t Strcoll(const char* a, const char* b, int& out);
status_t Strxfrm(char* out, const char* in, size_t size,
size_t& outSize);
private:
status_t _ToUnicodeString(const char* in,
UnicodeString& out);
Collator* fCollator;
};
} // namespace BPrivate
#endif // _ICU_COLLATE_DATA_H
@@ -0,0 +1,46 @@
/*
* Copyright 2010, Oliver Tappe, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef _ICU_CTYPE_DATA_H
#define _ICU_CTYPE_DATA_H
#include "ICUCategoryData.h"
#include "LocaleBackend.h"
namespace BPrivate {
class ICUCtypeData : public ICUCategoryData {
typedef ICUCategoryData inherited;
public:
ICUCtypeData();
virtual ~ICUCtypeData();
void Initialize(LocaleCtypeDataBridge* dataBridge);
virtual status_t SetTo(const Locale& locale,
const char* posixLocaleName);
virtual status_t SetToPosix();
int IsWCType(wint_t wc, wctype_t charClass);
status_t ToWCTrans(wint_t wc, wctrans_t transition,
wint_t& result);
const char* GetLanginfo(int index);
private:
unsigned short fClassInfo[256];
int fToLowerMap[256];
int fToUpperMap[256];
LocaleCtypeDataBridge* fDataBridge;
};
} // namespace BPrivate
#endif // _ICU_CTYPE_DATA_H
@@ -0,0 +1,74 @@
/*
* Copyright 2010, Oliver Tappe, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef _ICU_LOCALE_BACKEND_H
#define _ICU_LOCALE_BACKEND_H
#include "LocaleBackend.h"
#include <locale.h>
#include <timelocal.h>
#include "ICUCollateData.h"
#include "ICUCtypeData.h"
#include "ICUMessagesData.h"
#include "ICUMonetaryData.h"
#include "ICUNumericData.h"
#include "ICUTimeData.h"
namespace BPrivate {
class ICULocaleBackend : public LocaleBackend {
public:
ICULocaleBackend();
virtual ~ICULocaleBackend();
virtual void Initialize(LocaleDataBridge* dataBridge);
virtual const char* SetLocale(int category,
const char* posixLocaleName);
virtual const struct lconv* LocaleConv();
virtual const struct lc_time_t* LCTimeInfo();
virtual int IsWCType(wint_t wc, wctype_t charClass);
virtual status_t ToWCTrans(wint_t wc, wctrans_t transition,
wint_t& result);
virtual const char* GetLanginfo(int index);
virtual status_t Strcoll(const char* a, const char* b, int& out);
virtual status_t Strxfrm(char* out, const char* in, size_t size,
size_t& outSize);
private:
const char* _QueryLocale(int category);
const char* _SetPosixLocale(int category);
// buffer for locale names (up to one per category)
char fLocaleDescription[512];
// data containers
struct lconv fLocaleConv;
struct lc_time_t fLCTimeInfo;
// these work on the data containers above
ICUCollateData fCollateData;
ICUCtypeData fCtypeData;
ICUMessagesData fMessagesData;
ICUMonetaryData fMonetaryData;
ICUNumericData fNumericData;
ICUTimeData fTimeData;
// static posix langinfo data
const char** fPosixLanginfo;
};
} // namespace BPrivate
#endif // _ICU_LOCALE_BACKEND_H
@@ -0,0 +1,33 @@
/*
* Copyright 2010, Oliver Tappe, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef _ICU_LOCALECONV_DATA_H
#define _ICU_LOCALECONV_DATA_H
#include "ICUCategoryData.h"
#include <unicode/decimfmt.h>
namespace BPrivate {
typedef DecimalFormatSymbols::ENumberFormatSymbol FormatSymbol;
class ICULocaleconvData : public ICUCategoryData {
typedef ICUCategoryData inherited;
protected:
status_t _SetLocaleconvEntry(
const DecimalFormatSymbols* formatSymbols,
char* destination, FormatSymbol symbol,
const char* defaultValue = "");
};
} // namespace BPrivate
#endif // _ICU_LOCALECONV_DATA_H
@@ -0,0 +1,39 @@
/*
* Copyright 2010, Oliver Tappe, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef _ICU_MESSAGES_DATA_H
#define _ICU_MESSAGES_DATA_H
#include "ICUCategoryData.h"
#include "LocaleBackend.h"
namespace BPrivate {
class ICUMessagesData : public ICUCategoryData {
typedef ICUCategoryData inherited;
public:
virtual status_t SetTo(const Locale& locale,
const char* posixLocaleName);
virtual status_t SetToPosix();
void Initialize(
LocaleMessagesDataBridge* dataBridge);
const char* GetLanginfo(int index);
private:
char fYesExpression[80];
char fNoExpression[80];
const char** fPosixLanginfo;
};
} // namespace BPrivate
#endif // _ICU_MESSAGES_DATA_H
@@ -0,0 +1,69 @@
/*
* Copyright 2010, Oliver Tappe, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef _ICU_MONETARY_DATA_H
#define _ICU_MONETARY_DATA_H
#include "ICULocaleconvData.h"
#include "LocaleBackend.h"
#include <locale.h>
namespace BPrivate {
class ICUMonetaryData : public ICULocaleconvData {
typedef ICULocaleconvData inherited;
public:
static const int32 kParenthesesAroundCurrencyAndValue = 0;
static const int32 kSignPrecedesCurrencyAndValue = 1;
static const int32 kSignSucceedsCurrencyAndValue = 2;
static const int32 kSignImmediatelyPrecedesCurrency = 3;
static const int32 kSignImmediatelySucceedsCurrency = 4;
ICUMonetaryData(struct lconv& localeConv);
void Initialize(
LocaleMonetaryDataBridge* dataBridge);
virtual status_t SetTo(const Locale& locale,
const char* posixLocaleName);
virtual status_t SetToPosix();
const char* GetLanginfo(int index);
private:
static const int32 kCsPrecedesFlag = 1 << 0;
static const int32 kSepBySpaceFlag = 1 << 1;
int32 _DetermineCurrencyPosAndSeparator(
const UnicodeString& prefix,
const UnicodeString& suffix,
const UnicodeString& signSymbol,
const UnicodeString& currencySymbol,
UChar& currencySeparatorChar);
int32 _DetermineSignPos(const UnicodeString& prefix,
const UnicodeString& suffix,
const UnicodeString& signSymbol,
const UnicodeString& currencySymbol);
char fDecimalPoint[skLCBufSize];
char fThousandsSep[skLCBufSize];
char fGrouping[skLCBufSize];
char fIntCurrSymbol[skLCBufSize];
char fCurrencySymbol[skLCBufSize];
char fPositiveSign[skLCBufSize];
char fNegativeSign[skLCBufSize];
struct lconv& fLocaleConv;
const struct lconv* fPosixLocaleConv;
};
} // namespace BPrivate
#endif // _ICU_MONETARY_DATA_H
@@ -0,0 +1,43 @@
/*
* Copyright 2010, Oliver Tappe, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef _ICU_NUMERIC_DATA_H
#define _ICU_NUMERIC_DATA_H
#include "ICULocaleconvData.h"
#include "LocaleBackend.h"
namespace BPrivate {
class ICUNumericData : public ICULocaleconvData {
typedef ICULocaleconvData inherited;
public:
ICUNumericData(struct lconv& localeConv);
void Initialize(LocaleNumericDataBridge* dataBridge);
virtual status_t SetTo(const Locale& locale,
const char* posixLocaleName);
virtual status_t SetToPosix();
virtual const char* GetLanginfo(int index);
private:
char fDecimalPoint[skLCBufSize];
char fThousandsSep[skLCBufSize];
char fGrouping[skLCBufSize];
struct lconv& fLocaleConv;
LocaleNumericDataBridge* fDataBridge;
};
} // namespace BPrivate
#endif // _ICU_NUMERIC_DATA_H
@@ -0,0 +1,62 @@
/*
* Copyright 2010, Oliver Tappe, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef _ICU_TIME_DATA_H
#define _ICU_TIME_DATA_H
#include "ICUCategoryData.h"
#include "LocaleBackend.h"
#include <unicode/datefmt.h>
#include <timelocal.h>
namespace BPrivate {
class ICUTimeData : public ICUCategoryData {
typedef ICUCategoryData inherited;
public:
ICUTimeData(struct lc_time_t& lcTimeInfo);
void Initialize(LocaleTimeDataBridge* dataBridge);
virtual status_t SetTo(const Locale& locale,
const char* posixLocaleName);
virtual status_t SetToPosix();
const char* GetLanginfo(int index);
private:
status_t _SetLCTimeEntries(const UnicodeString* strings,
char* destination, int entrySize,
int count, int maxCount);
status_t _SetLCTimePattern(DateFormat* format,
char* destination, int destinationSize);
char fMon[12][24];
char fMonth[12][64];
char fWday[7][24];
char fWeekday[7][64];
char fTimeFormat[24];
char fDateFormat[24];
char fDateTimeFormat[32];
char fAm[24];
char fPm[24];
char fDateTimeZoneFormat[32];
char fAltMonth[12][64];
char fMonthDayOrder[4];
char fAmPmFormat[32];
struct lc_time_t& fLCTimeInfo;
const struct lc_time_t* fPosixLCTimeInfo;
};
} // namespace BPrivate
#endif // _ICU_TIME_DATA_H
@@ -0,0 +1,111 @@
/*
* Copyright 2010, Oliver Tappe, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef _LOCALE_BACKEND_H
#define _LOCALE_BACKEND_H
#include <SupportDefs.h>
#include <wctype.h>
struct lconv;
struct lc_time_t;
namespace BPrivate {
struct LocaleCtypeDataBridge {
const unsigned short** addrOfClassInfoTable;
const int** addrOfToLowerTable;
const int** addrOfToUpperTable;
const unsigned short* posixClassInfo;
const int* posixToLowerMap;
const int* posixToUpperMap;
LocaleCtypeDataBridge();
};
struct LocaleMessagesDataBridge {
const char** posixLanginfo;
LocaleMessagesDataBridge();
};
struct LocaleMonetaryDataBridge {
const struct lconv* posixLocaleConv;
LocaleMonetaryDataBridge();
};
struct LocaleNumericDataBridge {
const char** addrOfGlibcDecimalPoint;
const char** addrOfGlibcThousandsSep;
const char** addrOfGlibcGrouping;
uint32_t* addrOfGlibcWCDecimalPoint;
uint32_t* addrOfGlibcWCThousandsSep;
const struct lconv* posixLocaleConv;
LocaleNumericDataBridge();
};
struct LocaleTimeDataBridge {
const struct lc_time_t* posixLCTimeInfo;
LocaleTimeDataBridge();
};
struct LocaleDataBridge {
LocaleCtypeDataBridge ctypeDataBridge;
LocaleMessagesDataBridge messagesDataBridge;
LocaleMonetaryDataBridge monetaryDataBridge;
LocaleNumericDataBridge numericDataBridge;
LocaleTimeDataBridge timeDataBridge;
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;
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;
virtual void Initialize(LocaleDataBridge* dataBridge) = 0;
static status_t LoadBackend();
};
extern LocaleBackend* gLocaleBackend;
} // namespace BPrivate
#endif // _LOCALE_BACKEND_H
@@ -0,0 +1,20 @@
/*
* Copyright 2010, Oliver Tappe, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef _POSIX_CTYPE_H
#define _POSIX_CTYPE_H
namespace BPrivate {
extern const unsigned short gPosixClassInfo[256];
extern const int gPosixToLowerMap[256];
extern const int gPosixToUpperMap[256];
} // namespace BPrivate
#endif // _POSIX_CTYPE_H
@@ -0,0 +1,18 @@
/*
* Copyright 2010, Oliver Tappe, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef _POSIX_LANGINFO_H
#define _POSIX_LANGINFO_H
namespace BPrivate {
extern const char* gPosixLanginfo[];
} // namespace BPrivate
#endif // _POSIX_LANGINFO_H
@@ -0,0 +1,21 @@
/*
* Copyright 2010, Oliver Tappe, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef _POSIX_LOCALE_CONV_H
#define _POSIX_LOCALE_CONV_H
#include <locale.h>
namespace BPrivate {
extern struct lconv gPosixLocaleConv;
} // namespace BPrivate
#endif // _POSIX_LOCALE_CONV_H
@@ -0,0 +1,21 @@
/*
* Copyright 2010, Oliver Tappe, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef _POSIX_LC_TIME_INFO_H
#define _POSIX_LC_TIME_INFO_H
#include <timelocal.h>
namespace BPrivate {
extern const struct lc_time_t gPosixLCTimeInfo;
} // namespace BPrivate
#endif // _POSIX_LC_TIME_INFO_H
+60
View File
@@ -0,0 +1,60 @@
/*-
* Copyright (c) 1997-2002 FreeBSD Project.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD: /repoman/r/ncvs/src/lib/libc/stdtime/timelocal.h,v 1.11 2002/01/24 15:07:44 phantom Exp $
*/
#ifndef _TIMELOCAL_H_
#define _TIMELOCAL_H_
#include <sys/cdefs.h>
/*
* Private header file for the strftime and strptime localization
* stuff.
*/
struct lc_time_t {
const char* mon[12];
const char* month[12];
const char* wday[7];
const char* weekday[7];
const char* X_fmt;
const char* x_fmt;
const char* c_fmt;
const char* am;
const char* pm;
const char* date_fmt;
const char* alt_month[12];
const char* md_order;
const char* ampm_fmt;
};
__BEGIN_DECLS
const struct lc_time_t* __get_current_time_locale(void);
__END_DECLS
#endif /* !_TIMELOCAL_H_ */