diff options
author | Daniel Dunbar <daniel@zuster.org> | 2011-11-06 18:04:43 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2011-11-06 18:04:43 +0000 |
commit | 589fbb1770df5f7bee1c5e24e9e8f4ca5091d528 (patch) | |
tree | f8709aafc090333009509372c0aaed069a9c0917 /lib/Support/StringRef.cpp | |
parent | cc4bcba0b9a819cd0ef5cb06a8b4972e3d6f8bf1 (diff) |
ADT/StringRef: Add ::lower() and ::upper() methods.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@143880 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/StringRef.cpp')
-rw-r--r-- | lib/Support/StringRef.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/Support/StringRef.cpp b/lib/Support/StringRef.cpp index 576b95f6a4..c78b6d0afc 100644 --- a/lib/Support/StringRef.cpp +++ b/lib/Support/StringRef.cpp @@ -25,6 +25,12 @@ static char ascii_tolower(char x) { return x; } +static char ascii_toupper(char x) { + if (x >= 'a' && x <= 'z') + return x - 'a' + 'A'; + return x; +} + static bool ascii_isdigit(char x) { return x >= '0' && x <= '9'; } @@ -132,6 +138,26 @@ unsigned StringRef::edit_distance(llvm::StringRef Other, } //===----------------------------------------------------------------------===// +// String Operations +//===----------------------------------------------------------------------===// + +std::string StringRef::lower() const { + std::string Result(size(), char()); + for (size_type i = 0, e = size(); i != e; ++i) { + Result[i] = ascii_tolower(Data[i]); + } + return Result; +} + +std::string StringRef::upper() const { + std::string Result(size(), char()); + for (size_type i = 0, e = size(); i != e; ++i) { + Result[i] = ascii_tolower(Data[i]); + } + return Result; +} + +//===----------------------------------------------------------------------===// // String Searching //===----------------------------------------------------------------------===// |