c_locale_dummy.c
来自「stl的源码」· C语言 代码 · 共 486 行 · 第 1/2 页
C
486 行
/* * Copyright (c) 1999 * Silicon Graphics Computer Systems, Inc. * * Copyright (c) 1999 * Boris Fomitchev * * This material is provided "as is", with absolutely no warranty expressed * or implied. Any use is at your own risk. * * Permission to use or copy this software for any purpose is hereby granted * without fee, provided the above notices are retained on all copies. * Permission to modify the code and to distribute modified code is granted, * provided the above notices are retained, and a notice that the code was * modified is included with the above copyright notice. * *//* This is a "stub" implementation of the "c_locale.h" interface, intended for operating systems where we have not yet written a real implementation. A C++ library using this stub implementation is still standard-conforming, since the C++ standard does not require that any locales other than "C" be supported.*/#include <string.h>#include <wchar.h>#include <ctype.h>#include <wctype.h>#include <limits.h>#if defined (_STLP_USE_SAFE_STRING_FUNCTIONS)# define _STLP_STRNCPY(D, DS, S, C) strncpy_s(D, DS, S, C)# if !defined (_STLP_NO_WCHAR_T)# define _STLP_WCSNCPY(D, DS, S, C) wcsncpy_s(D, DS, S, C)# endif#else# define _STLP_STRNCPY(D, DS, S, C) strncpy(D, S, C)# if !defined (_STLP_NO_WCHAR_T)# define _STLP_WCSNCPY(D, DS, S, C) wcsncpy(D, S, C)# endif#endifstatic const char *_C_name = "C";static const char *_empty_str = "";#ifndef _STLP_NO_WCHAR_Tstatic const wchar_t *_empty_wstr = L"";#endifstatic _Locale_mask_t ctable[256];/* Framework functions */void _Locale_init(void) { /* Ctype table for the ASCII character set. */ char c; /* We might never reach 128 when char is signed. */ for (c = 0; /* c != 128 */; ++c) { if (isalpha(c)) ctable[(unsigned char)c] |= _Locale_ALPHA; if (iscntrl(c)) ctable[(unsigned char)c] |= _Locale_CNTRL; if (isdigit(c)) ctable[(unsigned char)c] |= _Locale_DIGIT; if (isprint(c)) ctable[(unsigned char)c] |= _Locale_PRINT; if (ispunct(c)) ctable[(unsigned char)c] |= _Locale_PUNCT; if (isspace(c)) ctable[(unsigned char)c] |= _Locale_SPACE; if (isxdigit(c)) ctable[(unsigned char)c] |= _Locale_XDIGIT; if (isupper(c)) ctable[(unsigned char)c] |= _Locale_UPPER; if (islower(c)) ctable[(unsigned char)c] |= _Locale_LOWER; if (c == 127) break; } /* ASCII is a 7-bit code, so everything else is non-ASCII. */ memset(&(ctable[128]), 0, 128 * sizeof(_Locale_mask_t));}void _Locale_final(void){}void* _Locale_create(const char* name, int *__err_code) { if (name[0] == 'C' && name[1] == 0) { return (void*)0x1; } *__err_code = _STLP_LOC_NO_PLATFORM_SUPPORT; return 0;}struct _Locale_ctype* _Locale_ctype_create(const char *name, struct _Locale_name_hint* hint, int *__err_code){ return (struct _Locale_ctype*)_Locale_create(name, __err_code); }struct _Locale_codecvt* _Locale_codecvt_create(const char *name, struct _Locale_name_hint* hint, int *__err_code){ return (struct _Locale_codecvt*)_Locale_create(name, __err_code); }struct _Locale_numeric* _Locale_numeric_create(const char *name, struct _Locale_name_hint* hint, int *__err_code){ return (struct _Locale_numeric*)_Locale_create(name, __err_code); }struct _Locale_time* _Locale_time_create(const char *name, struct _Locale_name_hint* hint, int *__err_code){ return (struct _Locale_time*)_Locale_create(name, __err_code); }struct _Locale_collate* _Locale_collate_create(const char *name, struct _Locale_name_hint* hint, int *__err_code){ return (struct _Locale_collate*)_Locale_create(name, __err_code); }struct _Locale_monetary* _Locale_monetary_create(const char *name, struct _Locale_name_hint* hint, int *__err_code){ return (struct _Locale_monetary*)_Locale_create(name, __err_code); }struct _Locale_messages* _Locale_messages_create(const char *name, struct _Locale_name_hint* hint, int *__err_code){ return (struct _Locale_messages*)_Locale_create(name, __err_code); }const char *_Locale_ctype_default(char* buf) { return _C_name; }const char *_Locale_numeric_default(char * buf) { return _C_name; }const char *_Locale_time_default(char* buf) { return _C_name; }const char *_Locale_collate_default(char* buf) { return _C_name; }const char *_Locale_monetary_default(char* buf) { return _C_name; }const char *_Locale_messages_default(char* buf) { return _C_name; }char const* _Locale_ctype_name(const struct _Locale_ctype *lctype, char* buf){ return _C_name; }char const* _Locale_codecvt_name(const struct _Locale_codecvt *lcodecvt, char* buf){ return _C_name; }char const* _Locale_numeric_name(const struct _Locale_numeric *lnum, char* buf){ return _C_name; }char const* _Locale_time_name(const struct _Locale_time *ltime, char* buf){ return _C_name; }char const* _Locale_collate_name(const struct _Locale_collate *lcol, char* buf){ return _C_name; }char const* _Locale_monetary_name(const struct _Locale_monetary *lmon, char* buf){ return _C_name; }char const* _Locale_messages_name(const struct _Locale_messages *lmes, char* buf){ return _C_name; }void _Locale_ctype_destroy(struct _Locale_ctype *lctype) {}void _Locale_codecvt_destroy(struct _Locale_codecvt *lcodecvt) {}void _Locale_numeric_destroy(struct _Locale_numeric *lnum) {}void _Locale_time_destroy(struct _Locale_time *ltime) {}void _Locale_collate_destroy(struct _Locale_collate *lcol) {}void _Locale_monetary_destroy(struct _Locale_monetary *lmon) {}void _Locale_messages_destroy(struct _Locale_messages *lmes) {}static char const* _Locale_extract_name(const char* name, int *__err_code) { // When the request is the default locale or the "C" locale we answer "C". if (name[0] == 0 || (name[0] == 'C' && name[1] == 0)) { return _C_name; } *__err_code = _STLP_LOC_NO_PLATFORM_SUPPORT; return 0;}char const* _Locale_extract_ctype_name(const char *name, char *buf, struct _Locale_name_hint* hint, int *__err_code){ return _Locale_extract_name(name, __err_code); }char const* _Locale_extract_numeric_name(const char *name, char *buf, struct _Locale_name_hint* hint, int *__err_code){ return _Locale_extract_name(name, __err_code); }char const* _Locale_extract_time_name(const char*name, char *buf, struct _Locale_name_hint* hint, int *__err_code){ return _Locale_extract_name(name, __err_code); }char const* _Locale_extract_collate_name(const char *name, char *buf, struct _Locale_name_hint* hint, int *__err_code){ return _Locale_extract_name(name, __err_code); }char const* _Locale_extract_monetary_name(const char *name, char *buf, struct _Locale_name_hint* hint, int *__err_code){ return _Locale_extract_name(name, __err_code); }char const* _Locale_extract_messages_name(const char *name, char *buf, struct _Locale_name_hint* hint, int *__err_code){ return _Locale_extract_name(name, __err_code); }struct _Locale_name_hint* _Locale_get_ctype_hint(struct _Locale_ctype* ctype){ return 0; }struct _Locale_name_hint* _Locale_get_numeric_hint(struct _Locale_numeric* numeric){ return 0; }struct _Locale_name_hint* _Locale_get_time_hint(struct _Locale_time* time){ return 0; }struct _Locale_name_hint* _Locale_get_collate_hint(struct _Locale_collate* collate){ return 0; }struct _Locale_name_hint* _Locale_get_monetary_hint(struct _Locale_monetary* monetary){ return 0; }struct _Locale_name_hint* _Locale_get_messages_hint(struct _Locale_messages* messages){ return 0; }/* ctype */const _Locale_mask_t* _Locale_ctype_table(struct _Locale_ctype* lctype) { _STLP_MARK_PARAMETER_AS_UNUSED(lctype) return ctable;}int _Locale_toupper(struct _Locale_ctype*lctype, int c){ return toupper(c); }int _Locale_tolower(struct _Locale_ctype*lctype, int c){ return tolower(c); }#ifndef _STLP_NO_WCHAR_T_Locale_mask_t _WLocale_ctype(struct _Locale_ctype *lctype, wint_t wc, _Locale_mask_t mask) { _Locale_mask_t ret = 0; if ((mask & _Locale_ALPHA) != 0 && iswalpha(wc)) ret |= _Locale_ALPHA; if ((mask & _Locale_CNTRL) != 0 && iswcntrl(wc)) ret |= _Locale_CNTRL; if ((mask & _Locale_DIGIT) != 0 && iswdigit(wc)) ret |= _Locale_DIGIT; if ((mask & _Locale_PRINT) != 0 && iswprint(wc)) ret |= _Locale_PRINT; if ((mask & _Locale_PUNCT) != 0 && iswpunct(wc)) ret |= _Locale_PUNCT; if ((mask & _Locale_SPACE) != 0 && iswspace(wc)) ret |= _Locale_SPACE; if ((mask & _Locale_XDIGIT) != 0 && iswxdigit(wc)) ret |= _Locale_XDIGIT; if ((mask & _Locale_UPPER) != 0 && iswupper(wc)) ret |= _Locale_UPPER; if ((mask & _Locale_LOWER) != 0 && iswlower(wc)) ret |= _Locale_LOWER; return ret;}wint_t _WLocale_tolower(struct _Locale_ctype *lctype, wint_t wc){ return towlower(wc); }wint_t _WLocale_toupper(struct _Locale_ctype *lctype, wint_t wc){ return towupper(wc); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?