Commit 1f9dabc1 authored by esprehn's avatar esprehn Committed by Commit bot

Move String::truncate to StringImpl.

String should be a thin wrapper over StringImpl and other functions.

Review-Url: https://codereview.chromium.org/2337683002
Cr-Commit-Position: refs/heads/master@{#419095}
parent c1eac5fc
......@@ -897,6 +897,15 @@ PassRefPtr<StringImpl> StringImpl::foldCase()
return newImpl.release();
}
PassRefPtr<StringImpl> StringImpl::truncate(unsigned length)
{
if (length >= m_length)
return this;
if (is8Bit())
return create(characters8(), length);
return create(characters16(), length);
}
template <class UCharPredicate>
inline PassRefPtr<StringImpl> StringImpl::stripMatchedCharacters(UCharPredicate predicate)
{
......
......@@ -338,6 +338,8 @@ public:
// FIXME: Do we need fill(char) or can we just do the right thing if UChar is ASCII?
PassRefPtr<StringImpl> foldCase();
PassRefPtr<StringImpl> truncate(unsigned length);
PassRefPtr<StringImpl> stripWhiteSpace();
PassRefPtr<StringImpl> stripWhiteSpace(IsWhiteSpaceFunctionPtr);
PassRefPtr<StringImpl> simplifyWhiteSpace(StripBehavior = StripExtraWhiteSpace);
......
......@@ -231,21 +231,10 @@ void String::ensure16Bit()
m_impl = StringImpl::empty16Bit();
}
void String::truncate(unsigned position)
void String::truncate(unsigned length)
{
if (position >= length())
return;
if (m_impl->is8Bit()) {
LChar* data;
RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(position, data);
memcpy(data, m_impl->characters8(), position * sizeof(LChar));
m_impl = newImpl.release();
} else {
UChar* data;
RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(position, data);
memcpy(data, m_impl->characters16(), position * sizeof(UChar));
m_impl = newImpl.release();
}
if (m_impl)
m_impl = m_impl->truncate(length);
}
void String::remove(unsigned start, unsigned lengthToRemove)
......
......@@ -246,7 +246,7 @@ public:
void ensure16Bit();
void truncate(unsigned len);
void truncate(unsigned length);
void remove(unsigned start, unsigned length = 1);
String substring(unsigned pos, unsigned len = UINT_MAX) const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment