diff --git a/src/emu/netlist/pstring.c b/src/emu/netlist/pstring.c index e60f950be1d..3f19cc16a89 100644 --- a/src/emu/netlist/pstring.c +++ b/src/emu/netlist/pstring.c @@ -88,6 +88,53 @@ pstring pstring::ucase() const return ret; } +int pstring::find_first_not_of(const pstring no) const +{ + for (int i=0; i < len(); i++) + { + bool f = true; + for (int j=0; j < no.len(); j++) + if (m_ptr->m_str[i] == no.m_ptr->m_str[j]) + f = false; + if (f) + return i; + } + return -1; +} + +int pstring::find_last_not_of(const pstring no) const +{ + for (int i=len() - 1; i >= 0; i--) + { + bool f = true; + for (int j=0; j < no.len(); j++) + if (m_ptr->m_str[i] == no.m_ptr->m_str[j]) + f = false; + if (f) + return i; + } + return -1; +} + + +pstring pstring::ltrim(const pstring ws) const +{ + int f = find_first_not_of(ws); + if (f>=0) + return substr(f); + else + return ""; +} + +pstring pstring::rtrim(const pstring ws) const +{ + int f = find_last_not_of(ws); + if (f>=0) + return left(f+1); + else + return ""; +} + //------------------------------------------------- // pcmpi - compare a character array to an nstring //------------------------------------------------- diff --git a/src/emu/netlist/pstring.h b/src/emu/netlist/pstring.h index b2b5cd0ae91..6ed539e0c13 100644 --- a/src/emu/netlist/pstring.h +++ b/src/emu/netlist/pstring.h @@ -155,6 +155,15 @@ public: inline pstring left(unsigned int count) const { return substr(0, count); } inline pstring right(unsigned int count) const { return substr(len() - count, count); } + int find_first_not_of(const pstring no) const; + int find_last_not_of(const pstring no) const; + + pstring ltrim(const pstring ws = " \t\n\r") const; + pstring rtrim(const pstring ws = " \t\n\r") const; + + + inline pstring trim(const pstring ws = " \t\n\r") const { return this->ltrim(ws).rtrim(ws); } + pstring ucase() const; // conversions