[llvm-commits] [llvm] r78792 - in /llvm/trunk: include/llvm/ADT/Triple.h lib/Support/Triple.cpp

Chris Lattner clattner at apple.com
Wed Aug 12 20:50:26 PDT 2009


On Aug 12, 2009, at 7:53 PM, Daniel Dunbar wrote:

>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =====================================================================
>> +static unsigned EatNumber(StringRef &Str) {
>> +  assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a  
>> number");
>> +  unsigned Result = Str[0]-'0';
>> +
>> +  // Eat the digit.
>> +  Str = Str.substr(1);
>> +
>> +  // Handle "darwin11".
>> +  if (Result == 1 && !Str.empty() && Str[0] >= '0' && Str[0] <=  
>> '9') {
>> +    Result = Result*10 + (Str[0] - '0');
>> +    // Eat the digit.
>> +    Str = Str.substr(1);
>> +  }
>> +
>> +  return Result;
>> +}
>
> Would it make more sense to just add a StringRef::toInt, and use that?

This only handles two digit strings that start with 1, so it's not  
very general :).  I guess we could generalize it if there are other  
potential clients, but then you need to determine a return type,  
handle overflow, etc..

-Chris



More information about the llvm-commits mailing list