[llvm-commits] [llvm] r65236 - /llvm/trunk/include/llvm/ADT/StringExtras.h
Cédric Venet
cedric.venet at laposte.net
Sat Feb 21 12:45:34 PST 2009
Nick Lewycky a écrit :
> Ted Kremenek wrote:
>
>> Author: kremenek
>> Date: Sat Feb 21 12:25:30 2009
>> New Revision: 65236
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=65236&view=rev
>> Log:
>> Add version of StringsEqualNoCase that takes two null-terminated C-strings and compares up to 'len' characters. I tend to screw up string comparison functions, so anyone who is interested please review this\!
>>
>
> According to my man pages, strncasecmp is defined in POSIX.1-2001. Does
> it not exist on any platform you're interested in?
>
>
Not on windows, at least not with VS2008. In fact, the function exist
but is named _strnicmp . Blame M$ for not following POSIX...
Note: Clang use this function, so this is needed to unbreak the build.
>> Modified:
>> llvm/trunk/include/llvm/ADT/StringExtras.h
>>
>> Modified: llvm/trunk/include/llvm/ADT/StringExtras.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringExtras.h?rev=65236&r1=65235&r2=65236&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/include/llvm/ADT/StringExtras.h (original)
>> +++ llvm/trunk/include/llvm/ADT/StringExtras.h Sat Feb 21 12:25:30 2009
>> @@ -159,6 +159,25 @@
>> }
>> return RHS[LHS.size()] == 0; // Not too long?
>> }
>> +
>> +/// StringsEqualNoCase - Return true if the two null-terminated C strings are
>> +/// equal, ignoring
>>
>
> Finish this sentence.
>
>
>> +
>> +static inline bool StringsEqualNoCase(const char *LHS, const char *RHS,
>> + unsigned len) {
>> +
>> + for (unsigned i = 0; i < len; ++i) {
>> + if (tolower(LHS[i]) != tolower(RHS[i]))
>> + return false;
>> +
>> + // If RHS[i] == 0 then LHS[i] == 0 or otherwise we would have returned
>> + // at the previous branch as tolower('\0') == '\0'.
>> + if (RHS[i] == 0)
>> + return true;
>> + }
>> +
>> + return true;
>> +}
>>
>
> That looks correct to me.
>
> Nick
>
>
>> /// CStrInCStrNoCase - Portable version of strcasestr. Locates the first
>> /// occurance of c-string 's2' in string 's1', ignoring case. Returns
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
More information about the llvm-commits
mailing list