Browse Source

Add String::remove(char) method

Signed-off-by: falkTX <falktx@falktx.com>
pull/272/head
falkTX 4 years ago
parent
commit
fe06ccecf5
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
1 changed files with 23 additions and 0 deletions
  1. +23
    -0
      distrho/extra/String.hpp

+ 23
- 0
distrho/extra/String.hpp View File

@@ -527,6 +527,29 @@ public:
return *this;
}

/*
* Remove all occurrences of character 'c', shifting and truncating the string as necessary.
*/
String& remove(const char c) noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(c != '\0', *this);

if (fBufferLen == 0)
return *this;

for (std::size_t i=0; i < fBufferLen; ++i)
{
if (fBuffer[i] == c)
{
--fBufferLen;
std::memmove(fBuffer+i, fBuffer+i+1, fBufferLen-i);
}
}

fBuffer[fBufferLen] = '\0';
return *this;
}

/*
* Truncate the string to size 'n'.
*/


Loading…
Cancel
Save