vin*_*yal 5 c linux string gcc
在Linux源代码中
tolower和topupper的实现如下实现
static inline unsigned char __tolower(unsigned char c)
{
if (isupper(c))
c -= 'A'-'a';
return c;
}
static inline unsigned char __toupper(unsigned char c)
{
if (islower(c))
c -= 'a'-'A';
return c;
}
Run Code Online (Sandbox Code Playgroud)
我可以使用XOR(^)按位运算,如下所示.
如果我使用xor操作,是否有任何潜在的Bug?
c -= 'A'-'a'; ----> c = c ^ 0x20 ; //using xor to convert to lower case to upper case and vice versa
Run Code Online (Sandbox Code Playgroud)