Merge branch 'master' of https://github.com/rheit/zdoom into zscript

This commit is contained in:
Christoph Oelckers 2016-12-04 10:27:35 +01:00
commit 71e8f09126
3 changed files with 49 additions and 47 deletions

View file

@ -1144,7 +1144,7 @@ CCMD(currentpos)
}
else
{
Printf("You are not in game!");
Printf("You are not in game!\n");
}
}

View file

@ -863,66 +863,34 @@ void FString::Insert (size_t index, const char *instr, size_t instrlen)
void FString::ReplaceChars (char oldchar, char newchar)
{
size_t i, j;
if (oldchar == '\0')
return;
LockBuffer();
for (i = 0, j = Len(); i < j; ++i)
{
if (Chars[i] == oldchar)
{
Chars[i] = newchar;
}
}
UnlockBuffer();
ReplaceChars([&oldchar](char c){ return c == oldchar; }, newchar);
}
void FString::ReplaceChars (const char *oldcharset, char newchar)
{
size_t i, j;
if (oldcharset == NULL || oldcharset[0] == '\0')
return;
LockBuffer();
for (i = 0, j = Len(); i < j; ++i)
{
if (strchr (oldcharset, Chars[i]) != NULL)
{
Chars[i] = newchar;
}
}
UnlockBuffer();
ReplaceChars([&oldcharset](char c){ return strchr(oldcharset, c) != NULL; }, newchar);
}
void FString::StripChars (char killchar)
{
size_t read, write, mylen;
if (killchar == '\0')
return;
LockBuffer();
for (read = write = 0, mylen = Len(); read < mylen; ++read)
{
if (Chars[read] != killchar)
{
Chars[write++] = Chars[read];
}
}
Chars[write] = '\0';
ReallocBuffer (write);
UnlockBuffer();
StripChars([&killchar](char c){ return c == killchar; });
}
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();
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();
StripChars([&killcharset](char c){ return strchr(killcharset, c) != NULL; });
}
void FString::MergeChars (char merger)

View file

@ -236,11 +236,45 @@ public:
void Insert (size_t index, const char *instr);
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 (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 (const char *killchars);
void StripChars (const char *killcharset);
void MergeChars (char merger);
void MergeChars (char merger, char newchar);