summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/plib/pfmtlog.cpp
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2019-03-26 11:13:37 +1100
committer Vas Crabb <vas@vastheman.com>2019-03-26 11:13:37 +1100
commit97b67170277437131adf6ed4d60139c172529e4f (patch)
tree7a5cbf608f191075f1612b1af15832c206a3fe2d /src/lib/netlist/plib/pfmtlog.cpp
parentb380514764cf857469bae61c11143a19f79a74c5 (diff)
(nw) Clean up the mess on master
This effectively reverts b380514764cf857469bae61c11143a19f79a74c5 and c24473ddff715ecec2e258a6eb38960cf8c8e98e, restoring the state at 598cd5227223c3b04ca31f0dbc1981256d9ea3ff. Before pushing, please check that what you're about to push is sane. Check your local commit log and ensure there isn't anything out-of-place before pushing to mainline. When things like this happen, it wastes everyone's time. I really don't need this in a week when real work™ is busting my balls and I'm behind where I want to be with preparing for MAME release.
Diffstat (limited to 'src/lib/netlist/plib/pfmtlog.cpp')
-rw-r--r--src/lib/netlist/plib/pfmtlog.cpp121
1 files changed, 67 insertions, 54 deletions
diff --git a/src/lib/netlist/plib/pfmtlog.cpp b/src/lib/netlist/plib/pfmtlog.cpp
index b8b5fcb3b91..af87251fbdf 100644
--- a/src/lib/netlist/plib/pfmtlog.cpp
+++ b/src/lib/netlist/plib/pfmtlog.cpp
@@ -8,83 +8,96 @@
#include "pfmtlog.h"
#include "palloc.h"
-#include <cstring>
-#include <cstdlib>
-#include <cstdarg>
#include <algorithm>
-#include <locale>
+#include <array>
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
#include <iostream>
+#include <locale>
namespace plib {
pfmt &pfmt::format_element(const char *l, const unsigned cfmt_spec, ...)
{
va_list ap;
- va_start(ap, cfmt_spec);
- pstring fmt("%");
- char buf[2048]; // FIXME
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
+ std::array<char, 2048> buf;
std::size_t sl;
+ bool found_abs = false;
m_arg++;
- pstring search("{");
- search += plib::to_string(m_arg);
- sl = search.length();
+ do {
+ pstring fmt("%");
+ va_start(ap, cfmt_spec);
+ found_abs = false;
+ buf[0] = 0;
+ pstring search("{");
+ search += plib::to_string(m_arg);
+ sl = search.size();
- auto p = m_str.find(search + ":");
- sl++; // ":"
- if (p == pstring::npos) // no further specifiers
- {
- p = m_str.find(search + "}");
- if (p == pstring::npos) // not found try default
- {
- sl = 2;
- p = m_str.find("{}");
- }
- if (p == pstring::npos)
+ auto p = m_str.find(search + ":");
+ sl++; // ":"
+ if (p == pstring::npos) // no further specifiers
{
- sl=1;
- p = m_str.find("{");
- if (p != pstring:: npos)
+ p = m_str.find(search + "}");
+ if (p == pstring::npos) // not found try default
{
- auto p1 = m_str.find("}", p);
- if (p1 != pstring::npos)
+ sl = 2;
+ p = m_str.find("{}");
+ }
+ else
+ // found absolute positional place holder
+ found_abs = true;
+ if (p == pstring::npos)
+ {
+ sl=2;
+ p = m_str.find("{:");
+ if (p != pstring:: npos)
{
- sl = p1 - p + 1;
- fmt += m_str.substr(p+1, p1 - p - 1);
+ auto p1 = m_str.find("}", p);
+ if (p1 != pstring::npos)
+ {
+ sl = p1 - p + 1;
+ fmt += m_str.substr(p+1, p1 - p - 1);
+ }
}
}
}
- }
- else
- {
- auto p1 = m_str.find("}", p);
- if (p1 != pstring::npos)
+ else
+ {
+ // found absolute positional place holder
+ auto p1 = m_str.find("}", p);
+ if (p1 != pstring::npos)
+ {
+ sl = p1 - p + 1;
+ fmt += ((m_arg>=10) ? m_str.substr(p+4, p1 - p - 4) : m_str.substr(p+3, p1 - p - 3));
+ found_abs = true;
+ }
+ }
+ pstring::value_type pend = fmt.at(fmt.size() - 1);
+ if (pstring("duxo").find(cfmt_spec) != pstring::npos)
{
- sl = p1 - p + 1;
- fmt += ((m_arg>=10) ? m_str.substr(p+4, p1 - p - 4) : m_str.substr(p+3, p1 - p - 3));
+ if (pstring("duxo").find(pend) == pstring::npos)
+ fmt += (pstring(l) + static_cast<pstring::value_type>(cfmt_spec));
+ else
+ fmt = plib::left(fmt, fmt.size() - 1) + pstring(l) + plib::right(fmt, 1);
+ }
+ else if (pstring("fge").find(cfmt_spec) != pstring::npos)
+ {
+ if (pstring("fge").find(pend) == pstring::npos)
+ fmt += cfmt_spec;
}
- }
- pstring::code_t pend = fmt.at(fmt.length() - 1);
- if (pstring("duxo").find(cfmt_spec) != pstring::npos)
- {
- if (pstring("duxo").find(pend) == pstring::npos)
- fmt += (pstring(l, pstring::UTF8) + cfmt_spec);
else
- fmt = fmt.left(fmt.length() - 1) + pstring(l, pstring::UTF8) + fmt.right(1);
- }
- else if (pstring("fge").find(cfmt_spec) != pstring::npos)
- {
- if (pstring("fge").find(pend) == pstring::npos)
fmt += cfmt_spec;
- }
- else
- fmt += cfmt_spec;
- vsprintf(buf, fmt.c_str(), ap);
- if (p != pstring::npos)
- m_str = m_str.substr(0, p) + pstring(buf, pstring::UTF8) + m_str.substr(p + sl);
- va_end(ap);
+ std::vsnprintf(buf.data(), buf.size(), fmt.c_str(), ap);
+ if (p != pstring::npos)
+ m_str = m_str.substr(0, p) + pstring(buf.data()) + m_str.substr(p + sl);
+ va_end(ap);
+ } while (found_abs);
return *this;
}
-}
+} // namespace plib