diff options
author | 2019-01-06 13:17:20 +0100 | |
---|---|---|
committer | 2019-01-06 13:17:20 +0100 | |
commit | 1415421fd707ad02e0cfddf20bf70bbd045a9203 (patch) | |
tree | a5df29611fa9a0e2670ab5f45b13b37aaf1c04d4 /src/lib/netlist/plib/pfunction.cpp | |
parent | c5b3f76360813e6a8caa139c3d1c743ce31d9560 (diff) |
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.
Diffstat (limited to 'src/lib/netlist/plib/pfunction.cpp')
-rw-r--r-- | src/lib/netlist/plib/pfunction.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/lib/netlist/plib/pfunction.cpp b/src/lib/netlist/plib/pfunction.cpp index 79f09cb4a46..e9e2de009c8 100644 --- a/src/lib/netlist/plib/pfunction.cpp +++ b/src/lib/netlist/plib/pfunction.cpp @@ -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; |