c_locale_win32.c

来自「symbian 上的stl_port进过编译的。」· C语言 代码 · 共 1,983 行 · 第 1/5 页

C
1,983
字号
    if (!lcol) return lcol;    memset(lcol, 0, sizeof(_Locale_collate_t));    __Extract_locale_name(name, LC_COLLATE, cname);    if (__GetLCIDFromName(cname, &lcol->lc.id, lcol->cp, lc_hint) == -1)    { free(lcol); return NULL; }    return lcol;  }  void* _Locale_monetary_create(const char * name, _Locale_lcid_t* lc_hint) {    char cname[_Locale_MAX_SIMPLE_NAME];    char *GroupingBuffer;    int BufferSize;    char FracDigits[3];    _Locale_monetary_t *lmon = (_Locale_monetary_t*)malloc(sizeof(_Locale_monetary_t));    if (!lmon) return lmon;    memset(lmon, 0, sizeof(_Locale_monetary_t));    __Extract_locale_name(name, LC_MONETARY, cname);    if (__GetLCIDFromName(cname, &lmon->lc.id, lmon->cp, lc_hint) == -1)    { free(lmon); return NULL; }    /* Extract information about monetary system */    __GetLocaleInfoUsingACP(lmon->lc.id, lmon->cp, LOCALE_SDECIMAL, lmon->decimal_point, 4);    __GetLocaleInfoUsingACP(lmon->lc.id, lmon->cp, LOCALE_STHOUSAND, lmon->thousands_sep, 4);    BufferSize = GetLocaleInfoA(lmon->lc.id, LOCALE_SGROUPING, NULL, 0);    GroupingBuffer = (char*)malloc(BufferSize);    if (!GroupingBuffer) { lmon->grouping = NULL; return lmon; }    GetLocaleInfoA(lmon->lc.id, LOCALE_SGROUPING, GroupingBuffer, BufferSize);    __FixGrouping(GroupingBuffer);    lmon->grouping=GroupingBuffer;    __GetLocaleInfoUsingACP(lmon->lc.id, lmon->cp, LOCALE_SCURRENCY, lmon->curr_symbol, 6);    __GetLocaleInfoUsingACP(lmon->lc.id, lmon->cp, LOCALE_SNEGATIVESIGN, lmon->negative_sign, 5);    __GetLocaleInfoUsingACP(lmon->lc.id, lmon->cp, LOCALE_SPOSITIVESIGN, lmon->positive_sign, 5);    GetLocaleInfoA(lmon->lc.id, LOCALE_ICURRDIGITS, FracDigits, 3);    lmon->frac_digits = atoi(FracDigits);    GetLocaleInfoA(lmon->lc.id, LOCALE_IINTLCURRDIGITS, FracDigits, 3);    lmon->int_frac_digits = atoi(FracDigits);    __GetLocaleInfoUsingACP(lmon->lc.id, lmon->cp, LOCALE_SINTLSYMBOL, lmon->int_curr_symbol, 5);    /* Even if Platform SDK documentation says that the returned symbol should     * be a 3 letters symbol followed by a seperation character, experimentation     * has shown that no seperation character is ever appended. We are adding it     * ourself to conform to the POSIX specification.     */    if (lmon->int_curr_symbol[3] == 0) {      lmon->int_curr_symbol[3] = ' ';      lmon->int_curr_symbol[4] = 0;    }    return lmon;  }  void* _Locale_messages_create(const char *name, _Locale_lcid_t* lc_hint) {    char cname[_Locale_MAX_SIMPLE_NAME];    _Locale_messages_t *lmes=(_Locale_messages_t*)malloc(sizeof(_Locale_messages_t));    if (!lmes) return lmes;    memset(lmes, 0, sizeof(_Locale_messages_t));    _Locale_extract_messages_name(name, cname, lc_hint);    if (__GetLCIDFromName(cname, &lmes->lc.id, lmes->cp, lc_hint) == -1)    { free(lmes); return NULL; }    return lmes;  }  static const char* _Locale_common_default(char* buf) {    char cp[MAX_CP_LEN + 1];    int CodePage = __GetDefaultCP(LOCALE_USER_DEFAULT);    my_ltoa(CodePage, cp);    return __GetLocaleName(LOCALE_USER_DEFAULT, cp, buf);  }  const char* _Locale_ctype_default(char* buf)  { return _Locale_common_default(buf); }  const char* _Locale_numeric_default(char * buf)  { return _Locale_common_default(buf); }  const char* _Locale_time_default(char* buf)  { return _Locale_common_default(buf); }  const char* _Locale_collate_default(char* buf)  { return _Locale_common_default(buf); }  const char* _Locale_monetary_default(char* buf)  { return _Locale_common_default(buf); }  const char* _Locale_messages_default(char* buf)  { return _Locale_common_default(buf); }  char const* _Locale_ctype_name(const void* loc, char* buf) {    char cp_buf[MAX_CP_LEN + 1];    _Locale_ctype_t* ltype = (_Locale_ctype_t*)loc;    my_ltoa(ltype->cp, cp_buf);    return __GetLocaleName(ltype->lc.id, cp_buf, buf);  }  char const* _Locale_numeric_name(const void* loc, char* buf) {    _Locale_numeric_t* lnum = (_Locale_numeric_t*)loc;    return __GetLocaleName(lnum->lc.id, lnum->cp, buf);  }  char const* _Locale_time_name(const void* loc, char* buf) {    _Locale_time_t* ltime = (_Locale_time_t*)loc;    return __GetLocaleName(ltime->lc.id, ltime->cp, buf);  }  char const* _Locale_collate_name(const void* loc, char* buf) {    _Locale_collate_t* lcol = (_Locale_collate_t*)loc;    return __GetLocaleName(lcol->lc.id, lcol->cp, buf);  }  char const* _Locale_monetary_name(const void* loc, char* buf) {    _Locale_monetary_t* lmon = (_Locale_monetary_t*)loc;    return __GetLocaleName(lmon->lc.id, lmon->cp, buf);  }  char const* _Locale_messages_name(const void* loc, char* buf) {    _Locale_messages_t* lmes = (_Locale_messages_t*)loc;    return __GetLocaleName(lmes->lc.id, lmes->cp, buf);  }  void _Locale_ctype_destroy(void* loc) {    _Locale_ctype_t *ltype = (_Locale_ctype_t*)loc;    if (!ltype) return;    free(ltype);  }  void _Locale_numeric_destroy(void* loc) {    _Locale_numeric_t *lnum = (_Locale_numeric_t *)loc;    if (!lnum) return;    if (lnum->grouping) free(lnum->grouping);    free(lnum);  }  void _Locale_time_destroy(void* loc) {    int i;    _Locale_time_t* ltime = (_Locale_time_t*)loc;    if (!ltime) return;  for (i = 0; i < 12; ++i) {      if (ltime->month[i]) free(ltime->month[i]);      if (ltime->abbrev_month[i]) free(ltime->abbrev_month[i]);    }  for (i = 0; i < 7; ++i) {      if (ltime->dayofweek[i]) free(ltime->dayofweek[i]);      if (ltime->abbrev_dayofweek[i]) free(ltime->abbrev_dayofweek[i]);    }    if (ltime->date_format) free(ltime->date_format);    if (ltime->long_date_format) free(ltime->long_date_format);    if (ltime->time_format) free(ltime->time_format);    if (ltime->date_time_format) free(ltime->date_time_format);    if (ltime->long_date_time_format) free(ltime->long_date_time_format);    free(ltime);  }  void _Locale_collate_destroy(void* loc) {    _Locale_collate_t* lcol=(_Locale_collate_t*)loc;    if (!lcol) return;    free(lcol);  }  void _Locale_monetary_destroy(void* loc) {    _Locale_monetary_t *lmon = (_Locale_monetary_t*)loc;    if (!lmon) return;    if (lmon->grouping) free(lmon->grouping);    free(lmon);  }  void _Locale_messages_destroy(void* loc) {    _Locale_messages_t* lmes = (_Locale_messages_t*)loc;    if (!lmes) return;    free(lmes);  }  static char const* _Locale_extract_category_name(const char* cname, int category, char* buf, _Locale_lcid_t* hint) {    char lname[_Locale_MAX_SIMPLE_NAME];    __Extract_locale_name(cname, category, lname);    if (lname[0] == 'C' && lname[1] == 0) {      _STLP_RETURN_STRCPY2(buf, _Locale_MAX_SIMPLE_NAME, lname);    }    return __TranslateToSystem(lname, buf, hint);  }  char const* _Locale_extract_ctype_name(const char* cname, char* buf, _Locale_lcid_t* hint)  { return _Locale_extract_category_name(cname, LC_CTYPE, buf, hint); }  char const* _Locale_extract_numeric_name(const char* cname, char* buf, _Locale_lcid_t* hint)  { return _Locale_extract_category_name(cname, LC_NUMERIC, buf, hint); }  char const* _Locale_extract_time_name(const char* cname, char* buf, _Locale_lcid_t* hint)  { return _Locale_extract_category_name(cname, LC_TIME, buf, hint); }  char const* _Locale_extract_collate_name(const char* cname, char* buf, _Locale_lcid_t* hint)  { return _Locale_extract_category_name(cname, LC_COLLATE, buf, hint); }  char const* _Locale_extract_monetary_name(const char* cname, char* buf, _Locale_lcid_t* hint)  { return _Locale_extract_category_name(cname, LC_MONETARY, buf, hint); }  char const* _Locale_extract_messages_name(const char* cname, char* buf, _Locale_lcid_t* hint) {    if (cname[0] == 'L' && cname[1] == 'C' && cname[2] == '_') {      _STLP_RETURN_STRCPY2(buf, _Locale_MAX_SIMPLE_NAME, "C");    }    if (cname[0] == 'C' && cname[1] == 0) {      _STLP_RETURN_STRCPY2(buf, _Locale_MAX_SIMPLE_NAME, cname);    }    return __TranslateToSystem(cname, buf, hint);  }  char const* _Locale_compose_name(char* buf,                             const char* _ctype, const char* numeric,                             const char* time, const char* _collate,                             const char* monetary, const char* messages,                             const char* default_name) {    (void) default_name;    if (!strcmp(_ctype, numeric) &&       !strcmp(_ctype, time) &&       !strcmp(_ctype, _collate) &&       !strcmp(_ctype, monetary) &&       !strcmp(_ctype, messages)) {      _STLP_RETURN_STRCPY2(buf, _Locale_MAX_COMPOSITE_NAME, _ctype);    }    _STLP_STRCPY2(buf, _Locale_MAX_COMPOSITE_NAME, "LC_CTYPE=");    _STLP_STRCAT2(buf, _Locale_MAX_COMPOSITE_NAME, _ctype);    _STLP_STRCAT2(buf, _Locale_MAX_COMPOSITE_NAME, ";");    _STLP_STRCAT2(buf, _Locale_MAX_COMPOSITE_NAME, "LC_TIME=");    _STLP_STRCAT2(buf, _Locale_MAX_COMPOSITE_NAME, time);    _STLP_STRCAT2(buf, _Locale_MAX_COMPOSITE_NAME, ";");    _STLP_STRCAT2(buf, _Locale_MAX_COMPOSITE_NAME, "LC_NUMERIC=");    _STLP_STRCAT2(buf, _Locale_MAX_COMPOSITE_NAME, numeric);    _STLP_STRCAT2(buf, _Locale_MAX_COMPOSITE_NAME, ";");    _STLP_STRCAT2(buf, _Locale_MAX_COMPOSITE_NAME, "LC_COLLATE=");    _STLP_STRCAT2(buf, _Locale_MAX_COMPOSITE_NAME, _collate);    _STLP_STRCAT2(buf, _Locale_MAX_COMPOSITE_NAME, ";");    _STLP_STRCAT2(buf, _Locale_MAX_COMPOSITE_NAME, "LC_MONETARY=");    _STLP_STRCAT2(buf, _Locale_MAX_COMPOSITE_NAME, monetary);    _STLP_STRCAT2(buf, _Locale_MAX_COMPOSITE_NAME, ";");    _STLP_STRCAT2(buf, _Locale_MAX_COMPOSITE_NAME, "LC_MESSAGES=");    _STLP_STRCAT2(buf, _Locale_MAX_COMPOSITE_NAME, messages);    _STLP_STRCAT2(buf, _Locale_MAX_COMPOSITE_NAME, ";");    return buf;  }  /* ctype */  const _Locale_mask_t* _Locale_ctype_table(_Locale_ctype_t* ltype) {    _STLP_STATIC_ASSERT(sizeof(_Locale_mask_t) == sizeof(unsigned int))    return (const _Locale_mask_t*)ltype->ctable;  }  int _Locale_toupper(_Locale_ctype_t* ltype, int c) {    char buf[2], out_buf[2];    buf[0] = (char)c; buf[1] = 0;    if ((UINT)__GetDefaultCP(ltype->lc.id) == ltype->cp) {      LCMapStringA(ltype->lc.id, LCMAP_LINGUISTIC_CASING | LCMAP_UPPERCASE, buf, 2, out_buf, 2);      return out_buf[0];    }    else {      wchar_t wbuf[2];      MultiByteToWideChar(ltype->cp, MB_PRECOMPOSED, buf, 2, wbuf, 2);      WideCharToMultiByte(__GetDefaultCP(ltype->lc.id), WC_COMPOSITECHECK | WC_SEPCHARS, wbuf, 2, buf, 2, NULL, FALSE);      LCMapStringA(ltype->lc.id, LCMAP_LINGUISTIC_CASING | LCMAP_UPPERCASE, buf, 2, out_buf, 2);      MultiByteToWideChar(__GetDefaultCP(ltype->lc.id), MB_PRECOMPOSED, out_buf, 2, wbuf, 2);      WideCharToMultiByte(ltype->cp, WC_COMPOSITECHECK | WC_SEPCHARS, wbuf, 2, out_buf, 2, NULL, FALSE);      return out_buf[0];    }  }  int _Locale_tolower(_Locale_ctype_t* ltype, int c) {    char buf[2], out_buf[2];    buf[0] = (char)c; buf[1] = 0;    if ((UINT)__GetDefaultCP(ltype->lc.id) == ltype->cp) {      LCMapStringA(ltype->lc.id, LCMAP_LINGUISTIC_CASING | LCMAP_LOWERCASE, buf, 2, out_buf, 2);      return out_buf[0];    }    else {      wchar_t wbuf[2];      MultiByteToWideChar(ltype->cp, MB_PRECOMPOSED, buf, 2, wbuf, 2);      WideCharToMultiByte(__GetDefaultCP(ltype->lc.id), WC_COMPOSITECHECK | WC_SEPCHARS, wbuf, 2, buf, 2, NULL, FALSE);      LCMapStringA(ltype->lc.id, LCMAP_LINGUISTIC_CASING | LCMAP_LOWERCASE, buf, 2, out_buf, 2);      MultiByteToWideChar(__GetDefaultCP(ltype->lc.id), MB_PRECOMPOSED, out_buf, 2, wbuf, 2);      WideCharToMultiByte(ltype->cp, WC_COMPOSITECHECK | WC_SEPCHARS, wbuf, 2, out_buf, 2, NULL, FALSE);      return out_buf[0];    }  }#if !defined (_STLP_NO_WCHAR_T)  _Locale_mask_t _Locale_wchar_ctype(_Locale_ctype_t* ltype, wint_t c,                                     _Locale_mask_t which_bits) {    wchar_t buf[2];    WORD out[2];    buf[0] = c; buf[1] = 0;    GetStringTypeW(CT_CTYPE1, buf, -1, out);    (void*)ltype;    return (_Locale_mask_t)out[0] & which_bits;  }  wint_t _Locale_wchar_tolower(_Locale_ctype_t* ltype, wint_t c) {    wchar_t in_c = c;    wchar_t res;    LCMapStringW(ltype->lc.id, LCMAP_LOWERCASE, &in_c, 1, &res, 1);    return res;  }  wint_t _Locale_wchar_toupper(_Locale_ctype_t* ltype, wint_t c) {    wchar_t in_c = c;    wchar_t res;    LCMapStringW(ltype->lc.id, LCMAP_UPPERCASE, &in_c, 1, &res, 1);    return res;  }#endif#if !defined (_STLP_NO_MBSTATE_T)  int _Locale_mb_cur_max (_Locale_ctype_t * ltype) {    CPINFO CPInfo;    if (!GetCPInfo(ltype->cp, &CPInfo)) return 0;    return CPInfo.MaxCharSize;  }  int _Locale_mb_cur_min (_Locale_ctype_t *dummy) {    (void*)dummy;    return 1;  }  int _Locale_is_stateless (_Locale_ctype_t * ltype) {    CPINFO CPInfo;    GetCPInfo(ltype->cp, &CPInfo);    return (CPInfo.MaxCharSize == 1) ? 1 : 0;  }#if defined (__BORLANDC__) && defined (__cplusplus)  /* Weird Borland compiler behavior, even if native wint_t is imported to   * STLport namespace in _cwchar.h, wint_t is still usable when scoped with   * the Standard namespace (std::wint_t). As following WEOF macro is expended   * to (std::wint_t)(0xFFFF) compilation failed. Repeating import avoid this   * problem.*/  using __std_alias::wint_t;#endif  wint_t _Locale_btowc(_Locale_ctype_t * ltype, int c) {    wchar_t wc;    if (c == EOF) return WEOF;    MultiByteToWideChar(ltype->cp, MB_PRECOMPOSED, (char*)&c, 1, &wc, 1);    return (wint_t)wc;  }  int _Locale_wctob(_Locale_ctype_t * ltype, wint_t wc) {    char c;    if (WideCharToMultiByte(ltype->cp, WC_COMPOSITECHECK | WC_DEFAULTCHAR, (wchar_t*)&wc, 1, &c, 1, NULL, NULL) == 0)      return WEOF; /* Not single byte or error conversion. */    return (int)c;  }  static int __isleadbyte(int c, unsigned int *ctable) {    return (ctable[(unsigned char)(c)] & _LEADBYTE);  }  static size_t __mbtowc(_Locale_ctype_t *l, wchar_t *dst, char src, mbstate_t *shift_state) {    int result;    if (*shift_state == 0) {      if (__isleadbyte(src, l->ctable)) {        ((unsigned char*)shift_state)[0] = src;        return (size_t)-2;      }      else {        result = MultiByteToWideChar(l->cp, MB_PRECOMPOSED, &src, 1, dst, 1);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?