mirror of
https://github.com/holub/mame
synced 2025-04-22 16:31:49 +03:00
Added rtrim, ltrim and trim to pstring. (nw)
This commit is contained in:
parent
f56db1ff3f
commit
5905f4d907
@ -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
|
||||
//-------------------------------------------------
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user