[Support] Add StringRef::consumeInteger.
authorZachary Turner <zturner@google.com>
Thu, 22 Sep 2016 15:05:19 +0000 (15:05 +0000)
committerZachary Turner <zturner@google.com>
Thu, 22 Sep 2016 15:05:19 +0000 (15:05 +0000)
commit65fd2fc7b407ca9dafc1b0a87df281b38e2eefb0
tree79114f29c97d9e383c6ccefb5a090c5b7797eebf
parent7f0e3153270d21d7931a18c2c0d4a2791103b52d
[Support] Add StringRef::consumeInteger.

StringRef::getInteger() exists and treats the entire string as
an integer of the specified radix, failing if any invalid characters
are encountered or the number overflows.

Sometimes you might have something like "123456foo" and you want
to get the number 123456 and leave the string "foo" remaining.
This is similar to what would be possible by using the standard
runtime library functions strtoul et al and specifying an end
pointer.

This patch adds consumeInteger(), which does exactly that.  It
consumes as much as possible until an invalid character is found,
and modifies the StringRef in place so that upon return only
the portion of the StringRef after the number remains.

Differential Revision: https://reviews.llvm.org/D24778

llvm-svn: 282164
llvm/include/llvm/ADT/StringRef.h
llvm/lib/Support/StringRef.cpp
llvm/unittests/ADT/StringRefTest.cpp