开发者

tchar safe functions -- count parameter for UTF-8 constants

I'm porting a library from char to TCHAR. the count parameter of this fragment, according to MSDN, is the number of multibyte characters, not the number of bytes. so,开发者_开发问答 did I get this right? My project properties in VC9 say 'use unicode character set' and I think that's correct, but I'm not how that impacts my count parameter.

_tcsncmp(access, TEXT("ftp"), 3); //or do i want _tcsnccmp?

"Supported on Windows platforms only, _mbsncmp and _mbsnbcmp are multibyte versions of strncmp. _mbsncmp will compare at most count multibyte characters and _mbsnbcmp will compare at most count bytes. They both use the current multibyte code page.

_tcsnccmp and _tcsncmp are the corresponding Generic functions for _mbsncmp and _mbsnbcmp, respectively. _tccmp is equivalent to _tcsnccmp."

A similar question is _tcslen vs _tcsclen.


Yes, you get it right.

The question, however, is why do you port it to TCHAR - something that is sensitive to _UNICODE define.

Why not use UTF8 and char*?


TCHAR is a type that's either 8 or 16 bits depending on whether _UNICODE is defined. But UTF-8 always uses 8-bit code units, so using TCHAR is silly. Just use char.

TCHAR is tied to the existence of two versions of the Windows API: "A" functions that use legacy 8-bit code pages, and "W" functions that use UTF-16. UTF-8 is not supported. You can use UTF-8 on Windows by explicitly converting your UTF-8 strings to UTF-16 for API calls, but you won't get any help from _UNICODE or TCHAR.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜