OSDN Git Service

[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)
commitfb27f55135bed1e993b58e849c1930268a64204c
tree7fa4bfdeb93ed54040c6d5aef99df71558966429
parent3abbc4d85486ad516b8c7dc73684e821f9d21cc3
[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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282164 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/ADT/StringRef.h
lib/Support/StringRef.cpp
unittests/ADT/StringRefTest.cpp