mirror of
https://github.com/holub/mame
synced 2025-04-24 17:30:55 +03:00
More c++ alignment. pstring now behaves like std::string. (nw)
This change removes all string extensions like trim, rpad, left, right, ... from pstring and replaces them by function templates. This aligns a lot better with the intentions of the standard library.
This commit is contained in:
parent
c5b3f76360
commit
1415421fd7
@ -444,7 +444,7 @@ netlist::setup_t &netlist_mame_device::setup()
|
||||
|
||||
void netlist_mame_device::register_memregion_source(netlist::setup_t &setup, const char *name)
|
||||
{
|
||||
setup.register_source(plib::make_unique_base<netlist::source_t, netlist_source_memregion_t>(setup, pstring(name, pstring::UTF8)));
|
||||
setup.register_source(plib::make_unique_base<netlist::source_t, netlist_source_memregion_t>(setup, pstring(name)));
|
||||
}
|
||||
|
||||
void netlist_mame_analog_input_device::write(const double val)
|
||||
@ -533,7 +533,7 @@ netlist_mame_analog_input_device::netlist_mame_analog_input_device(const machine
|
||||
void netlist_mame_analog_input_device::device_start()
|
||||
{
|
||||
LOGDEVCALLS("start\n");
|
||||
netlist::param_t *p = this->nl_owner().setup().find_param(pstring(m_param_name, pstring::UTF8));
|
||||
netlist::param_t *p = this->nl_owner().setup().find_param(pstring(m_param_name));
|
||||
m_param = dynamic_cast<netlist::param_double_t *>(p);
|
||||
if (m_param == nullptr)
|
||||
{
|
||||
@ -567,7 +567,7 @@ void netlist_mame_analog_output_device::set_params(const char *in_name, output_d
|
||||
|
||||
void netlist_mame_analog_output_device::custom_netlist_additions(netlist::setup_t &setup)
|
||||
{
|
||||
const pstring pin(m_in, pstring::UTF8);
|
||||
const pstring pin(m_in);
|
||||
pstring dname = pstring("OUT_") + pin;
|
||||
m_delegate.bind_relative_to(owner()->machine().root_device());
|
||||
|
||||
@ -602,7 +602,7 @@ void netlist_mame_logic_output_device::set_params(const char *in_name, output_de
|
||||
|
||||
void netlist_mame_logic_output_device::custom_netlist_additions(netlist::setup_t &setup)
|
||||
{
|
||||
pstring pin(m_in, pstring::UTF8);
|
||||
pstring pin(m_in);
|
||||
pstring dname = "OUT_" + pin;
|
||||
m_delegate.bind_relative_to(owner()->machine().root_device());
|
||||
|
||||
@ -643,7 +643,7 @@ void netlist_mame_int_input_device::set_params(const char *param_name, const uin
|
||||
void netlist_mame_int_input_device::device_start()
|
||||
{
|
||||
LOGDEVCALLS("start\n");
|
||||
netlist::param_t *p = downcast<netlist_mame_device *>(this->owner())->setup().find_param(pstring(m_param_name, pstring::UTF8));
|
||||
netlist::param_t *p = downcast<netlist_mame_device *>(this->owner())->setup().find_param(pstring(m_param_name));
|
||||
m_param = dynamic_cast<netlist::param_int_t *>(p);
|
||||
if (m_param == nullptr)
|
||||
{
|
||||
@ -674,7 +674,7 @@ void netlist_mame_logic_input_device::set_params(const char *param_name, const u
|
||||
void netlist_mame_logic_input_device::device_start()
|
||||
{
|
||||
LOGDEVCALLS("start\n");
|
||||
netlist::param_t *p = downcast<netlist_mame_device *>(this->owner())->setup().find_param(pstring(m_param_name, pstring::UTF8));
|
||||
netlist::param_t *p = downcast<netlist_mame_device *>(this->owner())->setup().find_param(pstring(m_param_name));
|
||||
m_param = dynamic_cast<netlist::param_logic_t *>(p);
|
||||
if (m_param == nullptr)
|
||||
{
|
||||
@ -705,7 +705,7 @@ void netlist_mame_ram_pointer_device::set_params(const char *param_name)
|
||||
void netlist_mame_ram_pointer_device::device_start()
|
||||
{
|
||||
LOGDEVCALLS("start\n");
|
||||
netlist::param_t *p = downcast<netlist_mame_device *>(this->owner())->setup().find_param(pstring(m_param_name, pstring::UTF8));
|
||||
netlist::param_t *p = downcast<netlist_mame_device *>(this->owner())->setup().find_param(pstring(m_param_name));
|
||||
m_param = dynamic_cast<netlist::param_ptr_t *>(p);
|
||||
if (m_param == nullptr)
|
||||
{
|
||||
@ -744,7 +744,7 @@ void netlist_mame_stream_input_device::custom_netlist_additions(netlist::setup_t
|
||||
setup.register_dev("NETDEV_SOUND_IN", "STREAM_INPUT");
|
||||
|
||||
pstring sparam = plib::pfmt("STREAM_INPUT.CHAN{1}")(m_channel);
|
||||
setup.register_param(sparam, pstring(m_param_name, pstring::UTF8));
|
||||
setup.register_param(sparam, pstring(m_param_name));
|
||||
sparam = plib::pfmt("STREAM_INPUT.MULT{1}")(m_channel);
|
||||
setup.register_param(sparam, m_mult);
|
||||
sparam = plib::pfmt("STREAM_INPUT.OFFSET{1}")(m_channel);
|
||||
@ -785,7 +785,7 @@ void netlist_mame_stream_output_device::custom_netlist_additions(netlist::setup_
|
||||
setup.register_param(sname + ".CHAN" , m_channel);
|
||||
setup.register_param(sname + ".MULT", m_mult);
|
||||
setup.register_param(sname + ".OFFSET", m_offset);
|
||||
setup.register_link(sname + ".IN", pstring(m_out_name, pstring::UTF8));
|
||||
setup.register_link(sname + ".IN", pstring(m_out_name));
|
||||
}
|
||||
|
||||
|
||||
|
@ -136,7 +136,7 @@ namespace netlist
|
||||
unsigned long total = 0;
|
||||
for (unsigned i=0; i<m_size; i++)
|
||||
{
|
||||
pati[i] = static_cast<unsigned long>(pat[i].as_long());
|
||||
pati[i] = static_cast<unsigned long>(plib::pstol(pat[i]));
|
||||
total += pati[i];
|
||||
}
|
||||
netlist_time ttotal = netlist_time::zero();
|
||||
|
@ -183,12 +183,12 @@ namespace netlist
|
||||
|
||||
for (std::size_t i=0; i < m_NI; i++)
|
||||
{
|
||||
inout[i] = inout[i].trim();
|
||||
inout[i] = plib::trim(inout[i]);
|
||||
m_I.emplace(i, *this, inout[i]);
|
||||
}
|
||||
for (std::size_t i=0; i < m_NO; i++)
|
||||
{
|
||||
out[i] = out[i].trim();
|
||||
out[i] = plib::trim(out[i]);
|
||||
m_Q.emplace(i, *this, out[i]);
|
||||
}
|
||||
// Connect output "Q" to input "_Q" if this exists
|
||||
@ -318,21 +318,21 @@ namespace netlist
|
||||
void truthtable_parser::parseline(unsigned cur, std::vector<pstring> list,
|
||||
tt_bitset state, uint_least64_t val, std::vector<uint_least8_t> &timing_index)
|
||||
{
|
||||
pstring elem = list[cur].trim();
|
||||
pstring elem = plib::trim(list[cur]);
|
||||
uint_least64_t start = 0;
|
||||
uint_least64_t end = 0;
|
||||
|
||||
if (elem.equals("0"))
|
||||
if (elem == "0")
|
||||
{
|
||||
start = 0;
|
||||
end = 0;
|
||||
}
|
||||
else if (elem.equals("1"))
|
||||
else if (elem == "1")
|
||||
{
|
||||
start = 1;
|
||||
end = 1;
|
||||
}
|
||||
else if (elem.equals("X"))
|
||||
else if (elem == "X")
|
||||
{
|
||||
start = 0;
|
||||
end = 1;
|
||||
@ -380,7 +380,7 @@ void truthtable_parser::parse(const std::vector<pstring> &truthtable)
|
||||
for (int j=0; j < 16; j++)
|
||||
m_timing_nt[j] = netlist_time::zero();
|
||||
|
||||
while (!ttline.equals(""))
|
||||
while (!(ttline == ""))
|
||||
{
|
||||
std::vector<pstring> io(plib::psplit(ttline,"|"));
|
||||
// checks
|
||||
@ -402,12 +402,12 @@ void truthtable_parser::parse(const std::vector<pstring> &truthtable)
|
||||
*/
|
||||
for (unsigned j=0; j<m_NO; j++)
|
||||
{
|
||||
pstring outs = out[j].trim();
|
||||
if (outs.equals("1"))
|
||||
pstring outs = plib::trim(out[j]);
|
||||
if (outs == "1")
|
||||
val.set(j);
|
||||
else
|
||||
nl_assert_always(outs.equals("0"), "Unknown value (not 0 or 1");
|
||||
netlist_time t = netlist_time::from_nsec(static_cast<unsigned long>(times[j].trim().as_long()));
|
||||
nl_assert_always(outs == "0", "Unknown value (not 0 or 1");
|
||||
netlist_time t = netlist_time::from_nsec(static_cast<unsigned long>(plib::pstol(plib::trim(times[j]))));
|
||||
uint_least8_t k=0;
|
||||
while (m_timing_nt[k] != netlist_time::zero() && m_timing_nt[k] != t)
|
||||
k++;
|
||||
|
@ -341,9 +341,8 @@ void netlist_t::start()
|
||||
if (p != setup().m_param_values.end())
|
||||
{
|
||||
//FIXME: turn this into a proper function
|
||||
bool error;
|
||||
auto v = p->second.as_double(&error);
|
||||
if (error || std::abs(v - std::floor(v)) > 1e-6 )
|
||||
auto v = plib::pstod(p->second);;
|
||||
if (std::abs(v - std::floor(v)) > 1e-6 )
|
||||
log().fatal(MF_1_HND_VAL_NOT_SUPPORTED, p->second);
|
||||
d->set_hint_deactivate(v == 0.0);
|
||||
}
|
||||
|
@ -1317,7 +1317,7 @@ namespace netlist
|
||||
private:
|
||||
|
||||
/* helper for save above */
|
||||
static pstring from_utf8(const char *c) { return pstring(c, pstring::UTF8); }
|
||||
static pstring from_utf8(const char *c) { return pstring(c); }
|
||||
static pstring from_utf8(const pstring &c) { return c; }
|
||||
|
||||
core_device_t *get_single_device(const pstring &classname, bool (*cc)(core_device_t *)) const;
|
||||
@ -1361,7 +1361,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, pstring(names.p[i], pstring::UTF8));
|
||||
this->emplace(i, dev, pstring(names.p[i]));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -29,7 +29,8 @@ bool parser_t::parse(const pstring &nlname)
|
||||
{
|
||||
set_identifier_chars("abcdefghijklmnopqrstuvwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_.-");
|
||||
set_number_chars(".0123456789", "0123456789eE-."); //FIXME: processing of numbers
|
||||
set_whitespace(pstring("").cat(' ').cat(9).cat(10).cat(13));
|
||||
//set_whitespace(pstring("").cat(' ').cat(9).cat(10).cat(13));
|
||||
set_whitespace(pstring("") + ' ' + (char)9 + (char)10 + (char)13);
|
||||
set_comment("/*", "*/", "//");
|
||||
m_tok_param_left = register_token("(");
|
||||
m_tok_param_right = register_token(")");
|
||||
@ -360,7 +361,7 @@ void parser_t::device(const pstring &dev_type)
|
||||
for (pstring tp : paramlist)
|
||||
{
|
||||
require_token(m_tok_comma);
|
||||
if (tp.startsWith("+"))
|
||||
if (plib::startsWith(tp, "+"))
|
||||
{
|
||||
pstring output_name = get_identifier();
|
||||
m_setup.log().debug("Link: {1} {2}\n", tp, output_name);
|
||||
@ -401,12 +402,11 @@ nl_double parser_t::eval_param(const token_t tok)
|
||||
static nl_double facs[6] = {1, 1e3, 1e6, 1e-6, 1e-9, 1e-12};
|
||||
int i;
|
||||
int f=0;
|
||||
bool e;
|
||||
nl_double ret;
|
||||
pstring val;
|
||||
|
||||
for (i=1; i<6;i++)
|
||||
if (tok.str().equals(macs[i]))
|
||||
if (tok.str() == macs[i])
|
||||
f = i;
|
||||
if (f>0)
|
||||
{
|
||||
@ -417,8 +417,7 @@ nl_double parser_t::eval_param(const token_t tok)
|
||||
else
|
||||
{
|
||||
val = tok.str();
|
||||
ret = val.as_double(&e);
|
||||
if (e)
|
||||
if (!plib::pstod_ne(val, ret))
|
||||
error(plib::pfmt("Parameter value <{1}> not double \n")(val));
|
||||
}
|
||||
return ret * facs[f];
|
||||
|
@ -97,8 +97,8 @@ void setup_t::register_model(const pstring &model_in)
|
||||
auto pos = model_in.find(" ");
|
||||
if (pos == pstring::npos)
|
||||
log().fatal(MF_1_UNABLE_TO_PARSE_MODEL_1, model_in);
|
||||
pstring model = model_in.left(pos).trim().ucase();
|
||||
pstring def = model_in.substr(pos + 1).trim();
|
||||
pstring model = plib::ucase(plib::trim(plib::left(model_in, pos)));
|
||||
pstring def = plib::trim(model_in.substr(pos + 1));
|
||||
if (!m_models.insert({model, def}).second)
|
||||
log().fatal(MF_1_MODEL_ALREADY_EXISTS_1, model_in);
|
||||
}
|
||||
@ -797,15 +797,15 @@ void setup_t::model_parse(const pstring &model_in, detail::model_map_t &map)
|
||||
pos = model.find("(");
|
||||
if (pos != pstring::npos) break;
|
||||
|
||||
key = model.ucase();
|
||||
key = plib::ucase(model);
|
||||
auto i = m_models.find(key);
|
||||
if (i == m_models.end())
|
||||
log().fatal(MF_1_MODEL_NOT_FOUND, model);
|
||||
model = i->second;
|
||||
}
|
||||
pstring xmodel = model.left(pos);
|
||||
pstring xmodel = plib::left(model, pos);
|
||||
|
||||
if (xmodel.equals("_"))
|
||||
if (xmodel == "_")
|
||||
map["COREMODEL"] = key;
|
||||
else
|
||||
{
|
||||
@ -816,11 +816,11 @@ void setup_t::model_parse(const pstring &model_in, detail::model_map_t &map)
|
||||
log().fatal(MF_1_MODEL_NOT_FOUND, model_in);
|
||||
}
|
||||
|
||||
pstring remainder = model.substr(pos + 1).trim();
|
||||
if (!remainder.endsWith(")"))
|
||||
pstring remainder = plib::trim(model.substr(pos + 1));
|
||||
if (!plib::endsWith(remainder, ")"))
|
||||
log().fatal(MF_1_MODEL_ERROR_1, model);
|
||||
// FIMXE: Not optimal
|
||||
remainder = remainder.left(remainder.length() - 1);
|
||||
remainder = plib::left(remainder, remainder.size() - 1);
|
||||
|
||||
std::vector<pstring> pairs(plib::psplit(remainder," ", true));
|
||||
for (pstring &pe : pairs)
|
||||
@ -828,7 +828,7 @@ void setup_t::model_parse(const pstring &model_in, detail::model_map_t &map)
|
||||
auto pose = pe.find("=");
|
||||
if (pose == pstring::npos)
|
||||
log().fatal(MF_1_MODEL_ERROR_ON_PAIR_1, model);
|
||||
map[pe.left(pose).ucase()] = pe.substr(pose + 1);
|
||||
map[plib::ucase(plib::left(pe, pose))] = pe.substr(pose + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -836,7 +836,7 @@ const pstring setup_t::model_value_str(detail::model_map_t &map, const pstring &
|
||||
{
|
||||
pstring ret;
|
||||
|
||||
if (entity != entity.ucase())
|
||||
if (entity != plib::ucase(entity))
|
||||
log().fatal(MF_2_MODEL_PARAMETERS_NOT_UPPERCASE_1_2, entity,
|
||||
model_string(map));
|
||||
if (map.find(entity) == map.end())
|
||||
@ -852,7 +852,7 @@ nl_double setup_t::model_value(detail::model_map_t &map, const pstring &entity)
|
||||
pstring tmp = model_value_str(map, entity);
|
||||
|
||||
nl_double factor = NL_FCONST(1.0);
|
||||
auto p = std::next(tmp.begin(), static_cast<pstring::difference_type>(tmp.length() - 1));
|
||||
auto p = std::next(tmp.begin(), static_cast<pstring::difference_type>(tmp.size() - 1));
|
||||
switch (*p)
|
||||
{
|
||||
case 'M': factor = 1e6; break;
|
||||
@ -868,8 +868,8 @@ nl_double setup_t::model_value(detail::model_map_t &map, const pstring &entity)
|
||||
log().fatal(MF_1_UNKNOWN_NUMBER_FACTOR_IN_1, entity);
|
||||
}
|
||||
if (factor != NL_FCONST(1.0))
|
||||
tmp = tmp.left(tmp.length() - 1);
|
||||
return tmp.as_double() * factor;
|
||||
tmp = plib::left(tmp, tmp.size() - 1);
|
||||
return plib::pstod(tmp) * factor;
|
||||
}
|
||||
|
||||
class logic_family_std_proxy_t : public logic_family_desc_t
|
||||
@ -970,11 +970,11 @@ bool setup_t::parse_stream(plib::putf8_reader &istrm, const pstring &name)
|
||||
return parser_t(reader2, *this).parse(name);
|
||||
}
|
||||
|
||||
void setup_t::register_define(pstring defstr)
|
||||
void setup_t::register_define(const pstring &defstr)
|
||||
{
|
||||
auto p = defstr.find("=");
|
||||
if (p != pstring::npos)
|
||||
register_define(defstr.left(p), defstr.substr(p+1));
|
||||
register_define(plib::left(defstr, p), defstr.substr(p+1));
|
||||
else
|
||||
register_define(defstr, "1");
|
||||
}
|
||||
@ -997,12 +997,12 @@ bool source_t::parse(const pstring &name)
|
||||
|
||||
std::unique_ptr<plib::pistream> source_string_t::stream(const pstring &name)
|
||||
{
|
||||
return plib::make_unique_base<plib::pistream, plib::pimemstream>(m_str.c_str(), m_str.mem_t_size());
|
||||
return plib::make_unique_base<plib::pistream, plib::pimemstream>(m_str.c_str(), std::strlen(m_str.c_str()));
|
||||
}
|
||||
|
||||
std::unique_ptr<plib::pistream> source_mem_t::stream(const pstring &name)
|
||||
{
|
||||
return plib::make_unique_base<plib::pistream, plib::pimemstream>(m_str.c_str(), m_str.mem_t_size());
|
||||
return plib::make_unique_base<plib::pistream, plib::pimemstream>(m_str.c_str(), std::strlen(m_str.c_str()));
|
||||
}
|
||||
|
||||
std::unique_ptr<plib::pistream> source_file_t::stream(const pstring &name)
|
||||
|
@ -269,7 +269,7 @@ namespace netlist
|
||||
}
|
||||
|
||||
void register_define(pstring def, pstring val) { m_defines.push_back(plib::ppreprocessor::define_t(def, val)); }
|
||||
void register_define(pstring defstr);
|
||||
void register_define(const pstring &defstr);
|
||||
|
||||
factory::list_t &factory() { return m_factory; }
|
||||
const factory::list_t &factory() const { return m_factory; }
|
||||
@ -371,7 +371,7 @@ namespace netlist
|
||||
{
|
||||
public:
|
||||
source_mem_t(setup_t &setup, const char *mem)
|
||||
: source_t(setup), m_str(mem, pstring::UTF8)
|
||||
: source_t(setup), m_str(mem)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ pfmt &pfmt::format_element(const char *l, const unsigned cfmt_spec, ...)
|
||||
|
||||
pstring search("{");
|
||||
search += plib::to_string(m_arg);
|
||||
sl = search.length();
|
||||
sl = search.size();
|
||||
|
||||
auto p = m_str.find(search + ":");
|
||||
sl++; // ":"
|
||||
@ -65,13 +65,13 @@ pfmt &pfmt::format_element(const char *l, const unsigned cfmt_spec, ...)
|
||||
fmt += ((m_arg>=10) ? m_str.substr(p+4, p1 - p - 4) : m_str.substr(p+3, p1 - p - 3));
|
||||
}
|
||||
}
|
||||
pstring::code_t pend = fmt.at(fmt.length() - 1);
|
||||
pstring::value_type pend = fmt.at(fmt.size() - 1);
|
||||
if (pstring("duxo").find(cfmt_spec) != pstring::npos)
|
||||
{
|
||||
if (pstring("duxo").find(pend) == pstring::npos)
|
||||
fmt += (pstring(l, pstring::UTF8) + cfmt_spec);
|
||||
fmt += (pstring(l) + (char) cfmt_spec);
|
||||
else
|
||||
fmt = fmt.left(fmt.length() - 1) + pstring(l, pstring::UTF8) + fmt.right(1);
|
||||
fmt = plib::left(fmt, fmt.size() - 1) + pstring(l) + plib::right(fmt, 1);
|
||||
}
|
||||
else if (pstring("fge").find(cfmt_spec) != pstring::npos)
|
||||
{
|
||||
@ -82,7 +82,7 @@ pfmt &pfmt::format_element(const char *l, const unsigned cfmt_spec, ...)
|
||||
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);
|
||||
m_str = m_str.substr(0, p) + pstring(buf) + m_str.substr(p + sl);
|
||||
va_end(ap);
|
||||
return *this;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ namespace plib {
|
||||
|
||||
void pfunction::compile(const std::vector<pstring> &inputs, const pstring &expr)
|
||||
{
|
||||
if (expr.startsWith("rpn:"))
|
||||
if (plib::startsWith(expr, "rpn:"))
|
||||
compile_postfix(inputs, expr.substr(4));
|
||||
else
|
||||
compile_infix(inputs, expr);
|
||||
@ -68,10 +68,8 @@ void pfunction::compile_postfix(const std::vector<pstring> &inputs,
|
||||
}
|
||||
if (rc.m_cmd != PUSH_INPUT)
|
||||
{
|
||||
bool err = false;
|
||||
rc.m_cmd = PUSH_CONST;
|
||||
rc.m_param = cmd.as_double(&err);
|
||||
if (err)
|
||||
if (!plib::pstod_ne(cmd, rc.m_param))
|
||||
throw plib::pexception(plib::pfmt("nld_function: unknown/misformatted token <{1}> in <{2}>")(cmd)(expr));
|
||||
stk += 1;
|
||||
}
|
||||
@ -88,7 +86,7 @@ static int get_prio(pstring v)
|
||||
{
|
||||
if (v == "(" || v == ")")
|
||||
return 1;
|
||||
else if (v.left(1) >= "a" && v.left(1) <= "z")
|
||||
else if (plib::left(v, 1) >= "a" && plib::left(v, 1) <= "z")
|
||||
return 0;
|
||||
else if (v == "*" || v == "/")
|
||||
return 20;
|
||||
@ -113,7 +111,7 @@ void pfunction::compile_infix(const std::vector<pstring> &inputs, const pstring
|
||||
{
|
||||
// Shunting-yard infix parsing
|
||||
std::vector<pstring> sep = {"(", ")", ",", "*", "/", "+", "-", "^"};
|
||||
std::vector<pstring> sexpr(plib::psplit(expr.replace_all(" ",""), sep));
|
||||
std::vector<pstring> sexpr(plib::psplit(plib::replace_all(expr, pstring(" "), pstring("")), sep));
|
||||
std::stack<pstring> opstk;
|
||||
std::vector<pstring> postfix;
|
||||
|
||||
|
@ -65,16 +65,28 @@ namespace plib {
|
||||
|
||||
int option_double::parse(const pstring &argument)
|
||||
{
|
||||
bool err = false;
|
||||
m_val = argument.as_double(&err);
|
||||
return (err ? 1 : 0);
|
||||
try
|
||||
{
|
||||
m_val = plib::pstod(argument);
|
||||
return 0;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int option_long::parse(const pstring &argument)
|
||||
{
|
||||
bool err = false;
|
||||
m_val = argument.as_long(&err);
|
||||
return (err ? 1 : 0);
|
||||
try
|
||||
{
|
||||
m_val = plib::pstol(argument);
|
||||
return 0;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int option_vec::parse(const pstring &argument)
|
||||
@ -110,16 +122,16 @@ namespace plib {
|
||||
|
||||
int options::parse(int argc, char *argv[])
|
||||
{
|
||||
m_app = pstring(argv[0], pstring::UTF8);
|
||||
m_app = pstring(argv[0]);
|
||||
|
||||
for (int i=1; i<argc; )
|
||||
{
|
||||
pstring arg(argv[i], pstring::UTF8);
|
||||
pstring arg(argv[i]);
|
||||
option *opt = nullptr;
|
||||
pstring opt_arg;
|
||||
bool has_equal_arg = false;
|
||||
|
||||
if (arg.startsWith("--"))
|
||||
if (plib::startsWith(arg, "--"))
|
||||
{
|
||||
auto v = psplit(arg.substr(2),"=");
|
||||
opt = getopt_long(v[0]);
|
||||
@ -131,7 +143,7 @@ namespace plib {
|
||||
opt_arg += v[v.size()-1];
|
||||
}
|
||||
}
|
||||
else if (arg.startsWith("-"))
|
||||
else if (plib::startsWith(arg, "-"))
|
||||
{
|
||||
std::size_t p = 1;
|
||||
opt = getopt_short(arg.substr(p, 1));
|
||||
@ -158,7 +170,7 @@ namespace plib {
|
||||
else
|
||||
{
|
||||
i++; // FIXME: are there more arguments?
|
||||
if (opt->do_parse(pstring(argv[i], pstring::UTF8)) != 0)
|
||||
if (opt->do_parse(pstring(argv[i])) != 0)
|
||||
return i - 1;
|
||||
}
|
||||
}
|
||||
@ -181,13 +193,13 @@ namespace plib {
|
||||
|
||||
for (auto &p : paragraphs)
|
||||
{
|
||||
pstring line = pstring("").rpad(" ", firstline_indent);
|
||||
pstring line = plib::rpad(pstring(""), pstring(" "), firstline_indent);
|
||||
for (auto &s : psplit(p, " "))
|
||||
{
|
||||
if (line.length() + s.length() > width)
|
||||
{
|
||||
ret += line + "\n";
|
||||
line = pstring("").rpad(" ", indent);
|
||||
line = plib::rpad(pstring(""), pstring(" "), indent);
|
||||
}
|
||||
line += s + " ";
|
||||
}
|
||||
@ -228,13 +240,13 @@ namespace plib {
|
||||
{
|
||||
line += v + "|";
|
||||
}
|
||||
line = line.left(line.length() - 1);
|
||||
line = plib::left(line, line.length() - 1);
|
||||
}
|
||||
else
|
||||
line += "Value";
|
||||
}
|
||||
}
|
||||
line = line.rpad(" ", indent - 2) + " ";
|
||||
line = plib::rpad(line, pstring(" "), indent - 2) + " ";
|
||||
if (line.length() > indent)
|
||||
{
|
||||
//ret += "TestGroup abc\n def gef\nxyz\n\n" ;
|
||||
|
@ -34,7 +34,7 @@ pstring ptokenizer::currentline_str()
|
||||
|
||||
void ptokenizer::skipeol()
|
||||
{
|
||||
pstring::code_t c = getc();
|
||||
pstring::value_type c = getc();
|
||||
while (c)
|
||||
{
|
||||
if (c == 10)
|
||||
@ -49,11 +49,11 @@ void ptokenizer::skipeol()
|
||||
}
|
||||
|
||||
|
||||
pstring::code_t ptokenizer::getc()
|
||||
pstring::value_type ptokenizer::getc()
|
||||
{
|
||||
if (m_unget != 0)
|
||||
{
|
||||
pstring::code_t c = m_unget;
|
||||
pstring::value_type c = m_unget;
|
||||
m_unget = 0;
|
||||
return c;
|
||||
}
|
||||
@ -66,11 +66,11 @@ pstring::code_t ptokenizer::getc()
|
||||
return 0;
|
||||
return '\n';
|
||||
}
|
||||
pstring::code_t c = *(m_px++);
|
||||
pstring::value_type c = *(m_px++);
|
||||
return c;
|
||||
}
|
||||
|
||||
void ptokenizer::ungetc(pstring::code_t c)
|
||||
void ptokenizer::ungetc(pstring::value_type c)
|
||||
{
|
||||
m_unget = c;
|
||||
}
|
||||
@ -129,9 +129,9 @@ double ptokenizer::get_number_double()
|
||||
{
|
||||
error(pfmt("Expected a number, got <{1}>")(tok.str()) );
|
||||
}
|
||||
bool err = false;
|
||||
double ret = tok.str().as_double(&err);
|
||||
if (err)
|
||||
double ret = 0.0;
|
||||
|
||||
if (!plib::pstod_ne(tok.str(), ret))
|
||||
error(pfmt("Expected a number, got <{1}>")(tok.str()) );
|
||||
return ret;
|
||||
}
|
||||
@ -143,9 +143,8 @@ long ptokenizer::get_number_long()
|
||||
{
|
||||
error(pfmt("Expected a long int, got <{1}>")(tok.str()) );
|
||||
}
|
||||
bool err = false;
|
||||
long ret = tok.str().as_long(&err);
|
||||
if (err)
|
||||
long ret = 0;
|
||||
if (!plib::pstol_ne(tok.str(), ret))
|
||||
error(pfmt("Expected a long int, got <{1}>")(tok.str()) );
|
||||
return ret;
|
||||
}
|
||||
@ -182,7 +181,7 @@ ptokenizer::token_t ptokenizer::get_token()
|
||||
ptokenizer::token_t ptokenizer::get_token_internal()
|
||||
{
|
||||
/* skip ws */
|
||||
pstring::code_t c = getc();
|
||||
pstring::value_type c = getc();
|
||||
while (m_whitespace.find(c) != pstring::npos)
|
||||
{
|
||||
c = getc();
|
||||
@ -327,7 +326,7 @@ double ppreprocessor::expr(const std::vector<pstring> &sexpr, std::size_t &start
|
||||
else
|
||||
{
|
||||
tok=sexpr[start];
|
||||
val = tok.as_double();
|
||||
val = plib::pstod(tok);
|
||||
start++;
|
||||
}
|
||||
while (start < sexpr.size())
|
||||
@ -410,57 +409,59 @@ static pstring catremainder(const std::vector<pstring> &elems, std::size_t start
|
||||
|
||||
pstring ppreprocessor::process_line(const pstring &line)
|
||||
{
|
||||
pstring lt = line.replace_all("\t"," ").trim();
|
||||
//pstring lt = plib::trim(plib::replace_all(line, pstring("\t"), pstring(" ")));
|
||||
pstring a = plib::replace_all(line, pstring("\t"), pstring(" "));
|
||||
pstring lt = plib::trim(a);
|
||||
pstring ret;
|
||||
m_lineno++;
|
||||
// FIXME ... revise and extend macro handling
|
||||
if (lt.startsWith("#"))
|
||||
if (plib::startsWith(lt, "#"))
|
||||
{
|
||||
std::vector<pstring> lti(psplit(lt, " ", true));
|
||||
if (lti[0].equals("#if"))
|
||||
if (lti[0] == "#if")
|
||||
{
|
||||
m_level++;
|
||||
std::size_t start = 0;
|
||||
lt = replace_macros(lt);
|
||||
std::vector<pstring> t(psplit(lt.substr(3).replace_all(" ",""), m_expr_sep));
|
||||
std::vector<pstring> t(psplit(replace_all(lt.substr(3), pstring(" "), pstring("")), m_expr_sep));
|
||||
int val = static_cast<int>(expr(t, start, 0));
|
||||
if (val == 0)
|
||||
m_ifflag |= (1 << m_level);
|
||||
}
|
||||
else if (lti[0].equals("#ifdef"))
|
||||
else if (lti[0] == "#ifdef")
|
||||
{
|
||||
m_level++;
|
||||
if (get_define(lti[1]) == nullptr)
|
||||
m_ifflag |= (1 << m_level);
|
||||
}
|
||||
else if (lti[0].equals("#ifndef"))
|
||||
else if (lti[0] == "#ifndef")
|
||||
{
|
||||
m_level++;
|
||||
if (get_define(lti[1]) != nullptr)
|
||||
m_ifflag |= (1 << m_level);
|
||||
}
|
||||
else if (lti[0].equals("#else"))
|
||||
else if (lti[0] == "#else")
|
||||
{
|
||||
m_ifflag ^= (1 << m_level);
|
||||
}
|
||||
else if (lti[0].equals("#endif"))
|
||||
else if (lti[0] == "#endif")
|
||||
{
|
||||
m_ifflag &= ~(1 << m_level);
|
||||
m_level--;
|
||||
}
|
||||
else if (lti[0].equals("#include"))
|
||||
else if (lti[0] == "#include")
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
else if (lti[0].equals("#pragma"))
|
||||
else if (lti[0] == "#pragma")
|
||||
{
|
||||
if (m_ifflag == 0 && lti.size() > 3 && lti[1].equals("NETLIST"))
|
||||
if (m_ifflag == 0 && lti.size() > 3 && lti[1] == "NETLIST")
|
||||
{
|
||||
if (lti[2].equals("warning"))
|
||||
if (lti[2] == "warning")
|
||||
error("NETLIST: " + catremainder(lti, 3, " "));
|
||||
}
|
||||
}
|
||||
else if (lti[0].equals("#define"))
|
||||
else if (lti[0] == "#define")
|
||||
{
|
||||
if (m_ifflag == 0)
|
||||
{
|
||||
|
@ -100,7 +100,7 @@ public:
|
||||
|
||||
void set_identifier_chars(pstring s) { m_identifier_chars = s; }
|
||||
void set_number_chars(pstring st, pstring rem) { m_number_chars_start = st; m_number_chars = rem; }
|
||||
void set_string_char(pstring::code_t c) { m_string = c; }
|
||||
void set_string_char(pstring::value_type c) { m_string = c; }
|
||||
void set_whitespace(pstring s) { m_whitespace = s; }
|
||||
void set_comment(pstring start, pstring end, pstring line)
|
||||
{
|
||||
@ -118,8 +118,8 @@ protected:
|
||||
private:
|
||||
void skipeol();
|
||||
|
||||
pstring::code_t getc();
|
||||
void ungetc(pstring::code_t c);
|
||||
pstring::value_type getc();
|
||||
void ungetc(pstring::value_type c);
|
||||
|
||||
bool eof() { return m_strm.eof(); }
|
||||
|
||||
@ -128,7 +128,7 @@ private:
|
||||
int m_lineno;
|
||||
pstring m_cur_line;
|
||||
pstring::const_iterator m_px;
|
||||
pstring::code_t m_unget;
|
||||
pstring::value_type m_unget;
|
||||
|
||||
/* tokenizer stuff follows ... */
|
||||
|
||||
@ -137,7 +137,7 @@ private:
|
||||
pstring m_number_chars_start;
|
||||
std::unordered_map<pstring, token_id_t> m_tokens;
|
||||
pstring m_whitespace;
|
||||
pstring::code_t m_string;
|
||||
pstring::value_type m_string;
|
||||
|
||||
token_id_t m_tok_comment_start;
|
||||
token_id_t m_tok_comment_end;
|
||||
|
@ -259,12 +259,12 @@ pstdout::~pstdout()
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
pimemstream::pimemstream(const void *mem, const pos_type len)
|
||||
: pistream(FLAG_SEEKABLE), m_pos(0), m_len(len), m_mem(static_cast<const pstring::mem_t *>(mem))
|
||||
: pistream(FLAG_SEEKABLE), m_pos(0), m_len(len), m_mem(static_cast<const char *>(mem))
|
||||
{
|
||||
}
|
||||
|
||||
pimemstream::pimemstream(const pomemstream &ostrm)
|
||||
: pistream(FLAG_SEEKABLE), m_pos(0), m_len(ostrm.size()), m_mem(reinterpret_cast<pstring::mem_t *>(ostrm.memory()))
|
||||
: pistream(FLAG_SEEKABLE), m_pos(0), m_len(ostrm.size()), m_mem(reinterpret_cast<const char *>(ostrm.memory()))
|
||||
{
|
||||
}
|
||||
|
||||
@ -366,7 +366,7 @@ pstream::pos_type pomemstream::vtell()
|
||||
|
||||
bool putf8_reader::readline(pstring &line)
|
||||
{
|
||||
pstring::code_t c = 0;
|
||||
putf8string::code_t c = 0;
|
||||
m_linebuf = "";
|
||||
if (!this->readcode(c))
|
||||
{
|
||||
@ -378,11 +378,11 @@ bool putf8_reader::readline(pstring &line)
|
||||
if (c == 10)
|
||||
break;
|
||||
else if (c != 13) /* ignore CR */
|
||||
m_linebuf += pstring(c);
|
||||
m_linebuf += putf8string(c);
|
||||
if (!this->readcode(c))
|
||||
break;
|
||||
}
|
||||
line = m_linebuf;
|
||||
line = m_linebuf.c_str();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -154,10 +154,10 @@ protected:
|
||||
/* write n bytes to stream */
|
||||
virtual void vwrite(const void *buf, const pos_type n) override
|
||||
{
|
||||
m_buf += pstring(static_cast<const pstring::mem_t *>(buf), n, pstring::UTF8);
|
||||
m_buf += pstring(static_cast<const char *>(buf), n);
|
||||
}
|
||||
virtual void vseek(const pos_type n) override { }
|
||||
virtual pos_type vtell() override { return m_buf.mem_t_size(); }
|
||||
virtual pos_type vtell() override { return m_buf.size(); }
|
||||
|
||||
private:
|
||||
pstring m_buf;
|
||||
@ -284,7 +284,7 @@ private:
|
||||
class pistringstream : public pimemstream
|
||||
{
|
||||
public:
|
||||
explicit pistringstream(const pstring &str) : pimemstream(str.c_str(), str.mem_t_size()), m_str(str) { }
|
||||
explicit pistringstream(const pstring &str) : pimemstream(str.c_str(), std::strlen(str.c_str())), m_str(str) { }
|
||||
virtual ~pistringstream() override;
|
||||
|
||||
private:
|
||||
@ -312,22 +312,22 @@ public:
|
||||
return (m_strm.read(&b, 1) == 1);
|
||||
}
|
||||
|
||||
bool readcode(pstring::code_t &c)
|
||||
bool readcode(putf8string::traits_type::code_t &c)
|
||||
{
|
||||
char b[4];
|
||||
if (m_strm.read(&b[0], 1) != 1)
|
||||
return false;
|
||||
const std::size_t l = pstring::traits_type::codelen(b);
|
||||
const std::size_t l = putf8string::traits_type::codelen(b);
|
||||
for (std::size_t i = 1; i < l; i++)
|
||||
if (m_strm.read(&b[i], 1) != 1)
|
||||
return false;
|
||||
c = pstring::traits_type::code(b);
|
||||
c = putf8string::traits_type::code(b);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
pistream &m_strm;
|
||||
pstring m_linebuf;
|
||||
putf8string m_linebuf;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -348,12 +348,14 @@ public:
|
||||
|
||||
void write(const pstring &text) const
|
||||
{
|
||||
m_strm.write(text.c_str(), text.mem_t_size());
|
||||
putf8string conv_utf8(text);
|
||||
m_strm.write(conv_utf8.c_str(), conv_utf8.mem_t_size());
|
||||
}
|
||||
|
||||
void write(const pstring::code_t c) const
|
||||
void write(const pstring::value_type c) const
|
||||
{
|
||||
write(pstring(c));
|
||||
pstring t = pstring("") + c;
|
||||
write(t);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -391,8 +393,10 @@ public:
|
||||
|
||||
void write(const pstring &s)
|
||||
{
|
||||
write(s.mem_t_size());
|
||||
m_strm.write(s.c_str(), s.mem_t_size());
|
||||
const char *sm = s.c_str();
|
||||
const std::size_t sl = std::strlen(sm);
|
||||
write(sl);
|
||||
m_strm.write(sm, sl);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -423,10 +427,10 @@ public:
|
||||
{
|
||||
std::size_t sz = 0;
|
||||
read(sz);
|
||||
pstring::mem_t *buf = new pstring::mem_t[sz+1];
|
||||
plib::string_info<pstring>::mem_t *buf = new plib::string_info<pstring>::mem_t[sz+1];
|
||||
m_strm.read(buf, sz);
|
||||
buf[sz] = 0;
|
||||
s = pstring(buf, pstring::UTF8);
|
||||
s = pstring(buf);
|
||||
delete [] buf;
|
||||
}
|
||||
|
||||
|
@ -66,18 +66,6 @@ pstring_t<F> pstring_t<F>::substr(size_type start, size_type nlen) const
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
pstring_t<F> pstring_t<F>::ucase() const
|
||||
{
|
||||
pstring_t ret;
|
||||
for (const auto &c : *this)
|
||||
if (c >= 'a' && c <= 'z')
|
||||
ret += (c - 'a' + 'A');
|
||||
else
|
||||
ret += c;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
typename pstring_t<F>::size_type pstring_t<F>::find_first_not_of(const pstring_t &no) const
|
||||
{
|
||||
@ -150,114 +138,6 @@ typename pstring_t<F>::size_type pstring_t<F>::find(code_t search, size_type sta
|
||||
return find(ss, start);
|
||||
}
|
||||
|
||||
|
||||
template<typename F>
|
||||
pstring_t<F> pstring_t<F>::replace_all(const pstring_t &search, const pstring_t &replace) const
|
||||
{
|
||||
pstring_t ret;
|
||||
const size_type slen = search.length();
|
||||
|
||||
size_type last_s = 0;
|
||||
size_type s = find(search, last_s);
|
||||
while (s != npos)
|
||||
{
|
||||
ret += substr(last_s, s - last_s);
|
||||
ret += replace;
|
||||
last_s = s + slen;
|
||||
s = find(search, last_s);
|
||||
}
|
||||
ret += substr(last_s);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
pstring_t<F> pstring_t<F>::rpad(const pstring_t &ws, const size_type cnt) const
|
||||
{
|
||||
// FIXME: pstringbuffer ret(*this);
|
||||
|
||||
pstring_t ret(*this);
|
||||
size_type wsl = ws.length();
|
||||
for (auto i = ret.length(); i < cnt; i+=wsl)
|
||||
ret += ws;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static double pstod(const pstring_t<pu8_traits> &str, std::size_t *e)
|
||||
{
|
||||
return std::stod(str.cpp_string(), e);
|
||||
}
|
||||
|
||||
static double pstod(const pstring &str, std::size_t *e)
|
||||
{
|
||||
return std::stod(str.cpp_string(), e);
|
||||
}
|
||||
|
||||
static double pstod(const pwstring &str, std::size_t *e)
|
||||
{
|
||||
return std::stod(str.cpp_string(), e);
|
||||
}
|
||||
|
||||
static double pstod(const pu16string &str, std::size_t *e)
|
||||
{
|
||||
pstring c;
|
||||
c = str;
|
||||
return std::stod(c.cpp_string(), e);
|
||||
}
|
||||
|
||||
static long pstol(const pstring_t<pu8_traits> &str, std::size_t *e, int base = 10)
|
||||
{
|
||||
return std::stol(str.cpp_string(), e, base);
|
||||
}
|
||||
|
||||
static long pstol(const pstring &str, std::size_t *e, int base = 10)
|
||||
{
|
||||
return std::stol(str.cpp_string(), e, base);
|
||||
}
|
||||
|
||||
static long pstol(const pwstring &str, std::size_t *e, int base = 10)
|
||||
{
|
||||
return std::stol(str.cpp_string(), e, base);
|
||||
}
|
||||
|
||||
static long pstol(const pu16string &str, std::size_t *e, int base = 10)
|
||||
{
|
||||
pstring c;
|
||||
c = str;
|
||||
return std::stol(c.cpp_string(), e, base);
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
double pstring_t<F>::as_double(bool *error) const
|
||||
{
|
||||
std::size_t e = 0;
|
||||
if (error != nullptr)
|
||||
*error = false;
|
||||
double ret = pstod(*this, &e);
|
||||
if (e != mem_t_size())
|
||||
if (error != nullptr)
|
||||
*error = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
long pstring_t<F>::as_long(bool *error) const
|
||||
{
|
||||
static pstring_t prefix(pstring("0x"));
|
||||
long ret;
|
||||
std::size_t e = 0;
|
||||
|
||||
if (error != nullptr)
|
||||
*error = false;
|
||||
if (startsWith(prefix))
|
||||
ret = pstol(substr(2), &e, 16);
|
||||
else
|
||||
ret = pstol(*this, &e, 10);
|
||||
if (e != mem_t_size())
|
||||
if (error != nullptr)
|
||||
*error = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// template stuff ...
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
@ -10,14 +10,19 @@
|
||||
#include <iterator>
|
||||
#include <exception>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// pstring: semi-immutable strings ...
|
||||
//
|
||||
// The only reason this class exists is the absence of support for multi-byte
|
||||
// strings in std:: which I would consider usuable for the use-cases I encounter.
|
||||
// strings in std:: which I would consider sub-optimal for the use-cases I encounter.
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
// enable this to use std::string instead of pstring globally.
|
||||
|
||||
#define PSTRING_USE_STD_STRING (0)
|
||||
|
||||
template <typename T>
|
||||
class pstring_const_iterator final
|
||||
{
|
||||
@ -64,6 +69,7 @@ public:
|
||||
|
||||
typedef typename traits_type::mem_t mem_t;
|
||||
typedef typename traits_type::code_t code_t;
|
||||
typedef typename traits_type::code_t value_type;
|
||||
typedef std::size_t size_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef typename traits_type::string_type string_type;
|
||||
@ -83,12 +89,6 @@ public:
|
||||
typedef const ref_value_type& const_reference;
|
||||
typedef const_reference reference;
|
||||
|
||||
enum enc_t
|
||||
{
|
||||
UTF8,
|
||||
UTF16
|
||||
};
|
||||
|
||||
// simple construction/destruction
|
||||
pstring_t()
|
||||
{
|
||||
@ -98,12 +98,12 @@ public:
|
||||
}
|
||||
|
||||
// FIXME: Do something with encoding
|
||||
pstring_t(const mem_t *string, const enc_t enc)
|
||||
pstring_t(const mem_t *string)
|
||||
: m_str(string)
|
||||
{
|
||||
}
|
||||
|
||||
pstring_t(const mem_t *string, const size_type len, const enc_t enc)
|
||||
pstring_t(const mem_t *string, const size_type len)
|
||||
: m_str(string, len)
|
||||
{
|
||||
}
|
||||
@ -122,7 +122,7 @@ public:
|
||||
: m_str(string.m_str)
|
||||
{ }
|
||||
|
||||
explicit pstring_t(const string_type &string, const enc_t enc)
|
||||
explicit pstring_t(const string_type &string)
|
||||
: m_str(string)
|
||||
{ }
|
||||
|
||||
@ -201,49 +201,12 @@ public:
|
||||
|
||||
const_reference at(const size_type pos) const { return *reinterpret_cast<const ref_value_type *>(F::nthcode(m_str.c_str(),pos)); }
|
||||
|
||||
/* The following is not compatible to std::string */
|
||||
|
||||
bool equals(const pstring_t &string) const { return (compare(string) == 0); }
|
||||
|
||||
bool startsWith(const pstring_t &arg) const { return arg.mem_t_size() > mem_t_size() ? false : m_str.compare(0, arg.mem_t_size(), arg.m_str) == 0; }
|
||||
bool endsWith(const pstring_t &arg) const { return arg.mem_t_size() > mem_t_size() ? false : m_str.compare(mem_t_size()-arg.mem_t_size(), arg.mem_t_size(), arg.m_str) == 0; }
|
||||
|
||||
pstring_t replace_all(const pstring_t &search, const pstring_t &replace) const;
|
||||
pstring_t cat(const pstring_t &s) const { return *this + s; }
|
||||
pstring_t cat(code_t c) const { return *this + c; }
|
||||
|
||||
// conversions
|
||||
|
||||
double as_double(bool *error = nullptr) const;
|
||||
long as_long(bool *error = nullptr) const;
|
||||
|
||||
/* the following are extensions to <string> */
|
||||
|
||||
size_type mem_t_size() const { return m_str.size(); }
|
||||
|
||||
pstring_t left(size_type len) const { return substr(0, len); }
|
||||
pstring_t right(size_type nlen) const
|
||||
{
|
||||
return nlen >= length() ? *this : substr(length() - nlen, nlen);
|
||||
}
|
||||
|
||||
pstring_t ltrim(const pstring_t &ws = pstring_t(" \t\n\r")) const
|
||||
{
|
||||
return substr(find_first_not_of(ws));
|
||||
}
|
||||
|
||||
pstring_t rtrim(const pstring_t &ws = pstring_t(" \t\n\r")) const
|
||||
{
|
||||
auto f = find_last_not_of(ws);
|
||||
return f == npos ? pstring_t() : substr(0, f + 1);
|
||||
}
|
||||
|
||||
pstring_t trim(const pstring_t &ws = pstring_t(" \t\n\r")) const { return this->ltrim(ws).rtrim(ws); }
|
||||
|
||||
pstring_t rpad(const pstring_t &ws, const size_type cnt) const;
|
||||
|
||||
pstring_t ucase() const;
|
||||
|
||||
const string_type &cpp_string() const { return m_str; }
|
||||
|
||||
static const size_type npos = static_cast<size_type>(-1);
|
||||
@ -519,37 +482,259 @@ extern template struct pstring_t<putf8_traits>;
|
||||
extern template struct pstring_t<putf16_traits>;
|
||||
extern template struct pstring_t<pwchar_traits>;
|
||||
|
||||
#if (PSTRING_USE_STD_STRING)
|
||||
typedef std::string pstring;
|
||||
#else
|
||||
typedef pstring_t<putf8_traits> pstring;
|
||||
#endif
|
||||
typedef pstring_t<putf8_traits> putf8string;
|
||||
typedef pstring_t<putf16_traits> pu16string;
|
||||
typedef pstring_t<pwchar_traits> pwstring;
|
||||
|
||||
namespace plib
|
||||
{
|
||||
template<class T>
|
||||
struct string_info
|
||||
{
|
||||
typedef typename T::mem_t mem_t;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct string_info<std::string>
|
||||
{
|
||||
typedef char mem_t;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
pstring to_string(const T &v)
|
||||
{
|
||||
return pstring(std::to_string(v), pstring::UTF8);
|
||||
return pstring(std::to_string(v));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
pwstring to_wstring(const T &v)
|
||||
{
|
||||
return pwstring(std::to_wstring(v), pwstring::UTF16);
|
||||
return pwstring(std::to_wstring(v));
|
||||
}
|
||||
|
||||
#if (PSTRING_USE_STD_STRING)
|
||||
inline double pstod(const std::string &str, std::size_t *e = nullptr)
|
||||
{
|
||||
return std::stod(str, e);
|
||||
}
|
||||
|
||||
inline long pstol(const std::string &str, std::size_t *e = nullptr, int base = 10)
|
||||
{
|
||||
return std::stol(str, e, base);
|
||||
}
|
||||
#else
|
||||
template<typename T>
|
||||
double pstod(const T &str, std::size_t *e = nullptr)
|
||||
{
|
||||
return std::stod(str.cpp_string(), e);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
long pstol(const T &str, std::size_t *e = nullptr, int base = 10)
|
||||
{
|
||||
return std::stol(str.cpp_string(), e, base);
|
||||
}
|
||||
#endif
|
||||
|
||||
template<typename T, typename R>
|
||||
bool pstol_ne(const T &str, R &ret)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::size_t e = 0;
|
||||
ret = pstol(str, &e);
|
||||
return str.c_str()[e] == 0;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, typename R>
|
||||
bool pstod_ne(const T &str, R &ret)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::size_t e = 0;
|
||||
ret = pstod(str, &e);
|
||||
return str.c_str()[e] == 0;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
typename T::size_type find_first_not_of(const T &str, const T &no)
|
||||
{
|
||||
typename T::size_type pos = 0;
|
||||
for (auto it = str.begin(); it != str.end(); ++it, ++pos)
|
||||
{
|
||||
bool f = true;
|
||||
for (typename T::value_type const jt : no)
|
||||
{
|
||||
if (*it == jt)
|
||||
{
|
||||
f = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (f)
|
||||
return pos;
|
||||
}
|
||||
return T::npos;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
typename T::size_type find_last_not_of(const T &str, const T &no)
|
||||
{
|
||||
/* FIXME: reverse iterator */
|
||||
typename T::size_type last_found = T::npos;
|
||||
typename T::size_type pos = 0;
|
||||
for (auto it = str.begin(); it != str.end(); ++it, ++pos)
|
||||
{
|
||||
bool f = true;
|
||||
for (typename T::value_type const jt : no)
|
||||
{
|
||||
if (*it == jt)
|
||||
{
|
||||
f = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (f)
|
||||
last_found = pos;
|
||||
}
|
||||
return last_found;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T ltrim(const T &str, const T &ws = T(" \t\n\r"))
|
||||
{
|
||||
auto f = find_first_not_of(str, ws);
|
||||
return (f == T::npos) ? T() : str.substr(f);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T rtrim(const T &str, const T &ws = T(" \t\n\r"))
|
||||
{
|
||||
auto f = find_last_not_of(str, ws);
|
||||
return (f == T::npos) ? T() : str.substr(0, f + 1);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T trim(const T &str, const T &ws = T(" \t\n\r"))
|
||||
{
|
||||
return rtrim(ltrim(str, ws), ws);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T left(const T &str, typename T::size_type len)
|
||||
{
|
||||
return str.substr(0, len);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T right(const T &str, typename T::size_type nlen)
|
||||
{
|
||||
return nlen >= str.length() ? str : str.substr(str.length() - nlen, nlen);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool startsWith(const T &str, const T &arg)
|
||||
{
|
||||
return (arg == left(str, arg.length()));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool endsWith(const T &str, const T &arg)
|
||||
{
|
||||
return (right(str, arg.length()) == arg);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool startsWith(const T &str, const char *arg)
|
||||
{
|
||||
return (left(str, std::strlen(arg)) == arg);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool endsWith(const T &str, const char *arg)
|
||||
{
|
||||
return (right(str, std::strlen(arg)) == arg);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T ucase(const T &str)
|
||||
{
|
||||
T ret;
|
||||
for (const auto &c : str)
|
||||
if (c >= 'a' && c <= 'z')
|
||||
ret += (c - 'a' + 'A');
|
||||
else
|
||||
ret += c;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T rpad(const T &str, const T &ws, const typename T::size_type cnt)
|
||||
{
|
||||
// FIXME: pstringbuffer ret(*this);
|
||||
|
||||
T ret(str);
|
||||
typename T::size_type wsl = ws.length();
|
||||
for (auto i = ret.length(); i < cnt; i+=wsl)
|
||||
ret += ws;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T replace_all(const T &str, const T &search, const T &replace)
|
||||
{
|
||||
T ret;
|
||||
const typename T::size_type slen = search.length();
|
||||
|
||||
typename T::size_type last_s = 0;
|
||||
typename T::size_type s = str.find(search, last_s);
|
||||
while (s != T::npos)
|
||||
{
|
||||
ret += str.substr(last_s, s - last_s);
|
||||
ret += replace;
|
||||
last_s = s + slen;
|
||||
s = str.find(search, last_s);
|
||||
}
|
||||
ret += str.substr(last_s);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename T, typename T1, typename T2>
|
||||
T replace_all(const T &str, const T1 &search, const T2 &replace)
|
||||
{
|
||||
return replace_all(str, T(search), T(replace));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// custom specialization of std::hash can be injected in namespace std
|
||||
namespace std
|
||||
{
|
||||
|
||||
template<typename T> struct hash<pstring_t<T>>
|
||||
{
|
||||
typedef pstring_t<T> argument_type;
|
||||
typedef std::size_t result_type;
|
||||
result_type operator()(argument_type const& s) const
|
||||
{
|
||||
const pstring::mem_t *string = s.c_str();
|
||||
const typename argument_type::mem_t *string = s.c_str();
|
||||
result_type result = 5381;
|
||||
for (pstring::mem_t c = *string; c != 0; c = *string++)
|
||||
for (typename argument_type::mem_t c = *string; c != 0; c = *string++)
|
||||
result = ((result << 5) + result ) ^ (result >> (32 - 5)) ^ static_cast<result_type>(c);
|
||||
return result;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ namespace plib
|
||||
if (getenv(var.c_str()) == nullptr)
|
||||
return default_val;
|
||||
else
|
||||
return pstring(getenv(var.c_str()), pstring::UTF8);
|
||||
return pstring(getenv(var.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ namespace plib
|
||||
}
|
||||
else
|
||||
{
|
||||
pstring::code_t c = *i;
|
||||
pstring::value_type c = *i;
|
||||
col += c;
|
||||
i++;
|
||||
}
|
||||
@ -143,7 +143,7 @@ namespace plib
|
||||
if (*str == ',')
|
||||
{
|
||||
*bufp = 0;
|
||||
return pstring(buf, pstring::UTF8);
|
||||
return pstring(buf);
|
||||
}
|
||||
else if (*str != ' ')
|
||||
*bufp++ = *str;
|
||||
@ -156,6 +156,6 @@ namespace plib
|
||||
str++;
|
||||
}
|
||||
*bufp = 0;
|
||||
return pstring(buf, pstring::UTF8);
|
||||
return pstring(buf);
|
||||
}
|
||||
} // namespace plib
|
||||
|
@ -259,7 +259,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(pstring(buf, pstring::UTF8), true);
|
||||
m_param = setup.find_param(pstring(buf), true);
|
||||
}
|
||||
|
||||
void setparam()
|
||||
@ -423,7 +423,7 @@ void tool_app_t::mac_out(const pstring &s, const bool cont)
|
||||
unsigned adj = 0;
|
||||
for (const auto &x : s)
|
||||
adj += (x == '\t' ? 3 : 0);
|
||||
pout("{1}\\\n", s.rpad(" ", RIGHT-1-adj));
|
||||
pout("{1}\\\n", plib::rpad(s, pstring(" "), RIGHT-1-adj));
|
||||
}
|
||||
else
|
||||
pout("{1}\n", s);
|
||||
@ -434,14 +434,14 @@ void tool_app_t::cmac(const netlist::factory::element_t *e)
|
||||
auto v = plib::psplit(e->param_desc(), ",");
|
||||
pstring vs;
|
||||
for (auto s : v)
|
||||
vs += ", p" + s.replace_all("+", "").replace_all(".", "_");
|
||||
vs += ", p" + plib::replace_all(plib::replace_all(s, "+", ""), ".", "_");
|
||||
mac_out("#define " + e->name() + "(name" + vs + ")");
|
||||
mac_out("\tNET_REGISTER_DEV(" + e->name() +", name)");
|
||||
|
||||
for (auto s : v)
|
||||
{
|
||||
pstring r(s.replace_all("+", "").replace_all(".", "_"));
|
||||
if (s.startsWith("+"))
|
||||
pstring r(plib::replace_all(plib::replace_all(s, "+", ""), ".", "_"));
|
||||
if (plib::startsWith(s, "+"))
|
||||
mac_out("\tNET_CONNECT(name, " + r + ", p" + r + ")");
|
||||
else
|
||||
mac_out("\tNETDEV_PARAMI(name, " + r + ", p" + r + ")");
|
||||
@ -455,7 +455,7 @@ void tool_app_t::mac(const netlist::factory::element_t *e)
|
||||
pstring vs;
|
||||
for (auto s : v)
|
||||
{
|
||||
vs += ", " + s.replace_all("+", "").replace_all(".", "_");
|
||||
vs += ", " + plib::replace_all(plib::replace_all(s, "+", ""), ".", "_");
|
||||
}
|
||||
pout("{1}(name{2})\n", e->name(), vs);
|
||||
if (v.size() > 0)
|
||||
@ -463,8 +463,8 @@ void tool_app_t::mac(const netlist::factory::element_t *e)
|
||||
pout("/*\n");
|
||||
for (auto s : v)
|
||||
{
|
||||
pstring r(s.replace_all("+", "").replace_all(".", "_"));
|
||||
if (s.startsWith("+"))
|
||||
pstring r(plib::replace_all(plib::replace_all(s, "+", ""), ".", "_"));
|
||||
if (plib::startsWith(s, "+"))
|
||||
pout("{1:10}: Terminal\n",r);
|
||||
else
|
||||
pout("{1:10}: Parameter\n", r);
|
||||
@ -506,9 +506,9 @@ void tool_app_t::create_header()
|
||||
if (last_source != e->sourcefile())
|
||||
{
|
||||
last_source = e->sourcefile();
|
||||
pout("{1}\n", pstring("// ").rpad("-", 72));
|
||||
pout("{1}{2}\n", pstring("// Source: "), e->sourcefile().replace_all("../", ""));
|
||||
pout("{1}\n", pstring("// ").rpad("-", 72));
|
||||
pout("{1}\n", plib::rpad(pstring("// "), pstring("-"), 72));
|
||||
pout("{1}{2}\n", pstring("// Source: "), plib::replace_all(e->sourcefile(), "../", ""));
|
||||
pout("{1}\n", plib::rpad(pstring("// "), pstring("-"), 72));
|
||||
}
|
||||
cmac(e.get());
|
||||
}
|
||||
@ -600,7 +600,7 @@ void tool_app_t::listdevices()
|
||||
|
||||
for (auto & t : nt.setup().m_terminals)
|
||||
{
|
||||
if (t.second->name().startsWith(d->name()))
|
||||
if (plib::startsWith(t.second->name(), d->name()))
|
||||
{
|
||||
pstring tn(t.second->name().substr(d->name().length()+1));
|
||||
if (tn.find(".") == pstring::npos)
|
||||
@ -610,7 +610,7 @@ void tool_app_t::listdevices()
|
||||
|
||||
for (auto & t : nt.setup().m_alias)
|
||||
{
|
||||
if (t.first.startsWith(d->name()))
|
||||
if (plib::startsWith(t.first, d->name()))
|
||||
{
|
||||
pstring tn(t.first.substr(d->name().length()+1));
|
||||
//printf("\t%s %s %s\n", t.first.c_str(), t.second.c_str(), tn.c_str());
|
||||
@ -632,7 +632,7 @@ void tool_app_t::listdevices()
|
||||
out += "," + f->param_desc();
|
||||
for (auto p : plib::psplit(f->param_desc(),",") )
|
||||
{
|
||||
if (p.startsWith("+"))
|
||||
if (plib::startsWith(p, "+"))
|
||||
{
|
||||
plib::container::remove(terms, p.substr(1));
|
||||
}
|
||||
@ -733,19 +733,19 @@ int tool_app_t::execute()
|
||||
contents = ostrm.str();
|
||||
|
||||
pstring result;
|
||||
if (opt_type().equals("spice"))
|
||||
if (opt_type() == "spice")
|
||||
{
|
||||
nl_convert_spice_t c;
|
||||
c.convert(contents);
|
||||
result = c.result();
|
||||
}
|
||||
else if (opt_type().equals("eagle"))
|
||||
else if (opt_type() == "eagle")
|
||||
{
|
||||
nl_convert_eagle_t c;
|
||||
c.convert(contents);
|
||||
result = c.result();
|
||||
}
|
||||
else if (opt_type().equals("rinf"))
|
||||
else if (opt_type() == "rinf")
|
||||
{
|
||||
nl_convert_rinf_t c;
|
||||
c.convert(contents);
|
||||
|
@ -131,13 +131,13 @@ std::unique_ptr<matrix_solver_t> create_it(netlist_t &nl, pstring name, solver_p
|
||||
template <std::size_t m_N, std::size_t storage_N>
|
||||
std::unique_ptr<matrix_solver_t> NETLIB_NAME(solver)::create_solver(std::size_t size, const pstring &solvername)
|
||||
{
|
||||
if (pstring("SOR_MAT").equals(m_method()))
|
||||
if (m_method() == "SOR_MAT")
|
||||
{
|
||||
return create_it<matrix_solver_SOR_mat_t<m_N, storage_N>>(netlist(), solvername, m_params, size);
|
||||
//typedef matrix_solver_SOR_mat_t<m_N,storage_N> solver_sor_mat;
|
||||
//return plib::make_unique<solver_sor_mat>(netlist(), solvername, &m_params, size);
|
||||
}
|
||||
else if (pstring("MAT_CR").equals(m_method()))
|
||||
else if (m_method() == "MAT_CR")
|
||||
{
|
||||
if (size > 0) // GCR always outperforms MAT solver
|
||||
{
|
||||
@ -150,29 +150,29 @@ std::unique_ptr<matrix_solver_t> NETLIB_NAME(solver)::create_solver(std::size_t
|
||||
return plib::make_unique<solver_mat>(netlist(), solvername, &m_params, size);
|
||||
}
|
||||
}
|
||||
else if (pstring("MAT").equals(m_method()))
|
||||
else if (m_method() == "MAT")
|
||||
{
|
||||
typedef matrix_solver_direct_t<m_N,storage_N> solver_mat;
|
||||
return plib::make_unique<solver_mat>(netlist(), solvername, &m_params, size);
|
||||
}
|
||||
else if (pstring("SM").equals(m_method()))
|
||||
else if (m_method() == "SM")
|
||||
{
|
||||
/* Sherman-Morrison Formula */
|
||||
typedef matrix_solver_sm_t<m_N,storage_N> solver_mat;
|
||||
return plib::make_unique<solver_mat>(netlist(), solvername, &m_params, size);
|
||||
}
|
||||
else if (pstring("W").equals(m_method()))
|
||||
else if (m_method() == "W")
|
||||
{
|
||||
/* Woodbury Formula */
|
||||
typedef matrix_solver_w_t<m_N,storage_N> solver_mat;
|
||||
return plib::make_unique<solver_mat>(netlist(), solvername, &m_params, size);
|
||||
}
|
||||
else if (pstring("SOR").equals(m_method()))
|
||||
else if (m_method() == "SOR")
|
||||
{
|
||||
typedef matrix_solver_SOR_t<m_N,storage_N> solver_GS;
|
||||
return plib::make_unique<solver_GS>(netlist(), solvername, &m_params, size);
|
||||
}
|
||||
else if (pstring("GMRES").equals(m_method()))
|
||||
else if (m_method() == "GMRES")
|
||||
{
|
||||
typedef matrix_solver_GMRES_t<m_N,storage_N> solver_GMRES;
|
||||
return plib::make_unique<solver_GMRES>(netlist(), solvername, &m_params, size);
|
||||
@ -268,7 +268,7 @@ void NETLIB_NAME(solver)::post_start()
|
||||
// Override log statistics
|
||||
pstring p = plib::util::environment("NL_STATS", "");
|
||||
if (p != "")
|
||||
m_params.m_log_stats = p.as_long();
|
||||
m_params.m_log_stats = plib::pstol(p);
|
||||
else
|
||||
m_params.m_log_stats = m_log_stats();
|
||||
|
||||
|
@ -49,7 +49,7 @@ static lib_map_t read_lib_map(const pstring &lm)
|
||||
while (reader.readline(line))
|
||||
{
|
||||
std::vector<pstring> split(plib::psplit(line, ","));
|
||||
m[split[0].trim()] = { split[1].trim(), split[2].trim() };
|
||||
m[plib::trim(split[0])] = { plib::trim(split[1]), plib::trim(split[2]) };
|
||||
}
|
||||
return m;
|
||||
}
|
||||
@ -185,21 +185,21 @@ const pstring nl_convert_base_t::get_nl_val(const double val)
|
||||
{
|
||||
{
|
||||
int i = 0;
|
||||
while (pstring(m_units[i].m_unit, pstring::UTF8) != "-" )
|
||||
while (pstring(m_units[i].m_unit) != "-" )
|
||||
{
|
||||
if (m_units[i].m_mult <= std::abs(val))
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
return plib::pfmt(pstring(m_units[i].m_func, pstring::UTF8))(val / m_units[i].m_mult);
|
||||
return plib::pfmt(pstring(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 (pstring(m_units[i].m_unit, pstring::UTF8) != "-")
|
||||
while (pstring(m_units[i].m_unit) != "-")
|
||||
{
|
||||
if (pstring(m_units[i].m_unit, pstring::UTF8) == unit)
|
||||
if (pstring(m_units[i].m_unit) == unit)
|
||||
return m_units[i].m_mult;
|
||||
i++;
|
||||
}
|
||||
@ -212,9 +212,9 @@ double nl_convert_base_t::get_sp_val(const pstring &sin)
|
||||
std::size_t p = 0;
|
||||
while (p < sin.length() && (m_numberchars.find(sin.substr(p, 1)) != pstring::npos))
|
||||
++p;
|
||||
pstring val = sin.left(p);
|
||||
pstring val = plib::left(sin, p);
|
||||
pstring unit = sin.substr(p);
|
||||
double ret = get_sp_unit(unit) * val.as_double();
|
||||
double ret = get_sp_unit(unit) * plib::pstod(val);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -255,8 +255,8 @@ void nl_convert_spice_t::convert(const pstring &contents)
|
||||
for (std::size_t i=0; i < spnl.size(); i++)
|
||||
{
|
||||
// Basic preprocessing
|
||||
pstring inl = spnl[i].trim().ucase();
|
||||
if (inl.startsWith("+"))
|
||||
pstring inl = plib::ucase(plib::trim(spnl[i]));
|
||||
if (plib::startsWith(inl, "+"))
|
||||
line = line + inl.substr(1);
|
||||
else
|
||||
{
|
||||
@ -285,13 +285,13 @@ void nl_convert_spice_t::process_line(const pstring &line)
|
||||
out("// {}\n", line.substr(1).c_str());
|
||||
break;
|
||||
case '.':
|
||||
if (tt[0].equals(".SUBCKT"))
|
||||
if (tt[0] == ".SUBCKT")
|
||||
{
|
||||
out("NETLIST_START({})\n", tt[1].c_str());
|
||||
for (std::size_t i=2; i<tt.size(); i++)
|
||||
add_ext_alias(tt[i]);
|
||||
}
|
||||
else if (tt[0].equals(".ENDS"))
|
||||
else if (tt[0] == ".ENDS")
|
||||
{
|
||||
dump_nl();
|
||||
out("NETLIST_END()\n");
|
||||
@ -301,15 +301,14 @@ void nl_convert_spice_t::process_line(const pstring &line)
|
||||
break;
|
||||
case 'Q':
|
||||
{
|
||||
bool cerr = false;
|
||||
/* check for fourth terminal ... should be numeric net
|
||||
* including "0" or start with "N" (ltspice)
|
||||
*/
|
||||
ATTR_UNUSED long nval(tt[4].as_long(&cerr));
|
||||
long nval = 0;
|
||||
pstring model;
|
||||
pstring pins ="CBE";
|
||||
|
||||
if ((!cerr || tt[4].startsWith("N")) && tt.size() > 5)
|
||||
if ((!plib::pstol_ne(tt[4], nval) || plib::startsWith(tt[4], "N")) && tt.size() > 5)
|
||||
model = tt[5];
|
||||
else
|
||||
model = tt[4];
|
||||
@ -318,7 +317,7 @@ void nl_convert_spice_t::process_line(const pstring &line)
|
||||
{
|
||||
if (m[1].length() != 4)
|
||||
fprintf(stderr, "error with model desc %s\n", model.c_str());
|
||||
pins = m[1].left(3);
|
||||
pins = plib::left(m[1], 3);
|
||||
}
|
||||
add_device("QBJT_EB", tt[0], m[0]);
|
||||
add_term(tt[1], tt[0] + "." + pins.at(0));
|
||||
@ -327,7 +326,7 @@ void nl_convert_spice_t::process_line(const pstring &line)
|
||||
}
|
||||
break;
|
||||
case 'R':
|
||||
if (tt[0].startsWith("RV"))
|
||||
if (plib::startsWith(tt[0], "RV"))
|
||||
{
|
||||
val = get_sp_val(tt[4]);
|
||||
add_device("POT", tt[0], val);
|
||||
@ -351,7 +350,7 @@ void nl_convert_spice_t::process_line(const pstring &line)
|
||||
break;
|
||||
case 'V':
|
||||
// just simple Voltage sources ....
|
||||
if (tt[2].equals("0"))
|
||||
if (tt[2] == "0")
|
||||
{
|
||||
val = get_sp_val(tt[3]);
|
||||
add_device("ANALOG_INPUT", tt[0], val);
|
||||
@ -381,7 +380,7 @@ void nl_convert_spice_t::process_line(const pstring &line)
|
||||
// last element is component type
|
||||
// FIXME: Parameter
|
||||
|
||||
pstring xname = tt[0].replace_all(".", "_");
|
||||
pstring xname = plib::replace_all(tt[0], pstring("."), pstring("_"));
|
||||
pstring tname = "TTL_" + tt[tt.size()-1] + "_DIP";
|
||||
add_device(tname, xname);
|
||||
for (std::size_t i=1; i < tt.size() - 1; i++)
|
||||
@ -407,7 +406,8 @@ nl_convert_eagle_t::tokenizer::tokenizer(nl_convert_eagle_t &convert, plib::putf
|
||||
{
|
||||
set_identifier_chars("abcdefghijklmnopqrstuvwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_.-");
|
||||
set_number_chars(".0123456789", "0123456789eE-."); //FIXME: processing of numbers
|
||||
set_whitespace(pstring("").cat(' ').cat(9).cat(10).cat(13));
|
||||
//set_whitespace(pstring("").cat(' ').cat(9).cat(10).cat(13));
|
||||
set_whitespace(pstring("") + ' ' + (char)9 + (char)10 + (char)13);
|
||||
/* FIXME: gnetlist doesn't print comments */
|
||||
set_comment("/*", "*/", "//");
|
||||
set_string_char('\'');
|
||||
@ -487,12 +487,12 @@ void nl_convert_eagle_t::convert(const pstring &contents)
|
||||
}
|
||||
break;
|
||||
case 'P':
|
||||
if (sval.ucase() == "HIGH")
|
||||
if (plib::ucase(sval) == "HIGH")
|
||||
add_device("TTL_INPUT", name, 1);
|
||||
else if (sval.ucase() == "LOW")
|
||||
else if (plib::ucase(sval) == "LOW")
|
||||
add_device("TTL_INPUT", name, 0);
|
||||
else
|
||||
add_device("ANALOG_INPUT", name, sval.as_double());
|
||||
add_device("ANALOG_INPUT", name, plib::pstod(sval));
|
||||
add_pin_alias(name, "1", "Q");
|
||||
break;
|
||||
case 'D':
|
||||
@ -544,7 +544,8 @@ nl_convert_rinf_t::tokenizer::tokenizer(nl_convert_rinf_t &convert, plib::putf8_
|
||||
{
|
||||
set_identifier_chars(".abcdefghijklmnopqrstuvwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_-");
|
||||
set_number_chars("0123456789", "0123456789eE-."); //FIXME: processing of numbers
|
||||
set_whitespace(pstring("").cat(' ').cat(9).cat(10).cat(13));
|
||||
//set_whitespace(pstring("").cat(' ').cat(9).cat(10).cat(13));
|
||||
set_whitespace(pstring("") + ' ' + (char)9 + (char)10 + (char)13);
|
||||
/* FIXME: gnetlist doesn't print comments */
|
||||
set_comment("","","//"); // FIXME:needs to be confirmed
|
||||
set_string_char('"');
|
||||
|
Loading…
Reference in New Issue
Block a user