]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/support/Arrays.cpp
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / support / Arrays.cpp
1 /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2  * Use of this file is governed by the BSD 3-clause license that
3  * can be found in the LICENSE.txt file in the project root.
4  */
5
6 #include "tree/ParseTree.h"
7 #include "Exceptions.h"
8
9 #include "support/Arrays.h"
10
11 using namespace antlrcpp;
12
13 std::string Arrays::listToString(const std::vector<std::string> &list, const std::string &separator)
14 {
15   std::stringstream ss;
16   bool firstEntry = true;
17
18   ss << '[';
19   for (const auto &entry : list) {
20     ss << entry;
21     if (firstEntry) {
22       ss << separator;
23       firstEntry = false;
24     }
25   }
26
27   ss << ']';
28   return ss.str();
29 }
30
31 template <>
32 std::string Arrays::toString(const std::vector<antlr4::tree::ParseTree*> &source) {
33   std::string result = "[";
34   bool firstEntry = true;
35   for (auto *value : source) {
36     result += value->toStringTree();
37     if (firstEntry) {
38       result += ", ";
39       firstEntry = false;
40     }
41   }
42   return result + "]";
43 }