📄 wstring.c
字号:
#endif/**********************************************************************/#ifdef L_wcsncat#define L_strncat#define Wstrncat wcsncat#else#define Wstrncat strncat#endif#ifdef L_strncatWchar *Wstrncat(Wchar * __restrict s1, register const Wchar * __restrict s2, size_t n){ register Wchar *s = s1; while (*s++); --s;#if __BCC__ while (n-- && ((*s = *s2++) != 0)) ++s;#else while (n && ((*s = *s2++) != 0)) { --n; ++s; }#endif *s = 0; return s1;}#endif/**********************************************************************/#ifdef L_wmemcmp#define L_memcmp#define Wmemcmp wmemcmp#else#define Wmemcmp memcmp#endif#ifdef L_memcmp#ifndef L_wmemcmpweak_alias(memcmp,bcmp);#endifint Wmemcmp(const Wvoid *s1, const Wvoid *s2, size_t n){ register const Wuchar *r1 = (const Wuchar *) s1; register const Wuchar *r2 = (const Wuchar *) s2;#ifdef WANT_WIDE while (n && (*r1 == *r2)) { ++r1; ++r2; --n; } return (n == 0) ? 0 : ((*r1 < *r2) ? -1 : 1);#else int r = 0; while (n-- && ((r = ((int)(*r1++)) - *r2++) == 0)); return r;#endif}#endif/**********************************************************************/#ifdef L_wcscmp#define L_strcmp#define Wstrcmp wcscmp#else#define Wstrcmp strcmp#endif#ifdef L_strcmp#ifdef __LOCALE_C_ONLY#ifdef L_wcscmpweak_alias(wcscmp,wcscoll);#else /* L_wcscmp */weak_alias(strcmp,strcoll);#endif /* L_wcscmp */#endif /* __LOCALE_C_ONLY */int Wstrcmp(register const Wchar *s1, register const Wchar *s2){#ifdef WANT_WIDE while (*((Wuchar *)s1) == *((Wuchar *)s2)) { if (!*s1++) { return 0; } ++s2; } return (*((Wuchar *)s1) < *((Wuchar *)s2)) ? -1 : 1;#else int r; while (((r = ((int)(*((Wuchar *)s1))) - *((Wuchar *)s2++)) == 0) && *s1++); return r;#endif}#endif/**********************************************************************/#ifdef L_wcsncmp#define L_strncmp#define Wstrncmp wcsncmp#else#define Wstrncmp strncmp#endif#ifdef L_strncmpint Wstrncmp(register const Wchar *s1, register const Wchar *s2, size_t n){#ifdef WANT_WIDE while (n && (*((Wuchar *)s1) == *((Wuchar *)s2))) { if (!*s1++) { return 0; } ++s2; --n; } return (n == 0) ? 0 : ((*((Wuchar *)s1) < *((Wuchar *)s2)) ? -1 : 1);#else int r = 0; while (n-- && ((r = ((int)(*((unsigned char *)s1))) - *((unsigned char *)s2++)) == 0) && *s1++); return r;#endif}#endif/**********************************************************************/#ifdef L_wmemchr#define L_memchr#define Wmemchr wmemchr#else#define Wmemchr memchr#endif#ifdef L_memchrWvoid *Wmemchr(const Wvoid *s, Wint c, size_t n){ register const Wuchar *r = (const Wuchar *) s;#ifdef __BCC__ /* bcc can optimize the counter if it thinks it is a pointer... */ register const char *np = (const char *) n;#else#define np n#endif while (np) { if (*r == ((Wuchar)c)) { return (Wvoid *) r; /* silence the warning */ } ++r; --np; } return NULL;}#undef np#endif/**********************************************************************/#ifdef L_wcschr#define L_strchr#define Wstrchr wcschr#else#define Wstrchr strchr#endif#ifdef L_strchr#ifndef L_wcschrweak_alias(strchr,index);#endifWchar *Wstrchr(register const Wchar *s, Wint c){ do { if (*s == ((Wchar)c)) { return (Wchar *) s; /* silence the warning */ } } while (*s++); return NULL;}#endif/**********************************************************************/#ifdef L_wcscspn#define L_strcspn#define Wstrcspn wcscspn#else#define Wstrcspn strcspn#endif#ifdef L_strcspnsize_t Wstrcspn(const Wchar *s1, const Wchar *s2){ register const Wchar *s; register const Wchar *p; for ( s=s1 ; *s ; s++ ) { for ( p=s2 ; *p ; p++ ) { if (*p == *s) goto done; } } done: return s - s1;}#endif/**********************************************************************/#ifdef L_wcspbrk#define L_strpbrk#define Wstrpbrk wcspbrk#else#define Wstrpbrk strpbrk#endif#ifdef L_strpbrkWchar *Wstrpbrk(const Wchar *s1, const Wchar *s2){ register const Wchar *s; register const Wchar *p; for ( s=s1 ; *s ; s++ ) { for ( p=s2 ; *p ; p++ ) { if (*p == *s) return (Wchar *) s; /* silence the warning */ } } return NULL;}#endif/**********************************************************************/#ifdef L_wcsrchr#define L_strrchr#define Wstrrchr wcsrchr#else#define Wstrrchr strrchr#endif#ifdef L_strrchr#ifndef L_wcsrchrweak_alias(strrchr,rindex);#endifWchar *Wstrrchr(register const Wchar *s, Wint c){ register const Wchar *p; p = NULL; do { if (*s == (Wchar) c) { p = s; } } while (*s++); return (Wchar *) p; /* silence the warning */}#endif/**********************************************************************/#ifdef L_wcsspn#define L_strspn#define Wstrspn wcsspn#else#define Wstrspn strspn#endif#ifdef L_strspnsize_t Wstrspn(const Wchar *s1, const Wchar *s2){ register const Wchar *s = s1; register const Wchar *p = s2; while (*p) { if (*p++ == *s) { ++s; p = s2; } } return s - s1;}#endif/**********************************************************************/#ifdef L_wcsstr#define L_strstr#define Wstrstr wcsstr#else#define Wstrstr strstr#endif#ifdef L_strstr/* NOTE: This is the simple-minded O(len(s1) * len(s2)) worst-case approach. */#ifdef L_wcsstrweak_alias(wcsstr,wcswcs);#endifWchar *Wstrstr(const Wchar *s1, const Wchar *s2){ register const Wchar *s = s1; register const Wchar *p = s2; do { if (!*p) { return (Wchar *) s1;; } if (*p == *s) { ++p; ++s; } else { p = s2; if (!*s) { return NULL; } s = ++s1; } } while (1);}#endif/**********************************************************************/#undef Wstrspn#undef Wstrpbrk#ifdef L_wcstok#define L_strtok_r#define Wstrtok_r wcstok#define Wstrspn wcsspn#define Wstrpbrk wcspbrk#else#define Wstrtok_r __strtok_r#define Wstrspn strspn#define Wstrpbrk strpbrk#endif#ifdef L_strtok_r#ifndef L_wcstokweak_alias(__strtok_r,strtok_r);#endifWchar *Wstrtok_r(Wchar * __restrict s1, const Wchar * __restrict s2, Wchar ** __restrict next_start){ register Wchar *s; register Wchar *p;#if 1 if (((s = s1) != NULL) || ((s = *next_start) != NULL)) { if (*(s += Wstrspn(s, s2))) { if ((p = Wstrpbrk(s, s2)) != NULL) { *p++ = 0; } } else { p = s = NULL; } *next_start = p; } return s;#else if (!(s = s1)) { s = *next_start; } if (s && *(s += Wstrspn(s, s2))) { if (*(p = s + Wstrcspn(s, s2))) { *p++ = 0; } *next_start = p; return s; } return NULL; /* TODO: set *next_start = NULL for safety? */#endif}#endif/**********************************************************************//* #ifdef L_wcstok *//* #define L_strtok *//* #define Wstrtok wcstok *//* #define Wstrtok_r wcstok_r *//* #else *//* #define Wstrtok strtok *//* #define Wstrtok_r strtok_r *//* #endif */#ifdef L_strtok#define Wstrtok strtok#define Wstrtok_r __strtok_rWchar *Wstrtok(Wchar * __restrict s1, const Wchar * __restrict s2){ static Wchar *next_start; /* Initialized to 0 since in bss. */ return Wstrtok_r(s1, s2, &next_start);}#endif/**********************************************************************/#ifdef L_wmemset#define L_memset#define Wmemset wmemset#else#define Wmemset memset#endif#ifdef L_memsetWvoid *Wmemset(Wvoid *s, Wint c, size_t n){ register Wuchar *p = (Wuchar *) s;#ifdef __BCC__ /* bcc can optimize the counter if it thinks it is a pointer... */ register const char *np = (const char *) n;#else#define np n#endif while (np) { *p++ = (Wuchar) c; --np; } return s;}#undef np#endif/**********************************************************************/#ifdef L_wcslen#define L_strlen#define Wstrlen wcslen#else#define Wstrlen strlen#endif#ifdef L_strlensize_t Wstrlen(const Wchar *s){ register const Wchar *p; for (p=s ; *p ; p++); return p - s;}#endif/**********************************************************************//* ANSI/ISO end here *//**********************************************************************/#ifdef L_ffsint ffs(int i){#if 1 /* inlined binary search method */ char n = 1;#if UINT_MAX == 0xffffU /* nothing to do here -- just trying to avoiding possible problems */#elif UINT_MAX == 0xffffffffU if (!(i & 0xffff)) { n += 16; i >>= 16; }#else#error ffs needs rewriting!#endif if (!(i & 0xff)) { n += 8; i >>= 8; } if (!(i & 0x0f)) { n += 4; i >>= 4; } if (!(i & 0x03)) { n += 2; i >>= 2; } return (i) ? (n + ((i+1) & 0x01)) : 0;#else /* linear search -- slow, but small */ int n; for (n = 0 ; i ; ++n) { i >>= 1; } return n;#endif}#endif/**********************************************************************/#if defined(L_strcasecmp) || defined(L_strcasecmp_l) || defined(L_wcscasecmp) || defined(L_wcscasecmp_l)#if defined(L_wcscasecmp) || defined(L_wcscasecmp_l)#define strcasecmp wcscasecmp#define strcasecmp_l wcscasecmp_l#define __strcasecmp_l __wcscasecmp_l#ifdef __UCLIBC_DO_XLOCALE#define TOLOWER(C) __towlower_l((C), locale_arg)#else#define TOLOWER(C) towlower((C))#endif#else /* defined(L_wcscasecmp) || defined(L_wcscasecmp_l) */#ifdef __UCLIBC_DO_XLOCALE#define TOLOWER(C) __tolower_l((C), locale_arg)#else#define TOLOWER(C) tolower((C))#endif#endif /* defined(L_wcscasecmp) || defined(L_wcscasecmp_l) */#if defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE)int strcasecmp(register const Wchar *s1, register const Wchar *s2){ return __strcasecmp_l(s1, s2, __UCLIBC_CURLOCALE);}#else /* defined(__UCLIBC_HAS_XLOCALE__) && !defined(__UCLIBC_DO_XLOCALE) */int __XL(strcasecmp)(register const Wchar *s1, register const Wchar *s2 __LOCALE_PARAM ){#ifdef WANT_WIDE while ((*s1 == *s2) || (TOLOWER(*s1) == TOLOWER(*s2))) { if (!*s1++) { return 0; } ++s2; } return (((Wuchar)TOLOWER(*s1)) < ((Wuchar)TOLOWER(*s2))) ? -1 : 1; /* TODO -- should wide cmp funcs do wchar or Wuchar compares? */#else int r = 0; while ( ((s1 == s2) || !(r = ((int)( TOLOWER(*((Wuchar *)s1)))) - TOLOWER(*((Wuchar *)s2))))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -