[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)
Paul Kirth via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 6 17:14:20 PDT 2024
================
@@ -0,0 +1,446 @@
+//===-- Mustache.cpp ------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+
+using namespace llvm;
+using namespace llvm::json;
+using namespace llvm::mustache;
+
+SmallString<128> escapeString(StringRef Input,
+ DenseMap<char, StringRef> &Escape) {
+ SmallString<128> EscapedString("");
+ for (char C : Input) {
+ if (Escape.find(C) != Escape.end())
+ EscapedString += Escape[C];
+ else
+ EscapedString += C;
+ }
+ return EscapedString;
+}
+
+std::vector<SmallString<128>> split(StringRef Str, char Delimiter) {
+ std::vector<SmallString<128>> Tokens;
+ if (Str == ".") {
+ Tokens.push_back(Str);
+ return Tokens;
+ }
+ StringRef Ref(Str);
+ while (!Ref.empty()) {
+ llvm::StringRef Part;
+ std::tie(Part, Ref) = Ref.split(Delimiter);
+ Tokens.push_back(Part.trim());
+ }
+ return Tokens;
+}
+
+Token::Token(StringRef RawBody, StringRef InnerBody, char Identifier)
+ : RawBody(RawBody), TokenBody(InnerBody) {
+
----------------
ilovepi wrote:
nit: newline
https://github.com/llvm/llvm-project/pull/105893
More information about the cfe-commits
mailing list