Skip to content
Snippets Groups Projects
Commit 12d4cff9 authored by Franck Dary's avatar Franck Dary
Browse files

Made debug printing for Config easier to read

parent a74b1252
No related branches found
No related tags found
No related merge requests found
......@@ -41,6 +41,8 @@ utf8string splitAsUtf8(std::string_view s);
std::string int2HumanStr(int number);
std::string shrink(const std::string & s, int printedSize);
int printedLength(std::string_view s);
bool isSeparator(utf8char c);
......
......@@ -75,6 +75,34 @@ util::utf8string util::splitAsUtf8(std::string_view s)
return result;
}
std::string util::shrink(const std::string & s, int printedSize)
{
static const std::string filler = "..";
if (printedLength(s) <= printedSize)
return s;
auto splited = splitAsUtf8(s);
std::string result;
std::string begin, end;
int nbLoop = 0;
while (printedLength(begin)+printedLength(end)+2 <= printedSize)
{
result = begin + filler + end;
if (nbLoop % 2)
end = fmt::format("{}{}", splited[splited.size()-1-(nbLoop/2)], end);
else
begin = fmt::format("{}{}", begin, splited[nbLoop/2]);
++nbLoop;
}
return result;
}
void util::warning(std::string_view message, const std::experimental::source_location & location)
{
fmt::print(stderr, "WARNING ({}) : {}\n", location, message);
......
......@@ -80,6 +80,7 @@ void Config::printForDebug(FILE * dest) const
{
static constexpr int windowSize = 5;
static constexpr int lettersWindowSize = 40;
static constexpr int maxWordLength = 7;
int firstLineToPrint = wordIndex;
int lastLineToPrint = wordIndex;
......@@ -102,7 +103,7 @@ void Config::printForDebug(FILE * dest) const
toPrint.emplace_back();
toPrint.back().emplace_back(line == (int)wordIndex ? "=>" : "");
for (unsigned int i = 0; i < getNbColumns(); i++)
toPrint.back().emplace_back(getLastNotEmptyConst(i, line));
toPrint.back().emplace_back(util::shrink(getLastNotEmptyConst(i, line), maxWordLength));
}
std::vector<std::size_t> colLength(toPrint[0].size(), 0);
......@@ -146,7 +147,7 @@ void Config::printForDebug(FILE * dest) const
if (line == 1)
fmt::print(dest, "{}\n", longLine);
for (unsigned int col = 0; col < toPrint[line].size()-1; col++)
fmt::print(dest, "{}{:>{}}{}", toPrint[line][col], "", colLength[col]-util::printedLength(toPrint[line][col]), col == toPrint[line].size()-2 ? "\n" : "\t");
fmt::print(dest, "{}{:>{}}{}", toPrint[line][col], "", colLength[col]-util::printedLength(toPrint[line][col]), col == toPrint[line].size()-2 ? "\n" : " ");
if (toPrint[line].back() == EOSSymbol1)
fmt::print(dest, "\n");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment