From: Benjamin Kramer Date: Fri, 10 Apr 2015 21:37:21 +0000 (+0000) Subject: [tblgen] Use StringRef::trim X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=420fd99bc3047f2a14bc91cd86689b6ac7aae8ef;p=clang [tblgen] Use StringRef::trim git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234643 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/utils/TableGen/ClangAttrEmitter.cpp b/utils/TableGen/ClangAttrEmitter.cpp index c2f9dec0c0..c1d1a1dbe6 100644 --- a/utils/TableGen/ClangAttrEmitter.cpp +++ b/utils/TableGen/ClangAttrEmitter.cpp @@ -115,11 +115,7 @@ static StringRef NormalizeAttrName(StringRef AttrName) { // 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 Record *DocCategory, // 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 DocumentationData &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"; }