[llvm-commits] [llvm] r143880 - in /llvm/trunk: include/llvm/ADT/StringRef.h lib/Support/StringRef.cpp
Joe Abbey
joe.abbey at gmail.com
Sun Nov 6 10:16:55 PST 2011
Shouldn't upper call ascii_toupper?
Joe
Sent from my iPhone
On Nov 6, 2011, at 1:04 PM, Daniel Dunbar <daniel at zuster.org> wrote:
> Author: ddunbar
> Date: Sun Nov 6 12:04:43 2011
> New Revision: 143880
>
> URL: http://llvm.org/viewvc/llvm-project?rev=143880&view=rev
> Log:
> ADT/StringRef: Add ::lower() and ::upper() methods.
>
> Modified:
> llvm/trunk/include/llvm/ADT/StringRef.h
> llvm/trunk/lib/Support/StringRef.cpp
>
> Modified: llvm/trunk/include/llvm/ADT/StringRef.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringRef.h?rev=143880&r1=143879&r2=143880&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/ADT/StringRef.h (original)
> +++ llvm/trunk/include/llvm/ADT/StringRef.h Sun Nov 6 12:04:43 2011
> @@ -327,6 +327,16 @@
> bool getAsInteger(unsigned Radix, APInt &Result) const;
>
> /// @}
> + /// @name String Operations
> + /// @{
> +
> + // lower - Convert the given ASCII string to lowercase.
> + std::string lower() const;
> +
> + /// upper - Convert the given ASCII string to uppercase.
> + std::string upper() const;
> +
> + /// @}
> /// @name Substring Operations
> /// @{
>
>
> Modified: llvm/trunk/lib/Support/StringRef.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/StringRef.cpp?rev=143880&r1=143879&r2=143880&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/StringRef.cpp (original)
> +++ llvm/trunk/lib/Support/StringRef.cpp Sun Nov 6 12:04:43 2011
> @@ -25,6 +25,12 @@
> 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 @@
> }
>
> //===----------------------------------------------------------------------===//
> +// 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
> //===----------------------------------------------------------------------===//
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list