mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2024-11-27 12:15:19 +01:00
Correct trim() in XString.
This commit is contained in:
parent
11817925ae
commit
de45197556
@ -935,13 +935,20 @@ public:
|
||||
|
||||
void trim()
|
||||
{
|
||||
size_t lengthInNativeBytes = __String<T, ThisXStringClass>::sizeInNativeChars();
|
||||
if ( lengthInNativeBytes == 0 ) return;
|
||||
T* start = 0;
|
||||
size_t count = 0;
|
||||
T* s = m_data;
|
||||
while ( *s && unsigned_type(T)(*s) <= 32 ) s++;
|
||||
if ( !*s ) {
|
||||
m_data[0] = 0;
|
||||
return;
|
||||
}
|
||||
start = s;
|
||||
while ( *s && unsigned_type(T)(*s) > 32 ) s++;
|
||||
count = uintptr_t(s - start);
|
||||
s = m_data + lengthInNativeBytes - 1;
|
||||
while ( *s && unsigned_type(T)(*s) <= 32 ) s--;
|
||||
count = uintptr_t(s - start) + 1;
|
||||
CheckSize(count); // We have to CheckSize in case this string point to a litteral.
|
||||
memmove(m_data, start, count*sizeof(T));
|
||||
m_data[count] = 0;
|
||||
|
@ -1577,9 +1577,20 @@ int XString_tests()
|
||||
XStringW xsw2;
|
||||
xsw2.takeValueFrom(xsw, 1);
|
||||
|
||||
XString8 xs8 = " toTRIM "_XS8;
|
||||
// xs8.trim();
|
||||
xs8.lowerAscii();
|
||||
{
|
||||
XString8 xs8 = " to TRIM "_XS8;
|
||||
xs8.trim();
|
||||
if ( xs8 != "to TRIM"_XS8 ) {
|
||||
nbTestFailed += 1;
|
||||
}
|
||||
}
|
||||
{
|
||||
XString8 xs8 = "Apple Inc."_XS8;
|
||||
xs8.trim();
|
||||
if ( xs8 != "Apple Inc."_XS8 ) {
|
||||
nbTestFailed += 1;
|
||||
}
|
||||
}
|
||||
|
||||
XString8 xsReplace = "babcbdeb"_XS8;
|
||||
xsReplace.replaceAll(U'b', U'𐅃');
|
||||
|
Loading…
Reference in New Issue
Block a user