OLD | NEW |
(Empty) | |
| 1 //===- llvm/unittests/Bitcode/NaClMungeTest.cpp - Test munging utils ------===// |
| 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('\n', StartPos); |
| 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 |