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 | 3fa528d67c9305cbf0edd7356dca333362d5a87a (patch) | |
tree | e8baca0d991ef64b7a878aa41d03625d7d861905 /llvm/lib/Support/StringRef.cpp | |
parent | 6b45852819f407a40f12d10e64d8170fc50c643a (diff) | |
download | bcm5719-llvm-3fa528d67c9305cbf0edd7356dca333362d5a87a.tar.gz bcm5719-llvm-3fa528d67c9305cbf0edd7356dca333362d5a87a.zip |
ADT/StringRef: Add ::lower() and ::upper() methods.
llvm-svn: 143880
Diffstat (limited to 'llvm/lib/Support/StringRef.cpp')
-rw-r--r-- | llvm/lib/Support/StringRef.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/lib/Support/StringRef.cpp b/llvm/lib/Support/StringRef.cpp index 576b95f6a4e..c78b6d0afc8 100644 --- a/llvm/lib/Support/StringRef.cpp +++ b/llvm/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 //===----------------------------------------------------------------------===// |