OLD | NEW |
---|---|
(Empty) | |
1 //===- llvm/unittest/Bitcode/NaClMungeTest.cpp - Test munging utils -------===// | |
jvoung (off chromium)
2015/08/25 13:31:10
unittest -> unittests
Karl
2015/08/25 16:15:48
Done.
| |
2 // | |
3 // The LLVM Compiler Infrastructure | |
4 // | |
5 // This file is distributed under the University of Illinois Open Source | |
6 // License. See LICENSE.TXT for details. | |
7 // | |
8 //===----------------------------------------------------------------------===// | |
9 // | |
10 // Implements stringify methods for munging tests. | |
11 // | |
12 //===----------------------------------------------------------------------===// | |
13 | |
14 #include "NaClMungeTest.h" | |
15 #include <regex> | |
16 | |
17 using namespace llvm; | |
18 | |
19 namespace naclmungetest { | |
20 | |
21 static bool matchErrorPrefixForLine(const std::string &Line, std::regex &Exp, | |
22 std::string &Suffix) { | |
23 std::smatch Match; | |
24 if (std::regex_search(Line, Match, Exp)) { | |
25 // Note: Element 0 is the original string. | |
26 Suffix = Match[2]; | |
27 return true; | |
28 } | |
29 Suffix.clear(); | |
30 return false; | |
31 } | |
32 | |
33 static std::string stripErrorPrefixForLine(const std::string &Line) { | |
34 std::string Suffix; | |
35 std::regex ErrorExp("[Ee]rror: (\\(.*\\) )?(.*)"); | |
36 if (matchErrorPrefixForLine(Line, ErrorExp, Suffix)) | |
37 return Suffix; | |
38 std::regex WarningExp("[Ww]arning: (\\(.*\\) )?(.*)"); | |
39 if (matchErrorPrefixForLine(Line, WarningExp, Suffix)) | |
40 return Suffix; | |
41 return Line; | |
42 } | |
43 | |
44 std::string stripErrorPrefix(const std::string &Message) { | |
45 std::string Result; | |
46 size_t StartPos = 0; | |
47 size_t NextEoln = Message.find_first_of("\n", StartPos); | |
Derek Schuff
2015/08/24 22:46:04
could this just be find instead of find_first_of?
Karl
2015/08/25 16:15:48
Changed to use find.
| |
48 while (NextEoln != std::string::npos) { | |
49 std::string Line(Message.c_str() + StartPos, NextEoln - StartPos); | |
50 Result.append(stripErrorPrefixForLine(Line)).push_back('\n'); | |
51 StartPos = NextEoln + 1; | |
52 NextEoln = Message.find_first_of("\n", StartPos); | |
53 } | |
54 if (StartPos < Message.size()) { | |
55 std::string Remainder(Message.c_str() + StartPos, | |
56 Message.size() - StartPos); | |
57 Result.append(stripErrorPrefixForLine(Remainder)); | |
58 } | |
59 return Result; | |
60 } | |
61 | |
62 } // end of naclmungetest namespace | |
OLD | NEW |