?
? ????? PHP ??? ???? ??? ?? ??
在頭文件<stdlib.h>中定義 | ||
---|---|---|
(1) | ||
size_t mbstowcs(wchar_t * dst,const char * src,size_t len) | (直到C99) | |
size_t mbstowcs(wchar_t * restrict dst,const char * restrict src,size_t len) | (自C99以來(lái)) | |
errno_t mbstowcs_s(size_t * restrict retval,wchar_t * restrict dst,rsize_t dstsz,const char * restrict src,rsize_t len); | (2) | (自C11以來(lái)) |
1)將多字節(jié)字符串從第一個(gè)元素被src指向的數(shù)組轉(zhuǎn)換為寬字符表示形式。 轉(zhuǎn)換后的字符存儲(chǔ)在由dst指向的數(shù)組的連續(xù)元素中。 不超過(guò)len的寬字符被寫入目標(biāo)數(shù)組。
除了mbtowc轉(zhuǎn)換狀態(tài)不受影響之外,每個(gè)字符都轉(zhuǎn)換為像通過(guò)調(diào)用mbtowc一樣。 在下列情況下停止轉(zhuǎn)換:
*多字節(jié)空字符已轉(zhuǎn)換并存儲(chǔ)。
*遇到無(wú)效(在當(dāng)前C語(yǔ)言環(huán)境中)多字節(jié)字符。
*要存儲(chǔ)的下一個(gè)寬字符將超過(guò)len
。
如果src
和dst
重疊,行為是不確定的
2)與(1)相同,除以下情況:
*通過(guò)mbrtowc轉(zhuǎn)換為as-if,而非mbtowc
*該函數(shù)將其結(jié)果作為out參數(shù)返回 retval
*如果寫完len寬字符后沒(méi)有空字符寫入dst,則L'\ 0'存儲(chǔ)在dst [len]中,這意味著寫入len + 1總寬字符
*如果dst是一個(gè)空指針,將產(chǎn)生的寬字符數(shù)存儲(chǔ)在* retval中
*該函數(shù)從終止空值到dstsz之間破壞目標(biāo)數(shù)組
*如果src
和dst
重疊,行為是未指定的。
*在運(yùn)行時(shí)檢測(cè)到以下錯(cuò)誤并調(diào)用當(dāng)前安裝的約束處理函數(shù):
retval或src是一個(gè)空指針
dstsz或len大于RSIZE_MAX / sizeof(wchar_t)(除非dst為空)
dstsz不為零(除非dst為空)
src數(shù)組中的第一個(gè)dstsz多字節(jié)字符中沒(méi)有空字符,并且len大于dstsz(除非dst為空)
作為所有邊界檢查函數(shù),只有當(dāng)__STDC_LIB_EXT1__由實(shí)現(xiàn)定義并且在包含stdlib.h之前用戶將__STDC_WANT_LIB_EXT1__定義為整數(shù)常量1時(shí),mbstowcs_s才能保證可用。
在大多數(shù)實(shí)現(xiàn)中,mbstowcs在處理整個(gè)字符串時(shí)更新一個(gè)類型為mbstate_t的全局靜態(tài)對(duì)象,并且不能由兩個(gè)線程同時(shí)調(diào)用,在這種情況下應(yīng)該使用mbsrtowcs。
POSIX指定一個(gè)公共擴(kuò)展名:如果dst是空指針,則該函數(shù)返回將被寫入dst的寬字符數(shù)(如果轉(zhuǎn)換)。 對(duì)于mbstowcs_s和mbsrtowcs,類似的行為是標(biāo)準(zhǔn)的。
dst | - | 寬字符串將被存儲(chǔ)的寬字符數(shù)組指針 |
---|---|---|
src | - | 指向要轉(zhuǎn)換的以空字符結(jié)尾的多字節(jié)字符串的第一個(gè)元素的指針 |
len | - | 由dst指向的數(shù)組中可用的寬字符數(shù) |
dstsz | - | 將寫入的最大寬字符數(shù)(dst數(shù)組的大小) |
retval | - | 指向?qū)⒋鎯?chǔ)結(jié)果的size_t對(duì)象的指針 |
1)成功時(shí),返回寫入目標(biāo)數(shù)組的寬字符數(shù)(不包括終止的L'\ 0)。 在轉(zhuǎn)換錯(cuò)誤(如果遇到無(wú)效多字節(jié)字符)時(shí),返回(size_t)-1。
2)成功時(shí)為零(在這種情況下,不包括終止零的寬字符的數(shù)量已經(jīng)或?qū)⒈粚懭雂st,存儲(chǔ)在* retval中),非錯(cuò)誤發(fā)生。 在違反運(yùn)行時(shí)約束的情況下,* retval中的stores(size_t)-1(除非retval為null)并將dst [0]設(shè)置為L(zhǎng)'\ 0'(除非dst為null或dstmax為零或大于RSIZE_MAX)
#include <stdio.h>#include <locale.h>#include <stdlib.h>#include <wchar.h> int main(void){ setlocale(LC_ALL, "en_US.utf8"); const char* mbstr = u8"z\u00df\u6c34\U0001F34C"; // or u8"z?水?" wchar_t wstr[5]; mbstowcs(wstr, mbstr, 5); wprintf(L"MB string: %s\n", mbstr); wprintf(L"Wide string: %ls\n", wstr);}
輸出:
MB string: z?水?Wide string: z?水?
C11標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.22.8.1 mbstowcs函數(shù)(p:359)
K.3.6.5.1 mbstowcs_s函數(shù)(p:611-612)
C99標(biāo)準(zhǔn)(ISO / IEC 9899:1999):
7.20.8.1 mbstowcs函數(shù)(p:323)
C89 / C90標(biāo)準(zhǔn)(ISO / IEC 9899:1990):
4.10.8.1 mbstowcs函數(shù)
mbsrtowcsmbsrtowcs_s(C95)(C11) | 將一個(gè)窄多字節(jié)字符串轉(zhuǎn)換為寬字符串,給定狀態(tài)(函數(shù)) |
---|---|
wcstombswcstombs_s(C11) | 將寬字符串轉(zhuǎn)換為窄多字節(jié)字符串(函數(shù)) |
| mbstowcs的C ++文檔 |
本文檔系騰訊云云+社區(qū)成員共同維護(hù),如有問(wèn)題請(qǐng)聯(lián)系 yunjia_community@tencent.com
在頭文件<wctype.h>中定義 | ||
---|---|---|
int iswdigit(wint_t ch); | (自C95以來(lái)) |
檢查給定的寬字符是否對(duì)應(yīng)(如果縮?。┦畟€(gè)十進(jìn)制數(shù)字字符0123456789中的一個(gè)。
CH | - | 寬字符 |
---|
如果寬字符是數(shù)字字符,則為非零值,否則為零。
iswdigit
與iswxdigit
是唯一不受當(dāng)前安裝的C語(yǔ)言環(huán)境影響的標(biāo)準(zhǔn)寬字符分類函數(shù)。
一些語(yǔ)言環(huán)境提供了檢測(cè)非ASCII數(shù)字的附加字符類。
#include <stdio.h>#include <wctype.h>#include <wchar.h>#include <locale.h> void test(wchar_t a3, wchar_t u3, wchar_t j3){ printf(" '%lc' '%lc' '%lc'\n", a3, u3, j3); printf("iswdigit %d %d %d\n", !!iswdigit(a3), !!iswdigit(u3), !!iswdigit(j3)); printf("jdigit: %d %d %d\n", !!iswctype(a3, wctype("jdigit")), !!iswctype(u3, wctype("jdigit")), !!iswctype(j3, wctype("jdigit")));} int main(void){ wchar_t a3 = L'3'; // the ASCII digit 3 wchar_t u3 = L'三'; // the CJK numeral 3 wchar_t j3 = L'3'; // the fullwidth digit 3 setlocale(LC_ALL, "en_US.utf8"); puts("In American locale:"); test(a3, u3, j3); setlocale(LC_ALL, "ja_JP.utf8"); puts("\nIn Japanese locale:"); test(a3, u3, j3);}
輸出:
In American locale: '3' '三' '3'iswdigit 1 0 0jdigit: 0 0 0 In Japanese locale: '3' '三' '3'iswdigit 1 0 0jdigit: 0 0 1
C11標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.30.2.1.5 iswdigit函數(shù)(p:449)
C99標(biāo)準(zhǔn)(ISO / IEC 9899:1999):
7.25.2.1.5 iswdigit函數(shù)(p:395)
isdigit | 檢查一個(gè)字符是否是一個(gè)數(shù)字(功能) |
---|
| 用于iswdigit的C ++文檔 |
ASCII 值 (十六進(jìn)制) | 字符 | iscntrl iswcntrl. | isprint iswprint. | isspace iswspace. | isblank iswblank. | isgraph iswgraph. | ispunct iswpunct. | isalnum iswalnum. | isalpha iswalpha. | isupper iswupper. | islower iswlower. | isdigit iswdigit. | isxdigit iswxdigit. | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 - 8 | 0x00-0x08 | 控制碼 (NUL, etc.) | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
9 | 0x09 | tab (\t) | ≠0 | 0 | ≠0 | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
10 - 13 | 0x0A-0x0D | 空格 (\n,\v,\f,\r) | ≠0 | 0 | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
14 - 31 | 0x0E-0x1F | 控制碼 | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
32 | 0x20 | space | 0 | ≠0 | ≠0 | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
33 - 47 | 0x21-0x2F | !"#$%&'()*+,-./ | 0 | ≠0 | 0 | 0 | ≠0 | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 |
48 - 57 | 0x30-0x39 | 0123456789 | 0 | ≠0 | 0 | 0 | ≠0 | 0 | ≠0 | 0 | 0 | 0 | ≠0 | ≠0 |
58 - 64 | 0x3a-0x40 | :;<=>?@ | 0 | ≠0 | 0 | 0 | ≠0 | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 |
65 - 70 | 0x41-0x46 | ABCDEF | 0 | ≠0 | 0 | 0 | ≠0 | 0 | ≠0 | ≠0 | ≠0 | 0 | 0 | ≠0 |
71 - 90 | 0x47-0x5A | GHIJKLMNOPQRSTUVWXYZ | 0 | ≠0 | 0 | 0 | ≠0 | 0 | ≠0 | ≠0 | ≠0 | 0 | 0 | 0 |
91 - 96 | 0x5B-0x60 | []^_` | 0 | ≠0 | 0 | 0 | ≠0 | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 | | ||||||||||||
97 -102 | 0x61-0x66 | abcdef | 0 | ≠0 | 0 | 0 | ≠0 | 0 | ≠0 | ≠0 | 0 | ≠0 | 0 | ≠0 |
103-122 | 0x67-0x7A | ghijklmnopqrstuvwxyz | 0 | ≠0 | 0 | 0 | ≠0 | 0 | ≠0 | ≠0 | 0 | ≠0 | 0 | 0 |
123-126 | 0x7B-0x7E | {|}~ | 0 | ≠0 | 0 | 0 | ≠0 | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 |
127 | 0x7F | 退格 (DEL) | ≠0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |