View Single Post
  #1  
Old 07-23-2024, 23:47
WhoCares's Avatar
WhoCares WhoCares is offline
who cares
 
Join Date: Jan 2002
Location: Here
Posts: 468
Rept. Given: 11
Rept. Rcvd 32 Times in 25 Posts
Thanks Given: 69
Thanks Rcvd at 247 Times in 94 Posts
WhoCares Reputation: 32
maybe a bug of Windows API PathMatchSpecW() ?

Consider the following code. PathMatchSpecW() is expected to do case-insensitive match(It seems that MS never documents this but it's true), so variable "matched" should be TRUE.

static const WCHAR pattern[] = L"的f";
const auto matched = PathMatchSpecW(L"的F", pattern);

But actually it is FALSE. Why?

I stepped into its asm code, it uses IsDBCSLeadByte(0x84) to check the first Chinese UTF-16 WCHAR '的'(0x7684), and IsDBCSLeadByte(0x84) returns TRUE for Chinese code page. Then it does case-sensitive comparison of 'f' and 'F', and finally returns FALSE.

I think it's WRONG to use IsDBCSLeadByte() for any byte of a UTF-16 string.
Perhaps MS guys add this logic to provide some compatibility with old weird strings?
__________________
AKA Solomon/blowfish.
Reply With Quote