Skip to content

Commit 181749c

Browse files
committed
adding prefix=... and suffix=... for REFORMAT tables
1 parent a900689 commit 181749c

2 files changed

Lines changed: 52 additions & 3 deletions

File tree

src/reformat.cpp

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,28 @@ bool Reformat::Cell::parse_keyformat(const std::string& key,
328328

329329
return true;
330330
}
331+
else if (key == "prefix")
332+
{
333+
std::string value;
334+
335+
if (!parse_keyvalue(curr, end, value))
336+
value = "";
337+
338+
m_prefix = value;
339+
340+
return true;
341+
}
342+
else if (key == "suffix")
343+
{
344+
std::string value;
345+
346+
if (!parse_keyvalue(curr, end, value))
347+
value = "";
348+
349+
m_suffix = value;
350+
351+
return true;
352+
}
331353
else
332354
{
333355
OUT_THROW("Invalid cell-level key: " << key);
@@ -356,6 +378,12 @@ void Reformat::Cell::apply(const Cell& c)
356378

357379
if (c.m_grouping.size())
358380
m_grouping = c.m_grouping;
381+
382+
if (c.m_prefix.size())
383+
m_prefix = c.m_prefix;
384+
385+
if (c.m_suffix.size())
386+
m_suffix = c.m_suffix;
359387
}
360388

361389
//! Test if we need to read the row/column data
@@ -728,6 +756,14 @@ std::string Reformat::format(int row, int col, const std::string& in_text) const
728756

729757
text = replace_all(text, ",", fmt.m_grouping);
730758

759+
// *** add prefix and suffix ***
760+
761+
if (fmt.m_prefix.size())
762+
text = fmt.m_prefix + text;
763+
764+
if (fmt.m_suffix.size())
765+
text = text + fmt.m_suffix;
766+
731767
// *** check for row/column minimum or maximum formatting ***
732768

733769
DBG("fmt: " << in_text << " - " << fmt.m_min_text);
@@ -761,11 +797,18 @@ std::string Reformat::format(int row, int col, const std::string& in_text) const
761797
fmt.apply(colfmt->second);
762798
}
763799

800+
// *** escape special LaTeX characters ***
801+
764802
if (fmt.m_escape)
765-
{
766-
// escape special LaTeX characters
767803
text = escape_latex(text);
768-
}
804+
805+
// *** add prefix and suffix ***
806+
807+
if (fmt.m_prefix.size())
808+
text = fmt.m_prefix + text;
809+
810+
if (fmt.m_suffix.size())
811+
text = text + fmt.m_suffix;
769812
}
770813

771814
return text;

src/reformat.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ class Reformat
109109
//! thousands grouping separator
110110
std::string m_grouping;
111111

112+
//! prefix
113+
std::string m_prefix;
114+
115+
//! suffix
116+
std::string m_suffix;
117+
112118
//! Initialize with sentinels
113119
Cell()
114120
: m_escape(false),

0 commit comments

Comments
 (0)