From bd392ea08135f011f2f2ccc1e7d7126f49eeece3 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Sat, 25 Oct 2014 12:20:55 +0200 Subject: [PATCH] split long lines in dot convert --- aconvert2/src/DotConverter.cpp | 274 ++++++++++++++++++++++++++++----- 1 file changed, 233 insertions(+), 41 deletions(-) diff --git a/aconvert2/src/DotConverter.cpp b/aconvert2/src/DotConverter.cpp index 8ffa927113..fa7e22a488 100644 --- a/aconvert2/src/DotConverter.cpp +++ b/aconvert2/src/DotConverter.cpp @@ -39,6 +39,14 @@ #include <vector> #include <typeinfo> +auto replace = [](std::string& str, const std::string& what, const std::string& with) { + size_t index = 0; + while((index = str.find(what, index)) != std::string::npos) { + str.replace(index, what.length(), with); + index += with.length(); + } +}; + void DotConverter::convert(const automaton::Automaton& a, std::ostream& out) { a.getData().Accept((void*) &out, DotConverter::instance); } @@ -603,14 +611,22 @@ void DotConverter::transitions(const automaton::EpsilonNFA& fsm, const std::map< if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol)); } else { - mapit->second += ", " + symbol; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; } } } //print the map - for (const std::pair<std::pair<int, int>, std::string>& transition : transitions) { + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); out << "[label=\"" << transition.second << "\"]\n"; } } @@ -630,14 +646,22 @@ void DotConverter::transitions(const automaton::MultiInitialStateNFA& fsm, const if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol)); } else { - mapit->second += ", " + symbol; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; } } } //print the map - for (const std::pair<std::pair<int, int>, std::string>& transition : transitions) { + for (std::pair< const std::pair<int, int>, std::string>& transition : transitions) { out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); out << "[label=\"" << transition.second << "\"]\n"; } } @@ -657,14 +681,22 @@ void DotConverter::transitions(const automaton::NFA& fsm, const std::map<automat if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol)); } else { - mapit->second += ", " + symbol; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; } } } //print the map - for (const std::pair<std::pair<int, int>, std::string>& transition : transitions) { + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); out << "[label=\"" << transition.second << "\"]\n"; } } @@ -683,13 +715,21 @@ void DotConverter::transitions(const automaton::DFA& fsm, const std::map<automat if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol)); } else { - mapit->second += ", " + symbol; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; } } //print the map - for (const std::pair<std::pair<int, int>, std::string>& transition : transitions) { + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); out << "[label=\"" << transition.second << "\"]\n"; } } @@ -709,14 +749,22 @@ void DotConverter::transitions(const automaton::ExtendedNFA& fsm, const std::map if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol)); } else { - mapit->second += ", " + symbol; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; } } } //print the map - for (const std::pair<std::pair<int, int>, std::string>& transition : transitions) { + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); out << "[label=\"" << transition.second << "\"]\n"; } } @@ -736,14 +784,22 @@ void DotConverter::transitions(const automaton::CompactNFA& fsm, const std::map< if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol)); } else { - mapit->second += ", " + symbol; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; } } } //print the map - for (const std::pair<std::pair<int, int>, std::string>& transition : transitions) { + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); out << "[label=\"" << transition.second << "\"]\n"; } } @@ -795,14 +851,22 @@ void DotConverter::transitions(const automaton::DPDA& pda, const std::map<automa if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol)); } else { - mapit->second += ", " + symbol; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; } } //print the map - for (const std::pair<std::pair<int, int>, std::string>& transition : transitions) { + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { out << transition.first.first << " -> " << transition.first.second; - out << "[label=\"" << transition.second << "\"]\n"; + replace(transition.second, "\n", "\\n"); + out << "[label=\"" << transition.second << "\"]\n"; } } @@ -846,13 +910,21 @@ void DotConverter::transitions(const automaton::SinglePopDPDA& pda, const std::m if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol)); } else { - mapit->second += ", " + symbol; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; } } //print the map - for (const std::pair<std::pair<int, int>, std::string>& transition : transitions) { + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); out << "[label=\"" << transition.second << "\"]\n"; } } @@ -907,14 +979,22 @@ void DotConverter::transitions(const automaton::InputDrivenNPDA& pda, const std: if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol2)); } else { - mapit->second += ", " + symbol2; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol2; } } } //print the map - for (const std::pair<std::pair<int, int>, std::string>& transition : transitions) { + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); out << "[label=\"" << transition.second << "\"]\n"; } } @@ -944,7 +1024,14 @@ void DotConverter::transitions(const automaton::VisiblyPushdownDPDA& pda, const if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol)); } else { - mapit->second += ", " + symbol; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; } } @@ -970,7 +1057,14 @@ void DotConverter::transitions(const automaton::VisiblyPushdownDPDA& pda, const if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol)); } else { - mapit->second += ", " + symbol; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; } } @@ -996,13 +1090,21 @@ void DotConverter::transitions(const automaton::VisiblyPushdownDPDA& pda, const if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol)); } else { - mapit->second += ", " + symbol; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; } } //print the map - for (const std::pair<std::pair<int, int>, std::string>& transition : transitions) { + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); out << "[label=\"" << transition.second << "\"]\n"; } } @@ -1036,7 +1138,14 @@ void DotConverter::transitions(const automaton::VisiblyPushdownNPDA& pda, const if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol2)); } else { - mapit->second += ", " + symbol2; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol2; } } } @@ -1066,7 +1175,14 @@ void DotConverter::transitions(const automaton::VisiblyPushdownNPDA& pda, const if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol2)); } else { - mapit->second += ", " + symbol2; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol2; } } } @@ -1096,14 +1212,22 @@ void DotConverter::transitions(const automaton::VisiblyPushdownNPDA& pda, const if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol2)); } else { - mapit->second += ", " + symbol2; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol2; } } } //print the map - for (const std::pair<std::pair<int, int>, std::string>& transition : transitions) { + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); out << "[label=\"" << transition.second << "\"]\n"; } } @@ -1136,7 +1260,14 @@ void DotConverter::transitions(const automaton::RealTimeHeightDeterministicDPDA& if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol)); } else { - mapit->second += ", " + symbol; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; } } @@ -1165,7 +1296,14 @@ void DotConverter::transitions(const automaton::RealTimeHeightDeterministicDPDA& if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol)); } else { - mapit->second += ", " + symbol; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; } } @@ -1194,13 +1332,21 @@ void DotConverter::transitions(const automaton::RealTimeHeightDeterministicDPDA& if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol)); } else { - mapit->second += ", " + symbol; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; } } //print the map - for (const std::pair<std::pair<int, int>, std::string>& transition : transitions) { + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); out << "[label=\"" << transition.second << "\"]\n"; } } @@ -1237,7 +1383,14 @@ void DotConverter::transitions(const automaton::RealTimeHeightDeterministicNPDA& if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol2)); } else { - mapit->second += ", " + symbol2; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol2; } } } @@ -1270,7 +1423,14 @@ void DotConverter::transitions(const automaton::RealTimeHeightDeterministicNPDA& if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol2)); } else { - mapit->second += ", " + symbol2; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol2; } } } @@ -1303,14 +1463,22 @@ void DotConverter::transitions(const automaton::RealTimeHeightDeterministicNPDA& if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol2)); } else { - mapit->second += ", " + symbol2; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol2; } } } //print the map - for (const std::pair<std::pair<int, int>, std::string>& transition : transitions) { + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); out << "[label=\"" << transition.second << "\"]\n"; } } @@ -1365,14 +1533,22 @@ void DotConverter::transitions(const automaton::NPDA& pda, const std::map<automa if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol2)); } else { - mapit->second += ", " + symbol2; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol2; } } } //print the map - for (const std::pair<std::pair<int, int>, std::string>& transition : transitions) { + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); out << "[label=\"" << transition.second << "\"]\n"; } } @@ -1420,14 +1596,22 @@ void DotConverter::transitions(const automaton::SinglePopNPDA& pda, const std::m if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol2)); } else { - mapit->second += ", " + symbol2; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol2; } } } //print the map - for (const std::pair<std::pair<int, int>, std::string>& transition : transitions) { + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); out << "[label=\"" << transition.second << "\"]\n"; } } @@ -1466,13 +1650,21 @@ void DotConverter::transitions(const automaton::OneTapeDTM& tm, const std::map<a if (mapit == transitions.end()) { transitions.insert(std::make_pair(key, symbol)); } else { - mapit->second += ", " + symbol; + mapit->second += ","; + + size_t pos = mapit->second.find_last_of("\n"); + if(pos == std::string::npos) pos = 0; + if(mapit->second.size() - pos > 100) mapit->second += "\n"; + else mapit->second += " "; + + mapit->second += symbol; } } //print the map - for (const std::pair<std::pair<int, int>, std::string>& transition : transitions) { + for (std::pair<const std::pair<int, int>, std::string>& transition : transitions) { out << transition.first.first << " -> " << transition.first.second; + replace(transition.second, "\n", "\\n"); out << "[label=\"" << transition.second << "\"]\n"; } } -- GitLab