mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-01-31 04:20:34 +00:00
- Added lambda feature to FString::(Strip|Replace)Chars.
Use it in the other (Strip|Replace)Chars methods to show how it would work.
This commit is contained in:
parent
30cbce051e
commit
c99a051a2a
2 changed files with 48 additions and 46 deletions
|
@ -863,66 +863,34 @@ void FString::Insert (size_t index, const char *instr, size_t instrlen)
|
||||||
|
|
||||||
void FString::ReplaceChars (char oldchar, char newchar)
|
void FString::ReplaceChars (char oldchar, char newchar)
|
||||||
{
|
{
|
||||||
size_t i, j;
|
if (oldchar == '\0')
|
||||||
|
return;
|
||||||
|
|
||||||
LockBuffer();
|
ReplaceChars([&oldchar](char c){ return c == oldchar; }, newchar);
|
||||||
for (i = 0, j = Len(); i < j; ++i)
|
|
||||||
{
|
|
||||||
if (Chars[i] == oldchar)
|
|
||||||
{
|
|
||||||
Chars[i] = newchar;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
UnlockBuffer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FString::ReplaceChars (const char *oldcharset, char newchar)
|
void FString::ReplaceChars (const char *oldcharset, char newchar)
|
||||||
{
|
{
|
||||||
size_t i, j;
|
if (oldcharset == NULL || oldcharset[0] == '\0')
|
||||||
|
return;
|
||||||
|
|
||||||
LockBuffer();
|
ReplaceChars([&oldcharset](char c){ return strchr(oldcharset, c) != NULL; }, newchar);
|
||||||
for (i = 0, j = Len(); i < j; ++i)
|
|
||||||
{
|
|
||||||
if (strchr (oldcharset, Chars[i]) != NULL)
|
|
||||||
{
|
|
||||||
Chars[i] = newchar;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
UnlockBuffer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FString::StripChars (char killchar)
|
void FString::StripChars (char killchar)
|
||||||
{
|
{
|
||||||
size_t read, write, mylen;
|
if (killchar == '\0')
|
||||||
|
return;
|
||||||
|
|
||||||
LockBuffer();
|
StripChars([&killchar](char c){ return c == killchar; });
|
||||||
for (read = write = 0, mylen = Len(); read < mylen; ++read)
|
|
||||||
{
|
|
||||||
if (Chars[read] != killchar)
|
|
||||||
{
|
|
||||||
Chars[write++] = Chars[read];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Chars[write] = '\0';
|
|
||||||
ReallocBuffer (write);
|
|
||||||
UnlockBuffer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FString::StripChars (const char *killchars)
|
void FString::StripChars (const char *killcharset)
|
||||||
{
|
{
|
||||||
size_t read, write, mylen;
|
if (killcharset == NULL || killcharset[0] == '\0')
|
||||||
|
return;
|
||||||
|
|
||||||
LockBuffer();
|
StripChars([&killcharset](char c){ return strchr(killcharset, c) != NULL; });
|
||||||
for (read = write = 0, mylen = Len(); read < mylen; ++read)
|
|
||||||
{
|
|
||||||
if (strchr (killchars, Chars[read]) == NULL)
|
|
||||||
{
|
|
||||||
Chars[write++] = Chars[read];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Chars[write] = '\0';
|
|
||||||
ReallocBuffer (write);
|
|
||||||
UnlockBuffer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FString::MergeChars (char merger)
|
void FString::MergeChars (char merger)
|
||||||
|
|
|
@ -236,11 +236,45 @@ public:
|
||||||
void Insert (size_t index, const char *instr);
|
void Insert (size_t index, const char *instr);
|
||||||
void Insert (size_t index, const char *instr, size_t instrlen);
|
void Insert (size_t index, const char *instr, size_t instrlen);
|
||||||
|
|
||||||
|
template<typename Func>
|
||||||
|
void ReplaceChars (Func IsOldChar, char newchar)
|
||||||
|
{
|
||||||
|
size_t i, j;
|
||||||
|
|
||||||
|
LockBuffer();
|
||||||
|
for (i = 0, j = Len(); i < j; ++i)
|
||||||
|
{
|
||||||
|
if (IsOldChar(Chars[i]))
|
||||||
|
{
|
||||||
|
Chars[i] = newchar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UnlockBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
void ReplaceChars (char oldchar, char newchar);
|
void ReplaceChars (char oldchar, char newchar);
|
||||||
void ReplaceChars (const char *oldcharset, char newchar);
|
void ReplaceChars (const char *oldcharset, char newchar);
|
||||||
|
|
||||||
|
template<typename Func>
|
||||||
|
void StripChars (Func IsKillChar)
|
||||||
|
{
|
||||||
|
size_t read, write, mylen;
|
||||||
|
|
||||||
|
LockBuffer();
|
||||||
|
for (read = write = 0, mylen = Len(); read < mylen; ++read)
|
||||||
|
{
|
||||||
|
if (!IsKillChar(Chars[read]))
|
||||||
|
{
|
||||||
|
Chars[write++] = Chars[read];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Chars[write] = '\0';
|
||||||
|
ReallocBuffer (write);
|
||||||
|
UnlockBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
void StripChars (char killchar);
|
void StripChars (char killchar);
|
||||||
void StripChars (const char *killchars);
|
void StripChars (const char *killcharset);
|
||||||
|
|
||||||
void MergeChars (char merger);
|
void MergeChars (char merger);
|
||||||
void MergeChars (char merger, char newchar);
|
void MergeChars (char merger, char newchar);
|
||||||
|
|
Loading…
Reference in a new issue