NzString::Trim(med) can now take a limit flag
Fixed NzString::Simplified removing non-separator character with HandleUtf8 flag
This commit is contained in:
parent
96ea5fdaa7
commit
f39e2f7d36
|
|
@ -25,9 +25,11 @@ class NAZARA_API NzString : public NzHashable
|
||||||
public:
|
public:
|
||||||
enum Flags
|
enum Flags
|
||||||
{
|
{
|
||||||
None = 0x00, // Mode par défaut
|
None = 0x00, // Mode par défaut
|
||||||
CaseInsensitive = 0x01, // Insensible à la casse
|
CaseInsensitive = 0x01, // Insensible à la casse
|
||||||
HandleUtf8 = 0x02 // Traite les octets comme une suite de caractères UTF-8
|
HandleUtf8 = 0x02, // Traite les octets comme une suite de caractères UTF-8
|
||||||
|
TrimOnlyLeft = 0x04, // Trim(med), ne coupe que la partie gauche de la chaîne
|
||||||
|
TrimOnlyRight = 0x08 // Trim(med), ne coupe que la partie droite de la chaîne
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SharedString;
|
struct SharedString;
|
||||||
|
|
|
||||||
|
|
@ -3317,7 +3317,7 @@ NzString NzString::Simplified(nzUInt32 flags) const
|
||||||
utf8::unchecked::iterator<const char*> it(ptr);
|
utf8::unchecked::iterator<const char*> it(ptr);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (NzUnicode::GetCategory(*it))
|
if (NzUnicode::GetCategory(*it) & NzUnicode::Category_Separator)
|
||||||
{
|
{
|
||||||
if (inword)
|
if (inword)
|
||||||
{
|
{
|
||||||
|
|
@ -3941,39 +3941,59 @@ NzString NzString::Trimmed(nzUInt32 flags) const
|
||||||
if (m_sharedString->size == 0)
|
if (m_sharedString->size == 0)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
unsigned int startPos = 0;
|
unsigned int startPos;
|
||||||
unsigned int endPos = m_sharedString->size-1;
|
unsigned int endPos;
|
||||||
if (flags & HandleUtf8)
|
if (flags & HandleUtf8)
|
||||||
{
|
{
|
||||||
utf8::unchecked::iterator<const char*> it(m_sharedString->string);
|
if ((flags & TrimOnlyRight) == 0)
|
||||||
do
|
|
||||||
{
|
{
|
||||||
if (NzUnicode::GetCategory(*it) & NzUnicode::Category_Separator)
|
utf8::unchecked::iterator<const char*> it(m_sharedString->string);
|
||||||
break;
|
do
|
||||||
}
|
{
|
||||||
while (*++it);
|
if (NzUnicode::GetCategory(*it) & NzUnicode::Category_Separator)
|
||||||
startPos = it.base() - m_sharedString->string;
|
break;
|
||||||
|
}
|
||||||
|
while (*++it);
|
||||||
|
|
||||||
utf8::unchecked::iterator<const char*> itR(&m_sharedString->string[m_sharedString->size]);
|
startPos = it.base() - m_sharedString->string;
|
||||||
while ((itR--).base() != m_sharedString->string)
|
|
||||||
{
|
|
||||||
if (NzUnicode::GetCategory(*itR) & NzUnicode::Category_Separator)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
endPos = itR.base() - m_sharedString->string;
|
else
|
||||||
|
startPos = 0;
|
||||||
|
|
||||||
|
if ((flags & TrimOnlyLeft) == 0)
|
||||||
|
{
|
||||||
|
utf8::unchecked::iterator<const char*> it(&m_sharedString->string[m_sharedString->size]);
|
||||||
|
while ((it--).base() != m_sharedString->string)
|
||||||
|
{
|
||||||
|
if (NzUnicode::GetCategory(*it) & NzUnicode::Category_Separator)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
endPos = it.base() - m_sharedString->string;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
endPos = m_sharedString->size-1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (; startPos < m_sharedString->size; ++startPos)
|
startPos = 0;
|
||||||
|
if ((flags & TrimOnlyRight) == 0)
|
||||||
{
|
{
|
||||||
if (!std::isspace(m_sharedString->string[startPos]))
|
for (; startPos < m_sharedString->size; ++startPos)
|
||||||
break;
|
{
|
||||||
|
if (!std::isspace(m_sharedString->string[startPos]))
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; endPos > 0; --endPos)
|
endPos = m_sharedString->size-1;
|
||||||
|
if ((flags & TrimOnlyLeft) == 0)
|
||||||
{
|
{
|
||||||
if (!std::isspace(m_sharedString->string[endPos]))
|
for (; endPos > 0; --endPos)
|
||||||
break;
|
{
|
||||||
|
if (!std::isspace(m_sharedString->string[endPos]))
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3990,30 +4010,42 @@ NzString NzString::Trimmed(char character, nzUInt32 flags) const
|
||||||
if (flags & CaseInsensitive)
|
if (flags & CaseInsensitive)
|
||||||
{
|
{
|
||||||
char ch = nzToLower(character);
|
char ch = nzToLower(character);
|
||||||
for (; startPos < m_sharedString->size; ++startPos)
|
if ((flags & TrimOnlyRight) == 0)
|
||||||
{
|
{
|
||||||
if (nzToLower(m_sharedString->string[startPos]) != ch)
|
for (; startPos < m_sharedString->size; ++startPos)
|
||||||
break;
|
{
|
||||||
|
if (nzToLower(m_sharedString->string[startPos]) != ch)
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; endPos > 0; --endPos)
|
if ((flags & TrimOnlyLeft) == 0)
|
||||||
{
|
{
|
||||||
if (nzToLower(m_sharedString->string[startPos]) != ch)
|
for (; endPos > 0; --endPos)
|
||||||
break;
|
{
|
||||||
|
if (nzToLower(m_sharedString->string[startPos]) != ch)
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (; startPos < m_sharedString->size; ++startPos)
|
if ((flags & TrimOnlyRight) == 0)
|
||||||
{
|
{
|
||||||
if (m_sharedString->string[startPos] != character)
|
for (; startPos < m_sharedString->size; ++startPos)
|
||||||
break;
|
{
|
||||||
|
if (m_sharedString->string[startPos] != character)
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; endPos > 0; --endPos)
|
if ((flags & TrimOnlyLeft) == 0)
|
||||||
{
|
{
|
||||||
if (m_sharedString->string[startPos] != character)
|
for (; endPos > 0; --endPos)
|
||||||
break;
|
{
|
||||||
|
if (m_sharedString->string[startPos] != character)
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue