iswctype ()- 测试字符属性

格式

#include <wctype.h>
int iswctype(wint_t wc, wctype_t wc_prop);

语言级别

ANSI

线程安全

语言环境敏感

如果在编译命令上指定了 LOCALETYPE (*LOCALE) ,那么此函数的行为可能受当前语言环境的 LC_CTYPE 类别影响。 如果在编译命令中指定了 LOCALETYPE (*LOCALEUCS2) 选项或 LOCALETYPE (*LOCALEUTF) 选项,那么此函数的行为可能受当前语言环境的 LC_UNI_CTYPE 类别影响。 当在编译命令上指定 LOCALETYPE (*CLD) 时,此功能不可用。 有关更多信息,请参阅 了解 CCSID 和语言环境

宽字符函数

有关更多信息,请参阅 宽字符

描述

iswctype() 函数确定宽字符 wc 是否具有属性 wc_prop。 如果 wc 的值既不是 WEOF ,也不是对应于多字节字符的宽字符的任何值,那么行为未定义。 如果 wc_prop 的值不正确 (即,先前对 wctype() 函数的调用未获取该值,或者后续对 setlocale() 函数的调用已使 wc_prop 失效) ,那么未定义该行为。

返回值

如果宽字符 wc 的值具有属性 wc_prop,那么 iswctype() 函数将返回 true。

以下字符串 (alnum 到 xdigit) 保留给标准字符类。 函数及其等效的 isw * () 函数如下所示:
iswctype(wc, wctype("alnum"));     /* is equivalent to */        iswalnum(wc);
iswctype(wc, wctype("alpha"));     /* is equivalent to */        iswalpha(wc);
iswctype(wc, wctype("blank"));     /* is equivalent to */        iswblank(wc);
iswctype(wc, wctype("cntrl"));     /* is equivalent to */        iswcntrl(wc);
iswctype(wc, wctype("digit"));     /* is equivalent to */        iswdigit(wc);
iswctype(wc, wctype("graph"));     /* is equivalent to */        iswgraph(wc);
iswctype(wc, wctype("lower"));     /* is equivalent to */        iswlower(wc);
iswctype(wc, wctype("print"));     /* is equivalent to */        iswprint(wc);
iswctype(wc, wctype("punct"));     /* is equivalent to */        iswpunct(wc);
iswctype(wc,wctype("space"));      /* is equivalent to */        iswspace(wc);
iswctype(wc, wctype("upper"));     /* is equivalent to */        iswupper(wc);
iswctype(wc, wctype("xdigit"));    /* is equivalent to */        iswxdigit(wc);

示例

#include <stdio.h>
#include <wctype.h>
 
int main(void)
{
   int wc;
 
   for (wc=0; wc <= 0xFF; wc++) {
      printf("%3d", wc);
      printf(" %#4x ", wc);
      printf("%3s", iswctype(wc, wctype("alnum"))  ? "AN" : " ");
      printf("%2s", iswctype(wc, wctype("alpha"))  ? "A"  : " ");
      printf("%2s", iswctype(wc, wctype("blank"))  ? "B"  : " ");
      printf("%2s", iswctype(wc, wctype("cntrl"))  ? "C"  : " ");
      printf("%2s", iswctype(wc, wctype("digit"))  ? "D"  : " ");
      printf("%2s", iswctype(wc, wctype("graph"))  ? "G"  : " ");
      printf("%2s", iswctype(wc, wctype("lower"))  ? "L"  : " ");
      printf(" %c", iswctype(wc, wctype("print"))  ? wc   : ' ');
      printf("%3s", iswctype(wc, wctype("punct"))  ? "PU" : " ");
      printf("%2s", iswctype(wc, wctype("space"))  ? "S"  : " ");
      printf("%3s", iswctype(wc, wctype("print"))  ? "PR" : " ");
      printf("%2s", iswctype(wc, wctype("upper"))  ? "U"  : " ");
      printf("%2s", iswctype(wc, wctype("xdigit")) ? "X"  : " ");
 
      putchar('\n');
   }
}

相关信息