sl@0: /* sl@0: * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: # include "stlport_prefix.h" sl@0: #include sl@0: sl@0: //madhu - 18/8/06 sl@0: #include "locale.h" sl@0: #include "langinfo.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include "c_locale.h" sl@0: #define CODECVT_ICONV //Define CODECVT_ICONV to use ICONV APIs for code conversion. sl@0: sl@0: //#define _MESSAGE_CATALOG_ sl@0: #ifdef _MESSAGE_CATALOG_ sl@0: #include sl@0: #endif sl@0: sl@0: # ifdef _STLP_REAL_LOCALE_IMPLEMENTED sl@0: sl@0: // here, we'll put C locale implementation for those compilers where sl@0: // it has to be done in C++ sl@0: sl@0: # else sl@0: sl@0: /* This is a "stub" implementation of the "c_locale.h" interface, sl@0: intended for operating systems where we have not yet written sl@0: a real implementation. A C++ library using this stub implementation sl@0: is still standard-conforming, since the C++ standard does not require sl@0: that any locales other than "C" be supported. sl@0: */ sl@0: sl@0: #if 0 //Madhu - 18/8/06 sl@0: /* Framework functions */ sl@0: sl@0: struct _Locale_ctype /* { } */ ; sl@0: struct _Locale_numeric /* { } */; sl@0: struct _Locale_time /* { } */; sl@0: struct _Locale_collate /*{ } */; sl@0: struct _Locale_monetary /* { } */; sl@0: struct _Locale_messages /* { } */; sl@0: sl@0: #endif //#if 0 sl@0: sl@0: sl@0: #ifdef CODECVT_ICONV sl@0: #include sl@0: #include sl@0: #define UNICODESTR "UCS2" sl@0: struct node; sl@0: enum CONVWAY sl@0: { sl@0: sl@0: IN = 0, sl@0: OUT sl@0: sl@0: }; sl@0: typedef struct node sl@0: { sl@0: mbstate_t *state; sl@0: iconv_t in_iconvstate; sl@0: iconv_t out_iconvstate; sl@0: struct node *next; sl@0: }StateList; sl@0: sl@0: void BEtoLE(wchar_t* src, int size) sl@0: { sl@0: int i = 0; sl@0: sl@0: for (i = 0;i>8) | (src[i]<<8); sl@0: } sl@0: sl@0: void ExtractCodeset(char* name, char* codeset) sl@0: { sl@0: char* temp = strstr(name,"."); sl@0: if( temp != NULL) sl@0: { sl@0: temp++; sl@0: while ( (*temp)&&(*temp!='=') ) sl@0: *codeset++ = *temp++; sl@0: } sl@0: } sl@0: sl@0: int AddState(StateList **list, iconv_t icnvstate, mbstate_t* state, enum CONVWAY way) sl@0: { sl@0: StateList *temp = *list; sl@0: StateList *newnode = NULL; sl@0: while(temp) sl@0: { sl@0: if (temp->state == state) sl@0: break; sl@0: temp = temp->next; sl@0: } sl@0: sl@0: if (!temp) sl@0: { sl@0: newnode = new StateList; sl@0: if (newnode == NULL) sl@0: return 0; sl@0: newnode->next = NULL; sl@0: newnode->state = state; sl@0: newnode->in_iconvstate = newnode->out_iconvstate = NULL; sl@0: } sl@0: if(newnode) sl@0: temp = newnode; sl@0: if (!way) sl@0: temp->in_iconvstate = icnvstate; sl@0: else sl@0: temp->out_iconvstate = icnvstate; sl@0: sl@0: if (*list == NULL) sl@0: { sl@0: *list = temp; sl@0: return 1; sl@0: } sl@0: else if(newnode) sl@0: { sl@0: sl@0: StateList *move = *list; sl@0: while(move->next) sl@0: move = move->next; sl@0: sl@0: move->next = temp; sl@0: } sl@0: return 1; sl@0: sl@0: } sl@0: sl@0: iconv_t GetState(StateList *list, mbstate_t* state, enum CONVWAY way) sl@0: { sl@0: while(list) sl@0: { sl@0: if (list->state == state) sl@0: { sl@0: if (!way) sl@0: return (iconv_t)list->in_iconvstate; sl@0: else sl@0: return (iconv_t)list->out_iconvstate; sl@0: } sl@0: sl@0: list = list->next; sl@0: } sl@0: return NULL; sl@0: } sl@0: sl@0: void DeleteAllStates(StateList *list) sl@0: { sl@0: while(list) sl@0: { sl@0: StateList *temp =list ; sl@0: iconv_close(temp->in_iconvstate); sl@0: iconv_close(temp->out_iconvstate); sl@0: list = list->next; sl@0: delete temp; sl@0: } sl@0: } sl@0: sl@0: sl@0: #endif sl@0: sl@0: sl@0: sl@0: //Madhu - locale function definitions - START sl@0: //Madhu - temporarily hardcoded system default locale - 18/8/06 sl@0: #define LOCALE_SYSTEM_DEFAULT "C" sl@0: #define MAX_NAME_LEN 64 sl@0: char presentLocaleName[64]; // Stores present locale name. sl@0: sl@0: sl@0: sl@0: #if defined (__GNUC__) || defined (_KCC) || defined(__ICC) sl@0: typedef unsigned short int _Locale_mask_t; sl@0: #else sl@0: typedef unsigned int _Locale_mask_t; sl@0: #endif sl@0: sl@0: typedef struct _Locale_ctype { sl@0: char name[MAX_NAME_LEN]; sl@0: _Locale_mask_t ctable[257]; sl@0: #ifdef CODECVT_ICONV sl@0: StateList *statelist; sl@0: ~_Locale_ctype() sl@0: { sl@0: DeleteAllStates(statelist); sl@0: } sl@0: #endif sl@0: sl@0: } L_ctype_t; sl@0: sl@0: sl@0: typedef struct _Locale_numeric { sl@0: char name[MAX_NAME_LEN]; sl@0: char decimal_point[4]; sl@0: char thousands_sep[4]; sl@0: char *grouping; sl@0: } L_numeric_t; sl@0: sl@0: typedef struct _Locale_time { sl@0: char name[MAX_NAME_LEN]; sl@0: char *month[12]; sl@0: char *abbrev_month[12]; sl@0: char *dayofweek[7]; sl@0: char *abbrev_dayofweek[7]; sl@0: } L_time_t; sl@0: sl@0: typedef struct _Locale_collate { sl@0: char name[MAX_NAME_LEN]; sl@0: } L_collate_t; sl@0: sl@0: typedef struct _Locale_monetary { sl@0: char name[MAX_NAME_LEN]; sl@0: char decimal_point[4]; sl@0: char thousands_sep[4]; sl@0: char *grouping; sl@0: char int_curr_symbol[5]; // 3+1+1 sl@0: char curr_symbol[6]; sl@0: char negative_sign[5]; sl@0: char positive_sign[5]; sl@0: int frac_digits; sl@0: int int_frac_digits; sl@0: } L_monetary_t; sl@0: sl@0: typedef struct _Locale_messages { sl@0: char name[MAX_NAME_LEN]; sl@0: char* domain; sl@0: } L_messages_t; sl@0: sl@0: sl@0: char* __getString(char* str) sl@0: { sl@0: int len = strlen(str)+1; sl@0: char* temp = (char*) new char[len]; sl@0: strcpy(temp, str); sl@0: sl@0: return temp; sl@0: sl@0: } sl@0: sl@0: /* Common function to set locale information */ sl@0: #if 0 sl@0: static void* Locale_Common_Create(const char* locale) sl@0: { sl@0: sl@0: setlocale(LC_ALL, locale); sl@0: sl@0: return (void*) localeconv(); sl@0: sl@0: sl@0: } sl@0: #endif sl@0: sl@0: /* Gets the system locale name */ sl@0: static const char* Locale_common_default( char* name) sl@0: { sl@0: #if 0 sl@0: char* presentLocalename = NULL; sl@0: char* defaultLocalename = NULL; sl@0: sl@0: //Madhu - going round to get default system locale, need to find alternative - 18/8/96 sl@0: presentLocalename = setlocale(LC_ALL, NULL); sl@0: defaultLocalename = setlocale(LC_ALL, ""); sl@0: setlocale(LC_ALL, presentLocalename); sl@0: #endif sl@0: sl@0: if(name!=NULL) sl@0: strcpy(name,LOCALE_SYSTEM_DEFAULT); sl@0: sl@0: return LOCALE_SYSTEM_DEFAULT; sl@0: sl@0: } sl@0: sl@0: #if 0 sl@0: /* Gets the present locale name */ sl@0: static char* Locale_common_name(const void* cat, char* name) sl@0: { sl@0: #if 0 sl@0: char* presentLocalename = NULL; sl@0: sl@0: presentLocalename = setlocale(LC_ALL, NULL); sl@0: strcpy(name,presentLocalename); sl@0: sl@0: return presentLocalename; sl@0: #endif sl@0: L_ctype_t* locale = (L_ctype_t*) cat; sl@0: strcpy(name,locale->name); sl@0: return name; sl@0: } sl@0: #endif sl@0: /* */ sl@0: static char * Locale_extract_name ( const char *cname, char *into, int category ) sl@0: { sl@0: int i = 0; sl@0: const char * end; sl@0: const char* strstar = "*", *strnull = ""; sl@0: sl@0: if ( cname[0] != '/' ) sl@0: { sl@0: if (strcmp(cname,strnull) == 0) sl@0: return strcpy(into, strstar); sl@0: else sl@0: return strcpy(into, cname); /* simple locale name */ sl@0: } sl@0: sl@0: for ( i = 0; i <= category; i ++ ) { sl@0: while ( *cname != '\0' && *cname != '/' ) sl@0: cname++; sl@0: if ( *cname == '\0' ) sl@0: return into; sl@0: cname++; sl@0: } sl@0: sl@0: if ( *cname == '\0' ) sl@0: return into; sl@0: sl@0: end = cname; sl@0: while ( *end != '\0' && *end != '/' ) sl@0: end++; sl@0: sl@0: strncpy ( into, cname, end - cname ); sl@0: into [ end - cname ] = '\0'; sl@0: sl@0: return into; sl@0: } sl@0: sl@0: # ifdef __cplusplus sl@0: _STLP_BEGIN_NAMESPACE //Madhu - moved to here sl@0: extern "C" { sl@0: sl@0: _Locale_mask_t Get_locale_wchar_ctype(wint_t wc, _Locale_mask_t /*mask*/) sl@0: sl@0: { sl@0: _Locale_mask_t ret = 0; sl@0: sl@0: if (iswcntrl(wc)) ret |= _Locale_CNTRL; sl@0: if (iswupper(wc)) ret |= _Locale_UPPER; sl@0: if (iswlower(wc)) ret |= _Locale_LOWER; sl@0: if (iswdigit(wc)) ret |= _Locale_DIGIT; sl@0: if (iswxdigit(wc)) ret |= _Locale_XDIGIT; sl@0: if (iswpunct(wc)) ret |= _Locale_PUNCT; sl@0: if (iswspace(wc)) ret |= _Locale_SPACE; sl@0: if (iswprint(wc)) ret |= _Locale_PRINT; sl@0: if (iswalpha(wc)) ret |= _Locale_ALPHA; sl@0: sl@0: return ret; sl@0: sl@0: } sl@0: sl@0: _Locale_mask_t Get_locale_char_ctype(unsigned char c) sl@0: sl@0: { sl@0: _Locale_mask_t ret = 0; sl@0: sl@0: if (iscntrl(c)) ret |= _Locale_CNTRL; sl@0: if (isupper(c)) ret |= _Locale_UPPER; sl@0: if (islower(c)) ret |= _Locale_LOWER; sl@0: if (isdigit(c)) ret |= _Locale_DIGIT; sl@0: if (isxdigit(c)) ret |= _Locale_XDIGIT; sl@0: if (ispunct(c)) ret |= _Locale_PUNCT; sl@0: if (isspace(c)) ret |= _Locale_SPACE; sl@0: if (isprint(c)) ret |= _Locale_PRINT; sl@0: if (isalpha(c)) ret |= _Locale_ALPHA; sl@0: sl@0: return ret; sl@0: sl@0: } sl@0: //Madhu - locale function definitions - END sl@0: sl@0: sl@0: //# ifdef __cplusplus sl@0: //_STLP_BEGIN_NAMESPACE sl@0: sl@0: # define __DUMMY_PAR sl@0: # define __DUMMY_PAR1 sl@0: # define __DUMMY_PAR2 sl@0: # define __DUMMY_PAR3 sl@0: # define __DUMMY_PAR4 sl@0: # define __DUMMY_PAR5 sl@0: # define __DUMMY_PAR6 sl@0: # define __DUMMY_PAR7 sl@0: # define __DUMMY_PAR8 sl@0: # endif sl@0: sl@0: void* _Locale_ctype_create(const char * name) sl@0: { sl@0: sl@0: unsigned char buffer[256]; sl@0: int i; sl@0: _Locale_mask_t* ctable; sl@0: sl@0: L_ctype_t *plocCType = (L_ctype_t*) new (L_ctype_t); sl@0: sl@0: if (!plocCType) sl@0: return NULL; sl@0: sl@0: strcpy(plocCType->name, name); sl@0: char* ptemp = setlocale(LC_CTYPE, name); sl@0: if (!ptemp) sl@0: return NULL; sl@0: ctable = plocCType->ctable; sl@0: sl@0: /* Partial implementation for ANSI code page, need to implement for DBCS code pages*/ sl@0: sl@0: /* Make table with all characters. */ sl@0: for(i = 0; i < 256; i++) buffer[i] = i; sl@0: sl@0: for (i=0;i<256;i++) sl@0: { sl@0: sl@0: ctable[i+1] = Get_locale_char_ctype(buffer[i]); sl@0: } sl@0: ctable[0] = 0; //EOF sl@0: #ifdef CODECVT_ICONV sl@0: plocCType->statelist = NULL; sl@0: #endif sl@0: return plocCType; sl@0: } sl@0: sl@0: void* _Locale_numeric_create(const char *name) sl@0: { sl@0: L_numeric_t *plocNumeric = (L_numeric_t *)new (L_numeric_t); sl@0: struct lconv *plconv; sl@0: sl@0: if (!plocNumeric) sl@0: return NULL; sl@0: strcpy(plocNumeric->name, name); sl@0: sl@0: char* ptemp = setlocale(LC_NUMERIC, name); sl@0: if (!ptemp) sl@0: return NULL; sl@0: plconv = localeconv(); sl@0: sl@0: //copy locale numeric data to local structure sl@0: strcpy(plocNumeric->decimal_point, plconv->decimal_point); sl@0: plocNumeric->grouping = __getString(plconv->grouping); sl@0: strcpy(plocNumeric->thousands_sep, plconv->thousands_sep); sl@0: sl@0: return plocNumeric; sl@0: } sl@0: sl@0: void*_Locale_time_create(const char * name) sl@0: { sl@0: L_time_t *plocTime = (L_time_t *)new(L_time_t); sl@0: //struct lconv *plconv; sl@0: sl@0: if (!plocTime ) sl@0: return NULL; sl@0: strcpy(plocTime ->name, name); sl@0: sl@0: char* ptemp = setlocale(LC_TIME, name); sl@0: if (!ptemp) sl@0: return NULL; sl@0: //plconv = localeconv(); sl@0: sl@0: int i; sl@0: int index = (MON_1); sl@0: //Get all month names sl@0: for (i = 0;i<12;i++,index++) sl@0: plocTime->month[i] = __getString(nl_langinfo(index)); sl@0: sl@0: //Get all abbrevated month names sl@0: index = (ABMON_1); sl@0: for (i = 0;i<12;i++,index++) sl@0: plocTime->abbrev_month[i] = __getString(nl_langinfo(index)); sl@0: sl@0: //Get all weekday names sl@0: index = (DAY_1); sl@0: for (i = 0;i<7;i++,index++) sl@0: plocTime->dayofweek[i] = __getString(nl_langinfo(index)); sl@0: sl@0: //Get all weekday names sl@0: index = (ABDAY_1); sl@0: for (i = 0;i<7;i++,index++) sl@0: plocTime->abbrev_dayofweek[i] = __getString(nl_langinfo(index)); sl@0: sl@0: sl@0: return plocTime; sl@0: } sl@0: sl@0: void* _Locale_collate_create(const char *name) sl@0: { sl@0: L_collate_t *plocCollate = (L_collate_t *)new(L_collate_t); sl@0: sl@0: if (!plocCollate) sl@0: return NULL; sl@0: strcpy(plocCollate->name, name); sl@0: sl@0: return plocCollate; sl@0: } sl@0: sl@0: void* _Locale_monetary_create(const char * name) sl@0: { sl@0: L_monetary_t *plocMonetary = (L_monetary_t *)new(L_monetary_t); sl@0: struct lconv *plconv; sl@0: sl@0: if (!plocMonetary) sl@0: return NULL; sl@0: strcpy(plocMonetary->name, name); sl@0: sl@0: char* ptemp = setlocale(LC_MONETARY, name); sl@0: if (!ptemp) sl@0: return NULL; sl@0: plconv = localeconv(); sl@0: sl@0: strcpy(plocMonetary->decimal_point,plconv->mon_decimal_point); sl@0: strcpy(plocMonetary->thousands_sep, plconv->mon_thousands_sep); sl@0: plocMonetary->grouping = __getString(plconv->mon_grouping); sl@0: strcpy(plocMonetary->int_curr_symbol, plconv->int_curr_symbol); // 3+1+1 sl@0: strcpy(plocMonetary->curr_symbol, plconv->currency_symbol); sl@0: strcpy(plocMonetary->negative_sign, plconv->negative_sign); sl@0: strcpy(plocMonetary->positive_sign, plconv->positive_sign); sl@0: plocMonetary->frac_digits = plconv->frac_digits; sl@0: plocMonetary->int_frac_digits = plconv->int_frac_digits; sl@0: sl@0: return plocMonetary; sl@0: } sl@0: void* _Locale_messages_create(const char *name) sl@0: { sl@0: L_messages_t *plocMessages= (L_messages_t *)new(L_messages_t); sl@0: sl@0: if (!plocMessages) sl@0: return NULL; sl@0: strcpy(plocMessages->name, name); sl@0: sl@0: return plocMessages; sl@0: } sl@0: sl@0: const char* _Locale_ctype_default(char* buff) sl@0: { sl@0: return Locale_common_default(buff); sl@0: } sl@0: sl@0: const char* _Locale_numeric_default(char *buff) sl@0: { sl@0: return Locale_common_default(buff); sl@0: } sl@0: sl@0: const char* _Locale_time_default(char* buff) sl@0: { sl@0: return Locale_common_default(buff); sl@0: } sl@0: sl@0: const char* _Locale_collate_default(char* buff) sl@0: { sl@0: return Locale_common_default(buff); sl@0: } sl@0: sl@0: const char* _Locale_monetary_default(char* buff) sl@0: { sl@0: return Locale_common_default(buff); sl@0: } sl@0: sl@0: const char* _Locale_messages_default(char* buff) sl@0: { sl@0: return Locale_common_default(buff); sl@0: } sl@0: sl@0: char* _Locale_ctype_name(const void* cat, char* buff) sl@0: { sl@0: L_ctype_t* locale = (L_ctype_t*) cat; sl@0: strcpy(buff,locale->name); sl@0: return buff; sl@0: //return Locale_common_name(locale,buff); sl@0: } sl@0: sl@0: char* _Locale_numeric_name(const void* cat, char* buff) sl@0: { sl@0: L_numeric_t* locale = (L_numeric_t*) cat; sl@0: strcpy(buff,locale->name); sl@0: return buff; sl@0: //return Locale_common_name(locale,buff); sl@0: } sl@0: sl@0: char* _Locale_time_name(const void* cat, char* buff) sl@0: { sl@0: L_time_t* locale = (L_time_t*) cat; sl@0: strcpy(buff,locale->name); sl@0: return buff; sl@0: //return Locale_common_name(locale,buff); sl@0: } sl@0: sl@0: char* _Locale_collate_name(const void* cat, char* buff) sl@0: { sl@0: L_collate_t* locale = (L_collate_t*) cat; sl@0: strcpy(buff,locale->name); sl@0: return buff; sl@0: //return Locale_common_name(locale,buff); sl@0: } sl@0: sl@0: char* _Locale_monetary_name(const void* cat, char* buff) sl@0: { sl@0: L_monetary_t* locale = (L_monetary_t*) cat; sl@0: strcpy(buff,locale->name); sl@0: return buff; sl@0: //return Locale_common_name(locale,buff); sl@0: } sl@0: sl@0: char* _Locale_messages_name(const void* cat, char* buff) sl@0: { sl@0: L_messages_t* locale = (L_messages_t*) cat; sl@0: strcpy(buff,locale->name); sl@0: return buff; sl@0: //return Locale_common_name(locale,buff); sl@0: } sl@0: sl@0: void _Locale_ctype_destroy(void* locale) sl@0: { sl@0: #ifdef CODECVT_ICONV sl@0: DeleteAllStates(((L_ctype_t*)locale)->statelist); sl@0: #endif sl@0: delete((L_ctype_t*)locale); sl@0: } sl@0: sl@0: void _Locale_numeric_destroy(void* locale) sl@0: { sl@0: delete ((L_numeric_t*)locale)->grouping; sl@0: delete (L_numeric_t*)locale; sl@0: } sl@0: sl@0: void _Locale_time_destroy(void* locale) sl@0: { sl@0: int i; sl@0: L_time_t* plocTime =(L_time_t*)locale; sl@0: //delete months sl@0: for (i = 0;i<12;i++) sl@0: delete (plocTime->month[i]); sl@0: //delete abbrevated months sl@0: for (i = 0;i<12;i++) sl@0: delete (plocTime->abbrev_month[i]); sl@0: //delete week day sl@0: for (i = 0;i<7;i++) sl@0: delete (plocTime->dayofweek[i]); sl@0: //delete abbrevated week day sl@0: for (i = 0;i<7;i++) sl@0: delete (plocTime->abbrev_dayofweek[i]); sl@0: sl@0: delete((L_time_t*)locale); sl@0: } sl@0: sl@0: void _Locale_collate_destroy(void* locale) sl@0: { sl@0: delete((L_collate_t*)locale); sl@0: } sl@0: sl@0: void _Locale_monetary_destroy(void* locale) sl@0: { sl@0: delete ((L_monetary_t*)locale)->grouping; sl@0: delete((L_monetary_t*)locale); sl@0: } sl@0: sl@0: void _Locale_messages_destroy(void* locale) sl@0: { sl@0: delete((L_messages_t*)locale); sl@0: } sl@0: sl@0: char* _Locale_extract_ctype_name(const char* cname, char* buf) sl@0: { sl@0: return Locale_extract_name(cname, buf, LC_CTYPE); sl@0: } sl@0: sl@0: char* _Locale_extract_numeric_name(const char* cname, char* buf) sl@0: { sl@0: return Locale_extract_name(cname, buf, LC_NUMERIC); sl@0: } sl@0: sl@0: char* _Locale_extract_time_name(const char* cname, char* buf) sl@0: { sl@0: return Locale_extract_name(cname, buf, LC_TIME); sl@0: } sl@0: sl@0: char* _Locale_extract_collate_name(const char* cname, char* buf) sl@0: { sl@0: return Locale_extract_name(cname, buf, LC_COLLATE); sl@0: } sl@0: sl@0: char* _Locale_extract_monetary_name(const char* cname, char* buf) sl@0: { sl@0: return Locale_extract_name(cname, buf, LC_MONETARY); sl@0: } sl@0: sl@0: char* _Locale_extract_messages_name(const char* cname, char* buf) sl@0: { sl@0: return Locale_extract_name(cname, buf, LC_MESSAGES); sl@0: } sl@0: sl@0: char* _Locale_compose_name(char* buf, sl@0: const char* ctype, const char* numeric, sl@0: const char* time, const char* collate, sl@0: const char* monetary, const char* messages, sl@0: const char* /*default_name*/) sl@0: { sl@0: sl@0: if ( !strcmp ( ctype, numeric ) && sl@0: !strcmp ( ctype, time ) && sl@0: !strcmp ( ctype, collate ) && sl@0: !strcmp ( ctype, monetary ) && sl@0: !strcmp ( ctype, messages ) ) sl@0: return strcpy ( buf, ctype ); sl@0: sl@0: strcpy ( buf, "/" ); sl@0: strcat ( buf, ctype ); sl@0: sl@0: strcat ( buf, "/" ); sl@0: strcat ( buf, numeric ); sl@0: sl@0: strcat ( buf, "/" ); sl@0: strcat ( buf, time ); sl@0: sl@0: strcat ( buf, "/" ); sl@0: strcat ( buf, collate ); sl@0: sl@0: strcat ( buf, "/" ); sl@0: strcat ( buf, monetary ); sl@0: sl@0: strcat ( buf, "/" ); sl@0: strcat ( buf, messages ); sl@0: sl@0: return buf; sl@0: } sl@0: sl@0: sl@0: /* ctype */ sl@0: sl@0: const _Locale_mask_t* _Locale_ctype_table(struct _Locale_ctype* lctype) sl@0: { sl@0: sl@0: return lctype->ctable; sl@0: } sl@0: sl@0: int _Locale_toupper(struct _Locale_ctype* /*lctype*/, int c) sl@0: { sl@0: return toupper(c); sl@0: } sl@0: sl@0: int _Locale_tolower(L_ctype_t* /*lctype*/, int c) sl@0: { sl@0: return tolower(c); sl@0: } sl@0: sl@0: #ifndef _STLP_NO_WCHAR_T sl@0: sl@0: _Locale_mask_t _Locale_wchar_ctype(L_ctype_t* /*lctype*/, wint_t c, _Locale_mask_t which_bits) sl@0: { sl@0: _Locale_mask_t mask = Get_locale_wchar_ctype(c,which_bits); sl@0: sl@0: return mask & which_bits; sl@0: } sl@0: sl@0: wint_t _Locale_wchar_tolower(L_ctype_t* lctype, wint_t c) sl@0: { sl@0: setlocale(LC_CTYPE, lctype->name); sl@0: return towlower(c); sl@0: } sl@0: sl@0: wint_t _Locale_wchar_toupper(L_ctype_t* /*lctype*/, wint_t c) sl@0: { sl@0: return towupper(c); sl@0: } sl@0: sl@0: # endif sl@0: sl@0: # ifndef _STLP_NO_MBSTATE_T sl@0: sl@0: int _Locale_mb_cur_max (L_ctype_t * /*lctype*/) sl@0: { sl@0: return MB_CUR_MAX; sl@0: } sl@0: sl@0: int _Locale_mb_cur_min (L_ctype_t * /*lctype*/) sl@0: { sl@0: return 1; sl@0: } sl@0: sl@0: int _Locale_is_stateless (L_ctype_t * /*lctype*/) sl@0: { sl@0: return (MB_CUR_MAX == 1)?1:0; sl@0: } sl@0: sl@0: #ifndef _STLP_NO_WCHAR_T sl@0: wint_t _Locale_btowc(L_ctype_t * lctype, int c) sl@0: { sl@0: setlocale(LC_CTYPE, lctype->name); sl@0: return btowc(c); sl@0: } sl@0: sl@0: int _Locale_wctob(L_ctype_t * lctype, wint_t wc) sl@0: { sl@0: setlocale(LC_CTYPE, lctype->name); sl@0: return wctob(wc); sl@0: } sl@0: sl@0: size_t _Locale_mbtowc(L_ctype_t *lctype, sl@0: wchar_t *to, size_t n1, sl@0: const char *from, size_t n, int* chars_write, sl@0: mbstate_t * shift_state) sl@0: { sl@0: #ifdef CODECVT_ICONV sl@0: char codeset[64] = sl@0: { sl@0: 0 sl@0: }; sl@0: iconv_t state = GetState(lctype->statelist, shift_state, IN); sl@0: if (state == NULL) sl@0: { sl@0: ExtractCodeset(lctype->name, codeset); sl@0: state= iconv_open(UNICODESTR,codeset); sl@0: if (state==NULL) sl@0: return (size_t)-1; sl@0: if (AddState(&lctype->statelist,state,shift_state,IN) == 0) sl@0: return (size_t)-1; sl@0: sl@0: } sl@0: char* outbuf = (char*)to; sl@0: const char* inbuf = (char*)from; sl@0: unsigned int inbytes = n; sl@0: unsigned int outbytes = n1*sizeof(wchar_t); sl@0: unsigned int chars_read = iconv((void*)state,&inbuf,&inbytes,&outbuf,&outbytes); sl@0: *chars_write = (wchar_t*)outbuf - to; sl@0: if (chars_read == (size_t)-1) sl@0: { sl@0: if ( (errno == EINVAL) || (outbuf!=(char*)to) ) sl@0: { sl@0: BEtoLE(to,(wchar_t*)outbuf-to); sl@0: return inbuf-from; sl@0: } sl@0: sl@0: return (size_t)-1; sl@0: sl@0: } sl@0: BEtoLE(to,(wchar_t*)outbuf-to); sl@0: //return (wchar_t*)outbuf-to; sl@0: return inbuf-from; sl@0: sl@0: #else sl@0: setlocale(LC_CTYPE, lctype->name); sl@0: return (size_t) mbtowc(to, from,n); sl@0: #endif sl@0: } sl@0: sl@0: size_t _Locale_wctomb(L_ctype_t* lctype, sl@0: char *to, size_t n, sl@0: const wchar_t c, sl@0: mbstate_t *shift_state) sl@0: { sl@0: #ifdef CODECVT_ICONV sl@0: char codeset[64] = sl@0: { sl@0: 0 sl@0: }; sl@0: iconv_t state = GetState(lctype->statelist, shift_state,OUT); sl@0: if (state == NULL) sl@0: { sl@0: ExtractCodeset(lctype->name, codeset); sl@0: state= iconv_open(codeset, UNICODESTR); sl@0: if (state==NULL) sl@0: return (size_t)-1; sl@0: if (AddState(&lctype->statelist,state,shift_state,OUT) == 0) sl@0: return (size_t)-1; sl@0: sl@0: } sl@0: char* outbuf = to; sl@0: const char* inbuf = (char*)&c; sl@0: unsigned int inbytes = 2; sl@0: unsigned int outbytes = n; sl@0: unsigned int chars_read = iconv((void*)state,&inbuf,&inbytes,&outbuf,&outbytes); sl@0: if (chars_read == (size_t)-1) sl@0: { sl@0: if (errno == EINVAL) sl@0: return outbuf-to; sl@0: else sl@0: return (size_t)-1; sl@0: sl@0: } sl@0: //BEtoLE(to,(wchar_t*)outbuf-to); sl@0: return outbuf-to; sl@0: #else sl@0: setlocale(LC_CTYPE, lctype->name); sl@0: return (size_t) wctomb(to, c); sl@0: sl@0: #endif sl@0: } sl@0: sl@0: # endif sl@0: sl@0: //Madhu - Need to double check the implementation. sl@0: size_t _Locale_unshift(L_ctype_t * /*lctype*/, sl@0: mbstate_t *st, sl@0: char *buff, size_t n, char ** next) sl@0: { sl@0: #if 0 sl@0: if(*st == 0) sl@0: { sl@0: *next = buff; sl@0: return 0; sl@0: } sl@0: else sl@0: { sl@0: if(n < 1) sl@0: { sl@0: *next = buff; sl@0: return (size_t)-2; sl@0: } sl@0: sl@0: *next = buff + 1; sl@0: return 1; sl@0: } sl@0: #endif sl@0: //Conversion is not required, because iconv will not do partial conversion. sl@0: *next = buff; sl@0: return 0; sl@0: } sl@0: sl@0: # endif /* _STLP_NO_MBSTATE_T */ sl@0: sl@0: sl@0: /* Collate */ sl@0: int _Locale_strcmp(L_collate_t* lcol, sl@0: const char* pStr1, size_t len1, const char* pStr2, sl@0: size_t len2) sl@0: { sl@0: sl@0: char *ptempStr1, *ptempStr2; sl@0: int tempLen1,tempLen2; sl@0: sl@0: tempLen1 = _Locale_strxfrm(lcol, NULL,0,pStr1,len1); sl@0: tempLen2 = _Locale_strxfrm(lcol, NULL,0,pStr2,len2); sl@0: ptempStr1 = (char*) new char[tempLen1]; sl@0: ptempStr2 = (char*) new char[tempLen2]; sl@0: int ret; sl@0: int minN = tempLen1 < tempLen2 ? tempLen1 : tempLen2; sl@0: setlocale(LC_COLLATE, lcol->name); sl@0: _Locale_strxfrm(lcol, ptempStr1,tempLen1,pStr1,len1); sl@0: _Locale_strxfrm(lcol, ptempStr2,tempLen2,pStr2,len2); sl@0: ret = strncmp(ptempStr1, ptempStr2, minN); sl@0: if (ret == 0) sl@0: { sl@0: if (len1 < len2) sl@0: return -1; sl@0: else if (len1 > len2) sl@0: return 1; sl@0: else sl@0: return 0; sl@0: } else sl@0: return ret; sl@0: sl@0: } sl@0: sl@0: # ifndef _STLP_NO_WCHAR_T sl@0: sl@0: int _Locale_strwcmp(L_collate_t* lcol, sl@0: const wchar_t* pStr1, size_t len1, sl@0: const wchar_t* pStr2, size_t len2) sl@0: { sl@0: wchar_t *ptempStr1, *ptempStr2; sl@0: int tempLen1,tempLen2; sl@0: sl@0: tempLen1 = _Locale_strwxfrm(lcol, NULL,0,pStr1,len1); sl@0: tempLen2 = _Locale_strwxfrm(lcol, NULL,0,pStr2,len2); sl@0: ptempStr1 = (wchar_t*) new wchar_t[tempLen1+1]; sl@0: ptempStr2 = (wchar_t*) new wchar_t[tempLen2+1]; sl@0: int ret; sl@0: int minN = tempLen1 < tempLen2 ? tempLen1 : tempLen2; sl@0: setlocale(LC_COLLATE, lcol->name); sl@0: _Locale_strwxfrm(lcol, ptempStr1,tempLen1,pStr1,len1); sl@0: _Locale_strwxfrm(lcol, ptempStr2,tempLen2,pStr2,len2); sl@0: ret = wcsncmp(ptempStr1, ptempStr2, minN); sl@0: if (ret == 0) sl@0: { sl@0: if (len1 < len2) sl@0: return -1; sl@0: else if (len1 > len2) sl@0: return 1; sl@0: else sl@0: return 0; sl@0: } else sl@0: return ret; sl@0: sl@0: sl@0: } sl@0: sl@0: # endif sl@0: sl@0: size_t _Locale_strxfrm(L_collate_t* lcol, sl@0: char* pDestStr, size_t destLen, sl@0: const char* pSrcStr, size_t srcLen) sl@0: { sl@0: size_t n; sl@0: setlocale(LC_COLLATE, lcol->name); sl@0: sl@0: char* ptemp = (char*) new char[srcLen+1]; sl@0: if(ptemp == NULL) sl@0: return 0; sl@0: memmove(ptemp,pSrcStr,srcLen); sl@0: *(ptemp+srcLen) = 0; sl@0: sl@0: n = strxfrm(pDestStr, ptemp, destLen); sl@0: sl@0: delete []ptemp; sl@0: sl@0: if ((pDestStr == NULL) || (destLen ==0) ) sl@0: return n; sl@0: else if(n > destLen) sl@0: return (size_t)-1; sl@0: sl@0: pDestStr[n] = 0; sl@0: return n; sl@0: } sl@0: sl@0: # ifndef _STLP_NO_WCHAR_T sl@0: sl@0: size_t _Locale_strwxfrm(L_collate_t* lcol, sl@0: wchar_t* pDestStr, size_t destLen, sl@0: const wchar_t* pSrcStr, size_t srcLen) sl@0: { sl@0: size_t n; sl@0: setlocale(LC_COLLATE, lcol->name); sl@0: wchar_t* ptemp = (wchar_t*) new wchar_t[srcLen+1]; sl@0: if(ptemp == NULL) sl@0: return 0; sl@0: memmove(ptemp,pSrcStr,srcLen*sizeof(wchar_t)); sl@0: *(ptemp+srcLen) = 0; sl@0: n = wcsxfrm(pDestStr, ptemp, destLen); sl@0: sl@0: delete []ptemp; sl@0: if ((pDestStr == NULL) || (destLen ==0) ) sl@0: return n; sl@0: else if(n > destLen) sl@0: return (size_t)-1; sl@0: sl@0: pDestStr[n] = 0; sl@0: return n; sl@0: } sl@0: sl@0: # endif sl@0: sl@0: /* Numeric */ sl@0: sl@0: char _Locale_decimal_point(L_numeric_t* lnum) sl@0: { sl@0: sl@0: return lnum->decimal_point[0]; sl@0: } sl@0: sl@0: char _Locale_thousands_sep(L_numeric_t* lnum) sl@0: { sl@0: sl@0: return lnum->thousands_sep[0]; sl@0: } sl@0: const char* _Locale_grouping(L_numeric_t*lnum) sl@0: { sl@0: sl@0: return lnum->grouping; sl@0: } sl@0: sl@0: const char * _Locale_true(L_numeric_t * /*lnum*/) sl@0: { sl@0: const char* __true_name="true"; //glib and NT doing the same sl@0: sl@0: sl@0: return __true_name; sl@0: } sl@0: sl@0: const char * _Locale_false(L_numeric_t * /*lnum*/) sl@0: { sl@0: const char* __false_name="false"; //glib and NT doing the same sl@0: sl@0: return __false_name; sl@0: } sl@0: sl@0: sl@0: /* Monetary */ sl@0: sl@0: const char* _Locale_int_curr_symbol(L_monetary_t * lmon) sl@0: { sl@0: sl@0: return lmon->int_curr_symbol; sl@0: } sl@0: sl@0: const char* _Locale_currency_symbol(L_monetary_t * lmon) sl@0: { sl@0: sl@0: return lmon->curr_symbol; sl@0: } sl@0: sl@0: char _Locale_mon_decimal_point(L_monetary_t * lmon) sl@0: { sl@0: return lmon->decimal_point[0]; sl@0: } sl@0: sl@0: char _Locale_mon_thousands_sep(L_monetary_t * lmon) sl@0: { sl@0: sl@0: return lmon->thousands_sep[0]; sl@0: } sl@0: sl@0: const char* _Locale_mon_grouping(L_monetary_t * lmon) sl@0: { sl@0: sl@0: return lmon->grouping; sl@0: } sl@0: sl@0: const char* _Locale_positive_sign(L_monetary_t * lmon) sl@0: { sl@0: sl@0: return lmon->positive_sign; sl@0: } sl@0: sl@0: const char* _Locale_negative_sign(L_monetary_t * lmon) sl@0: { sl@0: sl@0: return lmon->negative_sign; sl@0: } sl@0: sl@0: char _Locale_int_frac_digits(L_monetary_t * lmon) sl@0: { sl@0: sl@0: return lmon->int_frac_digits; sl@0: } sl@0: sl@0: char _Locale_frac_digits(L_monetary_t * lmon) sl@0: { sl@0: sl@0: return lmon->frac_digits; sl@0: } sl@0: sl@0: int _Locale_p_cs_precedes(L_monetary_t * lmon) sl@0: { sl@0: struct lconv* plconv; sl@0: setlocale(LC_MONETARY, lmon->name); sl@0: plconv = localeconv(); sl@0: sl@0: return plconv->p_cs_precedes; sl@0: } sl@0: sl@0: int _Locale_p_sep_by_space(L_monetary_t * lmon) sl@0: { sl@0: struct lconv* plconv; sl@0: setlocale(LC_MONETARY, lmon->name); sl@0: plconv = localeconv(); sl@0: sl@0: return plconv->p_sep_by_space; sl@0: } sl@0: sl@0: int _Locale_p_sign_posn(L_monetary_t * lmon) sl@0: { sl@0: struct lconv* plconv; sl@0: setlocale(LC_MONETARY, lmon->name); sl@0: plconv = localeconv(); sl@0: sl@0: return plconv->p_sign_posn; sl@0: } sl@0: sl@0: int _Locale_n_cs_precedes(L_monetary_t * lmon) sl@0: { sl@0: struct lconv* plconv; sl@0: setlocale(LC_MONETARY, lmon->name); sl@0: plconv = localeconv(); sl@0: sl@0: return plconv->n_cs_precedes; sl@0: } sl@0: sl@0: int _Locale_n_sep_by_space(L_monetary_t * lmon) sl@0: { sl@0: struct lconv* plconv; sl@0: setlocale(LC_MONETARY, lmon->name); sl@0: plconv = localeconv(); sl@0: sl@0: return plconv->n_sep_by_space; sl@0: } sl@0: sl@0: int _Locale_n_sign_posn(L_monetary_t * lmon) sl@0: { sl@0: struct lconv* plconv; sl@0: setlocale(LC_MONETARY, lmon->name); sl@0: plconv = localeconv(); sl@0: sl@0: return plconv->n_sign_posn; sl@0: } sl@0: sl@0: sl@0: /* Time */ sl@0: const char * _Locale_full_monthname(L_time_t * ltime, int month) sl@0: { sl@0: sl@0: return ltime->month[month]; sl@0: } sl@0: sl@0: const char * _Locale_abbrev_monthname(L_time_t * ltime, int month) sl@0: { sl@0: sl@0: return ltime->abbrev_month[month]; sl@0: } sl@0: sl@0: const char * _Locale_full_dayofweek(L_time_t * ltime, int day) sl@0: { sl@0: sl@0: return ltime->dayofweek[day]; sl@0: } sl@0: sl@0: const char * _Locale_abbrev_dayofweek(L_time_t * ltime, int day) sl@0: { sl@0: sl@0: return ltime->abbrev_dayofweek[day]; sl@0: } sl@0: sl@0: const char* _Locale_d_t_fmt(L_time_t* ltime) sl@0: { sl@0: setlocale(LC_TIME, ltime->name); sl@0: return nl_langinfo(D_T_FMT); sl@0: } sl@0: sl@0: const char* _Locale_d_fmt(L_time_t* ltime) sl@0: { sl@0: setlocale(LC_TIME, ltime->name); sl@0: return nl_langinfo(D_FMT); sl@0: } sl@0: sl@0: const char* _Locale_t_fmt(L_time_t* ltime) sl@0: { sl@0: setlocale(LC_TIME, ltime->name); sl@0: return nl_langinfo(T_FMT); sl@0: } sl@0: sl@0: const char* _Locale_long_d_t_fmt(L_time_t* ltime) sl@0: { sl@0: setlocale(LC_TIME, ltime->name); sl@0: return nl_langinfo(D_T_FMT); //Madhu--now same as D_T_FMT, need to check sl@0: } sl@0: sl@0: const char* _Locale_long_d_fmt(L_time_t* ltime) sl@0: { sl@0: setlocale(LC_TIME, ltime->name); sl@0: return nl_langinfo(D_FMT); //Madhu--now same as D_FMT, need to check sl@0: } sl@0: const char* _Locale_am_str(L_time_t* ltime) sl@0: { sl@0: setlocale(LC_TIME, ltime->name); sl@0: return nl_langinfo(AM_STR); sl@0: } sl@0: sl@0: const char* _Locale_pm_str(L_time_t* ltime) sl@0: { sl@0: setlocale(LC_TIME, ltime->name); sl@0: return nl_langinfo(PM_STR); sl@0: } sl@0: sl@0: const char* _Locale_t_fmt_ampm(L_time_t* ltime) sl@0: { sl@0: setlocale(LC_TIME, ltime->name); sl@0: return nl_langinfo(T_FMT_AMPM); sl@0: } sl@0: sl@0: /* Messages */ // Madhu - support after libc team supported. sl@0: sl@0: sl@0: sl@0: int _Locale_catopen(L_messages_t* lmessage, const char* catalogName) sl@0: { sl@0: lmessage->domain = __getString((char*)catalogName); sl@0: return 1;//catopen(catalogName,/*NL_CAT_LOCALE*/1); sl@0: } sl@0: sl@0: void _Locale_catclose(L_messages_t* lmessage, int /*catalog_desc*/) sl@0: { sl@0: //setlocale(LC_MESSAGES, lmessage->name); sl@0: delete(lmessage->domain); sl@0: lmessage->domain = NULL; sl@0: //catclose(catalog_desc); sl@0: sl@0: } sl@0: sl@0: const char* _Locale_catgets(L_messages_t* lmessage, int /*catalog_desc*/, sl@0: int /*set*/, int /*message*/, sl@0: const char *dfault) sl@0: { sl@0: char* locale = setlocale(LC_ALL, lmessage->name); sl@0: #ifdef _MESSAGE_CATALOG_ sl@0: textdomain(lmessage->domain); sl@0: sl@0: return gettext(dfault); sl@0: #else sl@0: return NULL; sl@0: #endif sl@0: sl@0: } sl@0: sl@0: #ifdef __cplusplus sl@0: } /* extern C */ sl@0: _STLP_END_NAMESPACE sl@0: #endif sl@0: sl@0: #endif /* real locale */