diff options
Diffstat (limited to 'src/lib/netlist/plib/pfmtlog.cpp')
-rw-r--r-- | src/lib/netlist/plib/pfmtlog.cpp | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/src/lib/netlist/plib/pfmtlog.cpp b/src/lib/netlist/plib/pfmtlog.cpp index ef12e05fb1d..188c04f4cf7 100644 --- a/src/lib/netlist/plib/pfmtlog.cpp +++ b/src/lib/netlist/plib/pfmtlog.cpp @@ -1,16 +1,13 @@ -// license:GPL-2.0+ +// license:BSD-3-Clause // copyright-holders:Couriersud -/* - * nl_string.c - * - */ #include "pfmtlog.h" #include "palloc.h" +#include "pstonum.h" +#include "pstrutil.h" #include <algorithm> #include <array> -#include <cmath> #include <iomanip> #include <iostream> @@ -42,14 +39,15 @@ private: }; #endif -pfmt::rtype pfmt::setfmt(std::stringstream &strm, char32_t cfmt_spec) +pfmt::rtype pfmt::set_format(std::stringstream &strm, char32_t char_format) { pstring fmt; pstring search("{"); search += plib::to_string(m_arg); + rtype r; - r.sl = search.size(); + r.sl = search.length(); r.p = m_str.find(search + ':'); r.sl++; // ":" if (r.p == pstring::npos) // no further specifiers @@ -92,33 +90,40 @@ pfmt::rtype pfmt::setfmt(std::stringstream &strm, char32_t cfmt_spec) if (r.p != pstring::npos) { // a.b format here ... - if (fmt != "" && pstring("duxofge").find(static_cast<pstring::value_type>(cfmt_spec)) != pstring::npos) + char32_t pend(0); + int width(0); + if (!fmt.empty() && pstring("duxofge").find(static_cast<pstring::value_type>(char_format)) != pstring::npos) { - r.pend = static_cast<char32_t>(fmt.at(fmt.size() - 1)); - if (pstring("duxofge").find(static_cast<pstring::value_type>(r.pend)) == pstring::npos) - r.pend = cfmt_spec; + //pend = static_cast<char32_t>(fmt.at(fmt.size() - 1)); + pend = plib::right(fmt, 1).at(0); + if (pstring("duxofge").find(static_cast<pstring::value_type>(pend)) == pstring::npos) + pend = char_format; else - fmt = plib::left(fmt, fmt.size() - 1); + fmt = plib::left(fmt, fmt.length() - 1); } else // FIXME: Error - r.pend = cfmt_spec; + pend = char_format; auto pdot(fmt.find('.')); if (pdot==0) - strm << std::setprecision(pstonum<int>(fmt.substr(1))); + strm << std::setprecision(pstonum_ne_def<int>(fmt.substr(1), 6)); else if (pdot != pstring::npos) { - //strm << std::setprecision(pstonum<int>(fmt.substr(pdot + 1))) << std::setw(pstonum<int>(left(fmt,pdot))); - strm << std::setprecision(pstonum<int>(fmt.substr(pdot + 1))); - r.width = pstonum<pstring::size_type>(left(fmt,pdot)); + strm << std::setprecision(pstonum_ne_def<int>(fmt.substr(pdot + 1), 6)); + width = pstonum_ne_def<int>(left(fmt,pdot), 0); } - else if (fmt != "") - //strm << std::setw(pstonum<int>(fmt)); - r.width = pstonum<pstring::size_type>(fmt); + else if (!fmt.empty()) + width = pstonum_ne_def<int>(fmt, 0); + + auto aw(plib::abs(width)); + + strm << std::setw(aw); + if (width < 0) + strm << std::left; - switch (r.pend) + switch (pend) { case 'x': strm << std::hex; |