mirror of
https://github.com/holub/mame
synced 2025-04-23 00:39:36 +03:00
Assume string literals are UTF8 in netlist code.
At the same time, any char pointer has to be explicitly converted to pstring by specifying an encoding. Not yet optimal, but certainly better than what was there before. Removed unneeded methods from pstring. (nw)
This commit is contained in:
parent
d0b6742563
commit
1ae3e29ea3
@ -62,7 +62,7 @@ netlist_mame_analog_input_t::netlist_mame_analog_input_t(const machine_config &m
|
||||
void netlist_mame_analog_input_t::static_set_name(device_t &device, const char *param_name)
|
||||
{
|
||||
netlist_mame_analog_input_t &netlist = downcast<netlist_mame_analog_input_t &>(device);
|
||||
netlist.m_param_name = param_name;
|
||||
netlist.m_param_name = pstring(param_name, pstring::UTF8);
|
||||
}
|
||||
|
||||
void netlist_mame_analog_input_t::device_start()
|
||||
@ -97,7 +97,7 @@ netlist_mame_analog_output_t::netlist_mame_analog_output_t(const machine_config
|
||||
void netlist_mame_analog_output_t::static_set_params(device_t &device, const char *in_name, netlist_analog_output_delegate adelegate)
|
||||
{
|
||||
netlist_mame_analog_output_t &mame_output = downcast<netlist_mame_analog_output_t &>(device);
|
||||
mame_output.m_in = in_name;
|
||||
mame_output.m_in = pstring(in_name, pstring::UTF8);
|
||||
mame_output.m_delegate = adelegate;
|
||||
}
|
||||
|
||||
@ -132,7 +132,7 @@ netlist_mame_logic_output_t::netlist_mame_logic_output_t(const machine_config &m
|
||||
void netlist_mame_logic_output_t::static_set_params(device_t &device, const char *in_name, netlist_logic_output_delegate adelegate)
|
||||
{
|
||||
netlist_mame_logic_output_t &mame_output = downcast<netlist_mame_logic_output_t &>(device);
|
||||
mame_output.m_in = in_name;
|
||||
mame_output.m_in = pstring(in_name, pstring::UTF8);
|
||||
mame_output.m_delegate = adelegate;
|
||||
}
|
||||
|
||||
@ -171,7 +171,7 @@ void netlist_mame_int_input_t::static_set_params(device_t &device, const char *p
|
||||
{
|
||||
netlist_mame_int_input_t &netlist = downcast<netlist_mame_int_input_t &>(device);
|
||||
LOG_DEV_CALLS(("static_set_params %s\n", device.tag()));
|
||||
netlist.m_param_name = param_name;
|
||||
netlist.m_param_name = pstring(param_name, pstring::UTF8);
|
||||
netlist.m_shift = shift;
|
||||
netlist.m_mask = mask;
|
||||
}
|
||||
@ -204,7 +204,7 @@ void netlist_mame_logic_input_t::static_set_params(device_t &device, const char
|
||||
{
|
||||
netlist_mame_logic_input_t &netlist = downcast<netlist_mame_logic_input_t &>(device);
|
||||
LOG_DEV_CALLS(("static_set_params %s\n", device.tag()));
|
||||
netlist.m_param_name = param_name;
|
||||
netlist.m_param_name = pstring(param_name, pstring::UTF8);
|
||||
netlist.m_shift = shift;
|
||||
}
|
||||
|
||||
@ -237,7 +237,7 @@ void netlist_mame_rom_t::static_set_params(device_t &device, const char *name, c
|
||||
{
|
||||
netlist_mame_rom_t &r = downcast<netlist_mame_rom_t&>(device);
|
||||
LOG_DEV_CALLS(("static_set_params %s\n", device.tag()));
|
||||
r.m_name = name;
|
||||
r.m_name = pstring(name, pstring::UTF8);
|
||||
r.m_region_tag = region_tag;
|
||||
r.m_offset = offset;
|
||||
r.m_size = size;
|
||||
@ -272,7 +272,7 @@ void netlist_ram_pointer_t::static_set_params(device_t &device, const char *para
|
||||
{
|
||||
netlist_ram_pointer_t &netlist = downcast<netlist_ram_pointer_t&>(device);
|
||||
LOG_DEV_CALLS(("static_set_params %s\n", device.tag()));
|
||||
netlist.m_param_name = param_name;
|
||||
netlist.m_param_name = pstring(param_name, pstring::UTF8);
|
||||
}
|
||||
|
||||
void netlist_ram_pointer_t::device_start()
|
||||
@ -303,7 +303,7 @@ netlist_mame_stream_input_t::netlist_mame_stream_input_t(const machine_config &m
|
||||
void netlist_mame_stream_input_t::static_set_params(device_t &device, int channel, const char *param_name)
|
||||
{
|
||||
netlist_mame_stream_input_t &netlist = downcast<netlist_mame_stream_input_t &>(device);
|
||||
netlist.m_param_name = param_name;
|
||||
netlist.m_param_name = pstring(param_name, pstring::UTF8);
|
||||
netlist.m_channel = channel;
|
||||
}
|
||||
|
||||
@ -340,7 +340,7 @@ netlist_mame_stream_output_t::netlist_mame_stream_output_t(const machine_config
|
||||
void netlist_mame_stream_output_t::static_set_params(device_t &device, int channel, const char *out_name)
|
||||
{
|
||||
netlist_mame_stream_output_t &netlist = downcast<netlist_mame_stream_output_t &>(device);
|
||||
netlist.m_out_name = out_name;
|
||||
netlist.m_out_name = pstring(out_name, pstring::UTF8);
|
||||
netlist.m_channel = channel;
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,8 @@
|
||||
|
||||
#define NETLIB_DEVICE_DECL(chip) extern factory::constructor_ptr_t decl_ ## chip;
|
||||
|
||||
#define ENTRYX1(nic, name, defparam, decl) factory.register_device( decl (# name, xstr(nic), defparam) );
|
||||
//#define ENTRYX1(nic, name, defparam, decl) factory.register_device( decl (# name, xstr(nic), defparam) );
|
||||
#define ENTRYX1(nic, name, defparam, decl) factory.register_device( decl (pstring(# name), pstring(xstr(nic)), pstring(defparam)) );
|
||||
#define ENTRYX(nic, name, defparam) { NETLIB_DEVICE_DECL(nic) ENTRYX1(NETLIB_NAME(nic), name, defparam, decl_ ## nic) }
|
||||
|
||||
namespace netlist
|
||||
|
@ -168,7 +168,7 @@ namespace netlist
|
||||
{
|
||||
while (*desc != nullptr && **desc != 0 )
|
||||
{
|
||||
m_desc.push_back(*desc);
|
||||
m_desc.push_back(pstring(*desc, pstring::UTF8));
|
||||
desc++;
|
||||
}
|
||||
init();
|
||||
|
@ -112,8 +112,10 @@ namespace netlist
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
pstring devname = out_proxied->device().name();
|
||||
auto tp = netlist().setup().find_terminal(devname + "." + power_syms[i][0], detail::device_object_t::type_t::INPUT, false);
|
||||
auto tn = netlist().setup().find_terminal(devname + "." + power_syms[i][1], detail::device_object_t::type_t::INPUT, false);
|
||||
auto tp = netlist().setup().find_terminal(devname + "." + pstring(power_syms[i][0], pstring::UTF8),
|
||||
detail::device_object_t::type_t::INPUT, false);
|
||||
auto tn = netlist().setup().find_terminal(devname + "." + pstring(power_syms[i][1], pstring::UTF8),
|
||||
detail::device_object_t::type_t::INPUT, false);
|
||||
if (tp != nullptr && tn != nullptr)
|
||||
{
|
||||
/* alternative logic */
|
||||
|
@ -199,7 +199,7 @@ void detail::queue_t::on_post_load()
|
||||
netlist().log().debug("current time {1} qsize {2}\n", netlist().time().as_double(), m_qsize);
|
||||
for (std::size_t i = 0; i < m_qsize; i++ )
|
||||
{
|
||||
detail::net_t *n = netlist().find_net(m_names[i].m_buf);
|
||||
detail::net_t *n = netlist().find_net(pstring(m_names[i].m_buf, pstring::UTF8));
|
||||
//log().debug("Got {1} ==> {2}\n", qtemp[i].m_name, n));
|
||||
//log().debug("schedule time {1} ({2})\n", n->time().as_double(), netlist_time::from_raw(m_times[i]).as_double()));
|
||||
this->push(n, netlist_time::from_raw(m_times[i]));
|
||||
@ -726,7 +726,7 @@ void device_t::connect_post_start(detail::core_terminal_t &t1, detail::core_term
|
||||
// family_setter_t
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
detail::family_setter_t::family_setter_t(core_device_t &dev, const char *desc)
|
||||
detail::family_setter_t::family_setter_t(core_device_t &dev, const pstring desc)
|
||||
{
|
||||
dev.set_logic_family(dev.netlist().family_from_model(desc));
|
||||
}
|
||||
|
@ -1159,7 +1159,7 @@ namespace netlist
|
||||
struct detail::family_setter_t
|
||||
{
|
||||
family_setter_t() { }
|
||||
family_setter_t(core_device_t &dev, const char *desc);
|
||||
family_setter_t(core_device_t &dev, const pstring desc);
|
||||
family_setter_t(core_device_t &dev, const logic_family_desc_t *desc);
|
||||
};
|
||||
|
||||
@ -1278,11 +1278,11 @@ namespace netlist
|
||||
|
||||
template<typename O, typename C> void save(O &owner, C &state, const pstring &stname)
|
||||
{
|
||||
this->state().save_item(static_cast<void *>(&owner), state, owner.name() + pstring(".") + stname);
|
||||
this->state().save_item(static_cast<void *>(&owner), state, pstring::from_utf8(owner.name()) + pstring(".") + stname);
|
||||
}
|
||||
template<typename O, typename C> void save(O &owner, C *state, const pstring &stname, const std::size_t count)
|
||||
{
|
||||
this->state().save_state_ptr(static_cast<void *>(&owner), owner.name() + pstring(".") + stname, plib::state_manager_t::datatype_f<C>::f(), count, state);
|
||||
this->state().save_state_ptr(static_cast<void *>(&owner), pstring::from_utf8(owner.name()) + pstring(".") + stname, plib::state_manager_t::datatype_f<C>::f(), count, state);
|
||||
}
|
||||
|
||||
void rebuild_lists(); /* must be called after post_load ! */
|
||||
@ -1342,7 +1342,7 @@ namespace netlist
|
||||
object_array_t(core_device_t &dev, init names)
|
||||
{
|
||||
for (std::size_t i = 0; i<N; i++)
|
||||
this->emplace(i, dev, names.p[i]);
|
||||
this->emplace(i, dev, pstring(names.p[i], pstring::UTF8));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -29,13 +29,8 @@ bool parser_t::parse(const pstring nlname)
|
||||
{
|
||||
set_identifier_chars("abcdefghijklmnopqrstuvwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_.-");
|
||||
set_number_chars(".0123456789", "0123456789eE-."); //FIXME: processing of numbers
|
||||
char ws[5];
|
||||
ws[0] = ' ';
|
||||
ws[1] = 9;
|
||||
ws[2] = 10;
|
||||
ws[3] = 13;
|
||||
ws[4] = 0;
|
||||
set_whitespace(ws);
|
||||
//const char ws[5] = { ' ', 9, 10, 13, 0 };
|
||||
set_whitespace(pstring("").cat(' ').cat(9).cat(10).cat(13));
|
||||
set_comment("/*", "*/", "//");
|
||||
m_tok_param_left = register_token("(");
|
||||
m_tok_param_right = register_token(")");
|
||||
@ -404,7 +399,7 @@ void parser_t::device(const pstring &dev_type)
|
||||
|
||||
nl_double parser_t::eval_param(const token_t tok)
|
||||
{
|
||||
static const char *macs[6] = {"", "RES_K", "RES_M", "CAP_U", "CAP_N", "CAP_P"};
|
||||
static pstring macs[6] = {"", "RES_K", "RES_M", "CAP_U", "CAP_N", "CAP_P"};
|
||||
static nl_double facs[6] = {1, 1e3, 1e6, 1e-6, 1e-9, 1e-12};
|
||||
int i;
|
||||
int f=0;
|
||||
|
@ -140,17 +140,17 @@ pstring setup_t::objtype_as_str(detail::device_object_t &in) const
|
||||
switch (in.type())
|
||||
{
|
||||
case terminal_t::TERMINAL:
|
||||
return "TERMINAL";
|
||||
return pstring("TERMINAL");
|
||||
case terminal_t::INPUT:
|
||||
return "INPUT";
|
||||
return pstring("INPUT");
|
||||
case terminal_t::OUTPUT:
|
||||
return "OUTPUT";
|
||||
return pstring("OUTPUT");
|
||||
case terminal_t::PARAM:
|
||||
return "PARAM";
|
||||
return pstring("PARAM");
|
||||
}
|
||||
// FIXME: noreturn
|
||||
log().fatal(MF_1_UNKNOWN_OBJECT_TYPE_1, static_cast<unsigned>(in.type()));
|
||||
return "Error";
|
||||
return pstring("Error");
|
||||
}
|
||||
|
||||
pstring setup_t::get_initial_param_val(const pstring name, const pstring def)
|
||||
@ -526,7 +526,8 @@ void setup_t::connect_terminal_input(terminal_t &term, detail::core_terminal_t &
|
||||
}
|
||||
else if (inp.is_logic())
|
||||
{
|
||||
log().verbose("connect terminal {1} (in, {2}) to {3}\n", inp.name(), pstring(inp.is_analog() ? "analog" : inp.is_logic() ? "logic" : "?"), term.name());
|
||||
log().verbose("connect terminal {1} (in, {2}) to {3}\n", inp.name(),
|
||||
inp.is_analog() ? pstring("analog") : inp.is_logic() ? pstring("logic") : pstring("?"), term.name());
|
||||
auto proxy = get_a_d_proxy(inp);
|
||||
|
||||
//out.net().register_con(proxy->proxy_term());
|
||||
|
@ -356,7 +356,7 @@ namespace netlist
|
||||
{
|
||||
public:
|
||||
source_mem_t(setup_t &setup, const char *mem)
|
||||
: source_t(setup), m_str(mem)
|
||||
: source_t(setup), m_str(mem, pstring::UTF8)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ public:
|
||||
explicit pfmt(const char *fmt);
|
||||
virtual ~pfmt();
|
||||
|
||||
operator pstring() const { return m_str; }
|
||||
operator pstring() const { return pstring(m_str, pstring::UTF8); }
|
||||
|
||||
const char *cstr() { return m_str; }
|
||||
|
||||
@ -196,7 +196,7 @@ public:
|
||||
|
||||
void operator ()(const char *fmt) const
|
||||
{
|
||||
if (build_enabled && m_enabled) vdowrite(fmt);
|
||||
if (build_enabled && m_enabled) vdowrite(pstring(fmt, pstring::UTF8));
|
||||
}
|
||||
|
||||
template<typename T1>
|
||||
|
@ -102,11 +102,11 @@ namespace plib {
|
||||
|
||||
int options::parse(int argc, char *argv[])
|
||||
{
|
||||
m_app = argv[0];
|
||||
m_app = pstring(argv[0], pstring::UTF8);
|
||||
|
||||
for (int i=1; i<argc; )
|
||||
{
|
||||
pstring arg(argv[i]);
|
||||
pstring arg(argv[i], pstring::UTF8);
|
||||
option *opt = nullptr;
|
||||
pstring opt_arg;
|
||||
bool has_equal_arg = false;
|
||||
@ -148,7 +148,7 @@ namespace plib {
|
||||
else
|
||||
{
|
||||
i++; // FIXME: are there more arguments?
|
||||
if (opt->parse(argv[i]) != 0)
|
||||
if (opt->parse(pstring(argv[i], pstring::UTF8)) != 0)
|
||||
return i - 1;
|
||||
}
|
||||
}
|
||||
|
@ -97,14 +97,15 @@ const pstring_t<F> pstring_t<F>::substr(const iterator start, const iterator end
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
template<typename F>
|
||||
const pstring_t<F> pstring_t<F>::ucase() const
|
||||
{
|
||||
pstring_t ret = *this;
|
||||
ret.pcopy(c_str(), blen());
|
||||
for (std::size_t i=0; i<ret.len(); i++)
|
||||
ret.m_ptr->str()[i] = static_cast<char>(toupper(static_cast<int>(ret.m_ptr->str()[i])));
|
||||
pstring_t ret = "";
|
||||
for (auto c : *this)
|
||||
if (c >= 'a' && c <= 'z')
|
||||
ret += (c - 'a' + 'A');
|
||||
else
|
||||
ret += c;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -151,7 +152,7 @@ typename pstring_t<F>::iterator pstring_t<F>::find_last_not_of(const pstring_t &
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
typename pstring_t<F>::iterator pstring_t<F>::find(const pstring_t &search, iterator start) const
|
||||
typename pstring_t<F>::iterator pstring_t<F>::find(const pstring_t search, iterator start) const
|
||||
{
|
||||
for (; start != end(); ++start)
|
||||
{
|
||||
@ -168,6 +169,15 @@ typename pstring_t<F>::iterator pstring_t<F>::find(const pstring_t &search, iter
|
||||
return end();
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
typename pstring_t<F>::iterator pstring_t<F>::find(const code_t search, iterator start) const
|
||||
{
|
||||
mem_t buf[traits::MAXCODELEN+1] = { 0 };
|
||||
traits::encode(search, buf);
|
||||
return find(pstring_t(&buf[0], UTF8), start);
|
||||
}
|
||||
|
||||
|
||||
template<typename F>
|
||||
pstring_t<F> pstring_t<F>::replace(const pstring_t &search, const pstring_t &replace) const
|
||||
{
|
||||
@ -188,13 +198,13 @@ pstring_t<F> pstring_t<F>::replace(const pstring_t &search, const pstring_t &rep
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
const pstring_t<F> pstring_t<F>::ltrim(const pstring_t &ws) const
|
||||
const pstring_t<F> pstring_t<F>::ltrim(const pstring_t ws) const
|
||||
{
|
||||
return substr(find_first_not_of(ws), end());
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
const pstring_t<F> pstring_t<F>::rtrim(const pstring_t &ws) const
|
||||
const pstring_t<F> pstring_t<F>::rtrim(const pstring_t ws) const
|
||||
{
|
||||
auto f = find_last_not_of(ws);
|
||||
if (f==end())
|
||||
@ -255,24 +265,6 @@ long pstring_t<F>::as_long(bool *error) const
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
typename pstring_t<F>::iterator pstring_t<F>::find(const mem_t *search, iterator start) const
|
||||
{
|
||||
for (; start != end(); ++start)
|
||||
{
|
||||
iterator itc(start);
|
||||
iterator cmp(search);
|
||||
while (itc != end() && *cmp != 0 && *itc == *cmp)
|
||||
{
|
||||
++itc;
|
||||
++cmp;
|
||||
}
|
||||
if (*cmp == 0)
|
||||
return start;
|
||||
}
|
||||
return end();
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
bool pstring_t<F>::startsWith(const pstring_t &arg) const
|
||||
{
|
||||
@ -291,17 +283,6 @@ bool pstring_t<F>::endsWith(const pstring_t &arg) const
|
||||
return (memcmp(c_str()+this->blen()-arg.blen(), arg.c_str(), arg.blen()) == 0);
|
||||
}
|
||||
|
||||
|
||||
template<typename F>
|
||||
bool pstring_t<F>::startsWith(const mem_t *arg) const
|
||||
{
|
||||
std::size_t alen = strlen(arg);
|
||||
if (alen > blen())
|
||||
return false;
|
||||
else
|
||||
return (memcmp(arg, c_str(), alen) == 0);
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
int pstring_t<F>::pcmp(const mem_t *right) const
|
||||
{
|
||||
@ -501,7 +482,7 @@ void pstring_t<F>::sfree(pstr_t *s)
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
pstr_t *pstring_t<F>::salloc(int n)
|
||||
pstr_t *pstring_t<F>::salloc(std::size_t n)
|
||||
{
|
||||
int size = sizeof(pstr_t) + n + 1;
|
||||
pstr_t *p = (pstr_t *) plib::palloc_array<char>(size);
|
||||
|
@ -53,20 +53,36 @@ public:
|
||||
typedef typename F::code_t code_t;
|
||||
typedef std::size_t size_type;
|
||||
|
||||
// simple construction/destruction
|
||||
pstring_t()
|
||||
enum enc_t
|
||||
{
|
||||
init();
|
||||
UTF8
|
||||
};
|
||||
|
||||
// simple construction/destruction
|
||||
pstring_t() : m_ptr(&m_zero)
|
||||
{
|
||||
init(nullptr);
|
||||
}
|
||||
~pstring_t();
|
||||
|
||||
// construction with copy
|
||||
pstring_t(const mem_t *string) { init(); if (string != nullptr && *string != 0) pcopy(string); }
|
||||
pstring_t(const pstring_t &string) { init(); pcopy(string); }
|
||||
// FIXME: Do something with encoding
|
||||
pstring_t(const mem_t *string, const enc_t enc) : m_ptr(&m_zero)
|
||||
{
|
||||
init(string);
|
||||
}
|
||||
|
||||
template<typename C, std::size_t N>
|
||||
pstring_t(C (&string)[N]) : m_ptr(&m_zero) {
|
||||
static_assert(std::is_same<C, const mem_t>::value, "pstring constructor only accepts const mem_t");
|
||||
static_assert(N>0,"pstring from array of length 0");
|
||||
//static_assert(string[N-1] == 0, "pstring constructor parameter not a string literal");
|
||||
init(string);
|
||||
}
|
||||
|
||||
pstring_t(const pstring_t &string) : m_ptr(&m_zero) { init(string); }
|
||||
pstring_t(pstring_t &&string) : m_ptr(string.m_ptr) { string.m_ptr = nullptr; }
|
||||
|
||||
// assignment operators
|
||||
pstring_t &operator=(const mem_t *string) { pcopy(string); return *this; }
|
||||
pstring_t &operator=(const pstring_t &string) { pcopy(string); return *this; }
|
||||
|
||||
struct iterator final : public std::iterator<std::forward_iterator_tag, mem_t>
|
||||
@ -94,41 +110,24 @@ public:
|
||||
|
||||
// concatenation operators
|
||||
pstring_t& operator+=(const pstring_t &string) { pcat(string); return *this; }
|
||||
pstring_t& operator+=(const mem_t *string) { pcat(string); return *this; }
|
||||
friend pstring_t operator+(const pstring_t &lhs, const pstring_t &rhs) { return pstring_t(lhs) += rhs; }
|
||||
friend pstring_t operator+(const pstring_t &lhs, const mem_t *rhs) { return pstring_t(lhs) += rhs; }
|
||||
friend pstring_t operator+(const mem_t *lhs, const pstring_t &rhs) { return pstring_t(lhs) += rhs; }
|
||||
|
||||
// comparison operators
|
||||
bool operator==(const mem_t *string) const { return (pcmp(string) == 0); }
|
||||
bool operator==(const pstring_t &string) const { return (pcmp(string) == 0); }
|
||||
bool operator!=(const mem_t *string) const { return (pcmp(string) != 0); }
|
||||
bool operator!=(const pstring_t &string) const { return (pcmp(string) != 0); }
|
||||
|
||||
bool operator<(const mem_t *string) const { return (pcmp(string) < 0); }
|
||||
bool operator<(const pstring_t &string) const { return (pcmp(string) < 0); }
|
||||
bool operator<=(const mem_t *string) const { return (pcmp(string) <= 0); }
|
||||
bool operator<=(const pstring_t &string) const { return (pcmp(string) <= 0); }
|
||||
bool operator>(const mem_t *string) const { return (pcmp(string) > 0); }
|
||||
bool operator>(const pstring_t &string) const { return (pcmp(string) > 0); }
|
||||
bool operator>=(const mem_t *string) const { return (pcmp(string) >= 0); }
|
||||
bool operator>=(const pstring_t &string) const { return (pcmp(string) >= 0); }
|
||||
|
||||
bool equals(const pstring_t &string) const { return (pcmp(string) == 0); }
|
||||
|
||||
//int cmp(const pstring_t &string) const { return pcmp(string); }
|
||||
//int cmp(const mem_t *string) const { return pcmp(string); }
|
||||
|
||||
bool startsWith(const pstring_t &arg) const;
|
||||
bool startsWith(const mem_t *arg) const;
|
||||
|
||||
bool endsWith(const pstring_t &arg) const;
|
||||
bool endsWith(const mem_t *arg) const { return endsWith(pstring_t(arg)); }
|
||||
|
||||
pstring_t replace(const pstring_t &search, const pstring_t &replace) const;
|
||||
|
||||
const pstring_t cat(const pstring_t &s) const { return *this + s; }
|
||||
const pstring_t cat(const mem_t *s) const { return *this + s; }
|
||||
const pstring_t cat(const code_t c) const { return *this + c; }
|
||||
|
||||
size_type blen() const { return m_ptr->len(); }
|
||||
|
||||
@ -145,11 +144,9 @@ public:
|
||||
pstring_t& operator+=(const code_t c) { mem_t buf[traits::MAXCODELEN+1] = { 0 }; traits::encode(c, buf); pcat(buf); return *this; }
|
||||
friend pstring_t operator+(const pstring_t &lhs, const code_t rhs) { return pstring_t(lhs) += rhs; }
|
||||
|
||||
iterator find(const pstring_t &search, iterator start) const;
|
||||
iterator find(const pstring_t &search) const { return find(search, begin()); }
|
||||
iterator find(const mem_t *search, iterator start) const;
|
||||
iterator find(const mem_t *search) const { return find(search, begin()); }
|
||||
iterator find(const code_t search, iterator start) const { mem_t buf[traits::MAXCODELEN+1] = { 0 }; traits::encode(search, buf); return find(buf, start); }
|
||||
iterator find(const pstring_t search, iterator start) const;
|
||||
iterator find(const pstring_t search) const { return find(search, begin()); }
|
||||
iterator find(const code_t search, iterator start) const;
|
||||
iterator find(const code_t search) const { return find(search, begin()); }
|
||||
|
||||
const pstring_t substr(const iterator start, const iterator end) const ;
|
||||
@ -162,9 +159,9 @@ public:
|
||||
iterator find_first_not_of(const pstring_t &no) const;
|
||||
iterator find_last_not_of(const pstring_t &no) const;
|
||||
|
||||
const pstring_t ltrim(const pstring_t &ws = " \t\n\r") const;
|
||||
const pstring_t rtrim(const pstring_t &ws = " \t\n\r") const;
|
||||
const pstring_t trim(const pstring_t &ws = " \t\n\r") const { return this->ltrim(ws).rtrim(ws); }
|
||||
const pstring_t ltrim(const pstring_t ws = pstring_t(" \t\n\r")) const;
|
||||
const pstring_t rtrim(const pstring_t ws = pstring_t(" \t\n\r")) const;
|
||||
const pstring_t trim(const pstring_t ws = pstring_t(" \t\n\r")) const { return this->ltrim(ws).rtrim(ws); }
|
||||
|
||||
const pstring_t rpad(const pstring_t &ws, const size_type cnt) const;
|
||||
|
||||
@ -172,16 +169,29 @@ public:
|
||||
|
||||
const pstring_t ucase() const;
|
||||
|
||||
// FIXME: do something with encoding
|
||||
// FIXME: belongs into derived class
|
||||
// This is only used in state saving to support "owners" whose name() function
|
||||
// returns char*.
|
||||
static pstring_t from_utf8(const mem_t *c) { return pstring_t(c, UTF8); }
|
||||
static pstring_t from_utf8(const pstring_t &c) { return c; }
|
||||
|
||||
static void resetmem();
|
||||
|
||||
protected:
|
||||
pstr_t *m_ptr;
|
||||
|
||||
private:
|
||||
void init()
|
||||
void init(const mem_t *string)
|
||||
{
|
||||
m_ptr = &m_zero;
|
||||
m_ptr->m_ref_count++;
|
||||
if (string != nullptr && *string != 0)
|
||||
pcopy(string);
|
||||
}
|
||||
void init(const pstring_t &string)
|
||||
{
|
||||
m_ptr->m_ref_count++;
|
||||
pcopy(string);
|
||||
}
|
||||
|
||||
int pcmp(const pstring_t &right) const;
|
||||
@ -191,14 +201,12 @@ private:
|
||||
void pcopy(const mem_t *from, std::size_t size);
|
||||
|
||||
void pcopy(const mem_t *from);
|
||||
|
||||
void pcopy(const pstring_t &from)
|
||||
{
|
||||
sfree(m_ptr);
|
||||
m_ptr = from.m_ptr;
|
||||
m_ptr->m_ref_count++;
|
||||
}
|
||||
|
||||
void pcat(const mem_t *s);
|
||||
void pcat(const pstring_t &s);
|
||||
|
||||
@ -358,7 +366,8 @@ public:
|
||||
// C string conversion helpers
|
||||
const char *c_str() const { return m_ptr; }
|
||||
|
||||
operator pstring() const { return pstring(m_ptr); }
|
||||
// FIXME: encoding should be parameter
|
||||
operator pstring() const { return pstring(m_ptr, pstring::UTF8); }
|
||||
|
||||
// concatenation operators
|
||||
pstringbuffer& operator+=(const char c) { char buf[2] = { c, 0 }; pcat(buf); return *this; }
|
||||
|
@ -36,7 +36,7 @@ namespace plib
|
||||
if (getenv(var.c_str()) == nullptr)
|
||||
return default_val;
|
||||
else
|
||||
return pstring(getenv(var.c_str()));
|
||||
return pstring(getenv(var.c_str()), pstring::UTF8);
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,7 +139,7 @@ namespace plib
|
||||
if (*str == ',')
|
||||
{
|
||||
*bufp = 0;
|
||||
return pstring(buf);
|
||||
return pstring(buf, pstring::UTF8);
|
||||
}
|
||||
else if (*str != ' ')
|
||||
*bufp++ = *str;
|
||||
@ -152,6 +152,6 @@ namespace plib
|
||||
str++;
|
||||
}
|
||||
*bufp = 0;
|
||||
return pstring(buf);
|
||||
return pstring(buf, pstring::UTF8);
|
||||
}
|
||||
} // namespace plib
|
||||
|
@ -211,7 +211,7 @@ struct input_t
|
||||
if (e != 3)
|
||||
throw netlist::nl_exception(plib::pfmt("error {1} scanning line {2}\n")(e)(line));
|
||||
m_time = netlist::netlist_time::from_double(t);
|
||||
m_param = setup.find_param(buf, true);
|
||||
m_param = setup.find_param(pstring(buf, pstring::UTF8), true);
|
||||
}
|
||||
|
||||
void setparam()
|
||||
@ -585,7 +585,7 @@ int main(int argc, char *argv[])
|
||||
result = c.result();
|
||||
}
|
||||
/* present result */
|
||||
pout_strm.write(result.c_str());
|
||||
pout_strm.write(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -185,21 +185,21 @@ const pstring nl_convert_base_t::get_nl_val(const double val)
|
||||
{
|
||||
{
|
||||
int i = 0;
|
||||
while (m_units[i].m_unit != "-" )
|
||||
while (pstring(m_units[i].m_unit, pstring::UTF8) != "-" )
|
||||
{
|
||||
if (m_units[i].m_mult <= std::abs(val))
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
return plib::pfmt(m_units[i].m_func.c_str())(val / m_units[i].m_mult);
|
||||
return plib::pfmt(m_units[i].m_func)(val / m_units[i].m_mult);
|
||||
}
|
||||
}
|
||||
double nl_convert_base_t::get_sp_unit(const pstring &unit)
|
||||
{
|
||||
int i = 0;
|
||||
while (m_units[i].m_unit != "-")
|
||||
while (pstring(m_units[i].m_unit, pstring::UTF8) != "-")
|
||||
{
|
||||
if (m_units[i].m_unit == unit)
|
||||
if (pstring(m_units[i].m_unit, pstring::UTF8) == unit)
|
||||
return m_units[i].m_mult;
|
||||
i++;
|
||||
}
|
||||
@ -407,13 +407,7 @@ nl_convert_eagle_t::tokenizer::tokenizer(nl_convert_eagle_t &convert, plib::pist
|
||||
{
|
||||
set_identifier_chars("abcdefghijklmnopqrstuvwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_.-");
|
||||
set_number_chars(".0123456789", "0123456789eE-."); //FIXME: processing of numbers
|
||||
char ws[5];
|
||||
ws[0] = ' ';
|
||||
ws[1] = 9;
|
||||
ws[2] = 10;
|
||||
ws[3] = 13;
|
||||
ws[4] = 0;
|
||||
set_whitespace(ws);
|
||||
set_whitespace(pstring("").cat(' ').cat(9).cat(10).cat(13));
|
||||
/* FIXME: gnetlist doesn't print comments */
|
||||
set_comment("/*", "*/", "//");
|
||||
set_string_char('\'');
|
||||
@ -549,13 +543,7 @@ nl_convert_rinf_t::tokenizer::tokenizer(nl_convert_rinf_t &convert, plib::pistre
|
||||
{
|
||||
set_identifier_chars(".abcdefghijklmnopqrstuvwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_-");
|
||||
set_number_chars("0123456789", "0123456789eE-."); //FIXME: processing of numbers
|
||||
char ws[5];
|
||||
ws[0] = ' ';
|
||||
ws[1] = 9;
|
||||
ws[2] = 10;
|
||||
ws[3] = 13;
|
||||
ws[4] = 0;
|
||||
set_whitespace(ws);
|
||||
set_whitespace(pstring("").cat(' ').cat(9).cat(10).cat(13));
|
||||
/* FIXME: gnetlist doesn't print comments */
|
||||
set_comment("","","//"); // FIXME:needs to be confirmed
|
||||
set_string_char('"');
|
||||
@ -590,7 +578,7 @@ void nl_convert_rinf_t::convert(const pstring &contents)
|
||||
{
|
||||
plib::pistringstream istrm(contents);
|
||||
tokenizer tok(*this, istrm);
|
||||
auto lm = read_lib_map(s_lib_map);
|
||||
auto lm = read_lib_map(pstring(s_lib_map, pstring::UTF8));
|
||||
|
||||
out("NETLIST_START(dummy)\n");
|
||||
add_term("GND", "GND");
|
||||
|
@ -101,8 +101,8 @@ private:
|
||||
};
|
||||
|
||||
struct unit_t {
|
||||
pstring m_unit;
|
||||
pstring m_func;
|
||||
const char *m_unit;
|
||||
const char *m_func;
|
||||
double m_mult;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user