summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/netlist
diff options
context:
space:
mode:
author couriersud <couriersud@arcor.de>2015-04-19 00:02:31 +0200
committer couriersud <couriersud@arcor.de>2015-04-19 00:02:31 +0200
commit5905f4d907858a39631f70c16539d17e28cad770 (patch)
treeae40c1fe11bfdf464f26d47a81ad74481c0ee8ea /src/emu/netlist
parentf56db1ff3fc73037fc900bfee9cebe80cc63afeb (diff)
Added rtrim, ltrim and trim to pstring. (nw)
Diffstat (limited to 'src/emu/netlist')
-rw-r--r--src/emu/netlist/pstring.c47
-rw-r--r--src/emu/netlist/pstring.h9
2 files changed, 56 insertions, 0 deletions
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