r234643 - [tblgen] Use StringRef::trim

Aaron Ballman aaron at aaronballman.com
Fri Apr 10 14:45:38 PDT 2015


Nice! Thanks!

~Aaron

On Fri, Apr 10, 2015 at 5:37 PM, Benjamin Kramer
<benny.kra at googlemail.com> wrote:
> Author: d0k
> Date: Fri Apr 10 16:37:21 2015
> New Revision: 234643
>
> URL: http://llvm.org/viewvc/llvm-project?rev=234643&view=rev
> Log:
> [tblgen] Use StringRef::trim
>
> Modified:
>     cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
>
> Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=234643&r1=234642&r2=234643&view=diff
> ==============================================================================
> --- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
> +++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Fri Apr 10 16:37:21 2015
> @@ -115,11 +115,7 @@ static StringRef NormalizeAttrName(Strin
>  // This is different from NormalizeAttrName in that it also handles names like
>  // _pascal and __pascal.
>  static StringRef NormalizeNameForSpellingComparison(StringRef Name) {
> -  while (Name.startswith("_"))
> -    Name = Name.substr(1, Name.size());
> -  while (Name.endswith("_"))
> -    Name = Name.substr(0, Name.size() - 1);
> -  return Name;
> +  return Name.trim("_");
>  }
>
>  // Normalize attribute spelling only if the spelling has both leading
> @@ -2787,17 +2783,9 @@ static void WriteCategoryHeader(const Re
>
>    // If there is content, print that as well.
>    std::string ContentStr = DocCategory->getValueAsString("Content");
> -  if (!ContentStr.empty()) {
> -    // Trim leading and trailing newlines and spaces.
> -    StringRef Content(ContentStr);
> -    while (Content.startswith("\r") || Content.startswith("\n") ||
> -           Content.startswith(" ") || Content.startswith("\t"))
> -           Content = Content.substr(1);
> -    while (Content.endswith("\r") || Content.endswith("\n") ||
> -           Content.endswith(" ") || Content.endswith("\t"))
> -           Content = Content.substr(0, Content.size() - 1);
> -    OS << Content;
> -  }
> +  // Trim leading and trailing newlines and spaces.
> +  OS << StringRef(ContentStr).trim();
> +
>    OS << "\n\n";
>  }
>
> @@ -2919,14 +2907,7 @@ static void WriteDocumentation(const Doc
>
>    std::string ContentStr = Doc.Documentation->getValueAsString("Content");
>    // Trim leading and trailing newlines and spaces.
> -  StringRef Content(ContentStr);
> -  while (Content.startswith("\r") || Content.startswith("\n") ||
> -         Content.startswith(" ") || Content.startswith("\t"))
> -    Content = Content.substr(1);
> -  while (Content.endswith("\r") || Content.endswith("\n") ||
> -         Content.endswith(" ") || Content.endswith("\t"))
> -    Content = Content.substr(0, Content.size() - 1);
> -  OS << Content;
> +  OS << StringRef(ContentStr).trim();
>
>    OS << "\n\n\n";
>  }
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list