Add ReplaceChars with a char16_t array. Bug 979556, r=bsmedberg

This commit is contained in:
Simon Montagu 2014-03-05 21:04:36 +02:00
parent 108ae026f2
commit a0be4ca960
2 changed files with 24 additions and 0 deletions

View File

@ -344,6 +344,9 @@ class nsTString_CharT : public nsTSubstring_CharT
void ReplaceChar( char_type aOldChar, char_type aNewChar );
void ReplaceChar( const char* aSet, char_type aNewChar );
#ifdef CharT_is_PRUnichar
void ReplaceChar( const char16_t* aSet, char16_t aNewChar );
#endif
void ReplaceSubstring( const self_type& aTarget, const self_type& aNewValue);
void ReplaceSubstring( const char_type* aTarget, const char_type* aNewValue);

View File

@ -915,6 +915,27 @@ nsString::FindCharInSet( const char16_t* aSet, int32_t aOffset ) const
return result;
}
void
nsString::ReplaceChar( const char16_t* aSet, char16_t aNewChar )
{
if (!EnsureMutable()) // XXX do this lazily?
NS_ABORT_OOM(mLength);
char16_t* data = mData;
uint32_t lenRemaining = mLength;
while (lenRemaining)
{
int32_t i = ::FindCharInSet(data, lenRemaining, aSet);
if (i == kNotFound)
break;
data[i++] = aNewChar;
data += i;
lenRemaining -= i;
}
}
/**
* nsTString::Compare,CompareWithConversion,etc.