summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author couriersud <couriersud@gmx.org>2020-09-24 07:53:56 +0200
committer couriersud <couriersud@gmx.org>2020-09-24 15:22:25 +0200
commit0acb9992f4c73db6f865ed89411ce4db20cee9f2 (patch)
tree21203310f91c9590da371e2826395e75eb00d99a
parentdd5769bea9d3ef209c5cd46507ef6d4800ee1ccf (diff)
netlist: make pstring length/size use consistent.
* length reports the number of character codes in the string * size reports the size in memory units * Reminder: Set PSTRING_USE_STD_STRING to 1 in pstring.h and get native std::string * pstrings are compatible to std::string but only support a limited subset of functionality. * By default (always like this) utf8 is supported and thus length reports the number of multi-byte characters.
-rw-r--r--src/lib/netlist/nl_setup.cpp6
-rw-r--r--src/lib/netlist/plib/pfmtlog.cpp7
-rw-r--r--src/lib/netlist/plib/pfunction.cpp2
-rw-r--r--src/lib/netlist/plib/ppreprocessor.cpp6
-rw-r--r--src/lib/netlist/plib/pstream.h4
-rw-r--r--src/lib/netlist/plib/pstring.h24
6 files changed, 33 insertions, 16 deletions
diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp
index 9af1ec92d51..3a2ba38d921 100644
--- a/src/lib/netlist/nl_setup.cpp
+++ b/src/lib/netlist/nl_setup.cpp
@@ -1305,7 +1305,7 @@ void models_t::model_parse(const pstring &model_in, map_t &map)
if (!plib::endsWith(remainder, ")"))
throw nl_exception(MF_MODEL_ERROR_1(model));
// FIMXE: Not optimal
- remainder = plib::left(remainder, remainder.size() - 1);
+ remainder = plib::left(remainder, remainder.length() - 1);
const auto pairs(plib::psplit(remainder,' ', true));
for (const pstring &pe : pairs)
@@ -1353,7 +1353,7 @@ nl_fptype models_t::model_t::value(const pstring &entity) const
pstring tmp = value_str(entity);
nl_fptype factor = nlconst::one();
- auto p = std::next(tmp.begin(), plib::narrow_cast<pstring::difference_type>(tmp.size() - 1));
+ auto p = std::next(tmp.begin(), plib::narrow_cast<pstring::difference_type>(tmp.length() - 1));
switch (*p)
{
case 'M': factor = nlconst::magic(1e6); break; // NOLINT
@@ -1370,7 +1370,7 @@ nl_fptype models_t::model_t::value(const pstring &entity) const
throw nl_exception(MF_UNKNOWN_NUMBER_FACTOR_IN_2(m_model, entity));
}
if (factor != nlconst::one())
- tmp = plib::left(tmp, tmp.size() - 1);
+ tmp = plib::left(tmp, tmp.length() - 1);
// FIXME: check for errors
bool err(false);
auto val = plib::pstonum_ne<nl_fptype>(tmp, err);
diff --git a/src/lib/netlist/plib/pfmtlog.cpp b/src/lib/netlist/plib/pfmtlog.cpp
index ddb9b5dd2e5..32468752658 100644
--- a/src/lib/netlist/plib/pfmtlog.cpp
+++ b/src/lib/netlist/plib/pfmtlog.cpp
@@ -47,7 +47,7 @@ pfmt::rtype pfmt::setfmt(std::stringstream &strm, char32_t cfmt_spec)
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
@@ -94,11 +94,12 @@ pfmt::rtype pfmt::setfmt(std::stringstream &strm, char32_t cfmt_spec)
int width(0);
if (!fmt.empty() && pstring("duxofge").find(static_cast<pstring::value_type>(cfmt_spec)) != pstring::npos)
{
- pend = static_cast<char32_t>(fmt.at(fmt.size() - 1));
+ //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 = cfmt_spec;
else
- fmt = plib::left(fmt, fmt.size() - 1);
+ fmt = plib::left(fmt, fmt.length() - 1);
}
else
// FIXME: Error
diff --git a/src/lib/netlist/plib/pfunction.cpp b/src/lib/netlist/plib/pfunction.cpp
index 5a00844becc..3ab937735cf 100644
--- a/src/lib/netlist/plib/pfunction.cpp
+++ b/src/lib/netlist/plib/pfunction.cpp
@@ -143,7 +143,7 @@ namespace plib {
if (r == units_si<fl_t>().end())
rc.m_param.val = plib::pstonum_ne<fl_t>(cmd, err);
else
- rc.m_param.val = plib::pstonum_ne<fl_t>(plib::left(cmd, cmd.size()-1), err) * r->second;
+ rc.m_param.val = plib::pstonum_ne<fl_t>(plib::left(cmd, cmd.length()-1), err) * r->second;
if (err)
throw pexception(plib::pfmt("pfunction: unknown/misformatted token <{1}> in <{2}>")(cmd)(expr));
stk += 1;
diff --git a/src/lib/netlist/plib/ppreprocessor.cpp b/src/lib/netlist/plib/ppreprocessor.cpp
index 320cbe23857..c203fea1753 100644
--- a/src/lib/netlist/plib/ppreprocessor.cpp
+++ b/src/lib/netlist/plib/ppreprocessor.cpp
@@ -245,10 +245,10 @@ namespace plib {
else
{
pstring tok=tmp[pi];
- if (tok.size() >= 2 && pi < tmp.size() - 2 )
+ if (tok.length() >= 2 && pi < tmp.size() - 2 )
{
auto sc=tok.substr(0,1);
- auto ec=tok.substr(tok.size()-1, 1);
+ auto ec=tok.substr(tok.length()-1, 1);
if ((sc == "." || (sc>="0" && sc<="9")) && (ec=="e" || ec=="E"))
{
// looks like an incomplete float due splitting by - or +
@@ -496,7 +496,7 @@ namespace plib {
{
bool line_cont = plib::right(line_in, 1) == "\\";
- pstring line = line_cont ? plib::left(line_in, line_in.size() - 1) : line_in;
+ pstring line = line_cont ? plib::left(line_in, line_in.length() - 1) : line_in;
if (m_state == LINE_CONTINUATION)
m_line += line;
diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h
index bc0c7cfc31e..231d75e9ebb 100644
--- a/src/lib/netlist/plib/pstream.h
+++ b/src/lib/netlist/plib/pstream.h
@@ -228,7 +228,7 @@ public:
// NOLINTNEXTLINE(performance-unnecessary-copy-initialization)
const putf8string conv_utf8(text);
//m_strm->write(conv_utf8.c_str(), static_cast<std::streamsize>(plib::strlen(conv_utf8.c_str() )));
- ostream_write(*m_strm, conv_utf8.c_str(), string_info<putf8string>::mem_size(conv_utf8));
+ ostream_write(*m_strm, conv_utf8.c_str(), conv_utf8.size());
}
void write(const pstring::value_type c) const
@@ -290,7 +290,7 @@ public:
{
const auto *sm = s.c_str();
//const auto sl(std::char_traits<pstring::mem_t>::length(sm));
- const auto sl(string_info<pstring>::mem_size(s));
+ const auto sl(s.size());
write(sl);
ostream_write(m_strm, sm, sl);
}
diff --git a/src/lib/netlist/plib/pstring.h b/src/lib/netlist/plib/pstring.h
index 9a58e75fbd3..6af155a640c 100644
--- a/src/lib/netlist/plib/pstring.h
+++ b/src/lib/netlist/plib/pstring.h
@@ -178,11 +178,23 @@ public:
const_iterator cend() const noexcept { return const_iterator(m_str.end()); }
// C string conversion helpers
- const mem_t *c_str() const noexcept { return static_cast<const mem_t *>(m_str.c_str()); }
- const mem_t *data() const noexcept { return c_str(); }
-
+ const mem_t *c_str() const noexcept { return static_cast<const mem_t *>(m_str.c_str()); }
+ const mem_t *data() const noexcept { return c_str(); }
+
+ /// \brief return number of codes in the string
+ ///
+ /// This may report a number less than what \ref size reports. pstrings
+ /// operate on character codes. In the case of utf pstrings thus the physical size
+ /// may be bigger than the logical size.
size_type length() const noexcept { return traits_type::len(m_str); }
- size_type size() const noexcept { return traits_type::len(m_str); }
+
+ /// \brief return number of memory units in the string
+ ///
+ /// This function returns the number of memory units used by a string.
+ /// Depending on the string type the size may be reported as bytes, words
+ /// or quad-words.
+ size_type size() const noexcept { return m_str.size(); }
+
bool empty() const noexcept { return m_str.empty(); }
void clear() noexcept { m_str.clear(); }
@@ -478,14 +490,18 @@ namespace plib
struct string_info<pstring_t<T>>
{
using mem_t = typename T::mem_t;
+#if 0
static std::size_t mem_size(const pstring_t<T> &s) { return s.mem_t_size(); }
+#endif
};
template<typename T>
struct string_info<std::basic_string<T>>
{
using mem_t = T;
+#if 0
static std::size_t mem_size(const std::basic_string<T> &s) { return s.size(); }
+#endif
};
} // namespace plib