Commit 9623e8d6 authored by bdakin's avatar bdakin

Reviewed Darin.

        No test cases needed.

        Implemented a version of StringImpl::append that takes a UChar* and 
        a length.

        * platform/StringImpl.cpp:
        (WebCore::StringImpl::append):
        (WebCore::StringImpl::insert): Call new append instead of making a 
        new StringImpl.
        * platform/StringImpl.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@16759 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 231a03c1
2006-10-03 Beth Dakin <bdakin@apple.com>
Reviewed Darin.
No test cases needed.
Implemented a version of StringImpl::append that takes a UChar* and
a length.
* platform/StringImpl.cpp:
(WebCore::StringImpl::append):
(WebCore::StringImpl::insert): Call new append instead of making a
new StringImpl.
* platform/StringImpl.h:
2006-10-03 MorganL <morganl.webkit@yahoo.com>
Reviewed by Darin.
......@@ -147,15 +147,14 @@ const UChar* StringImpl::charactersWithNullTermination()
return m_data;
}
void StringImpl::append(const StringImpl* str)
void StringImpl::append(const UChar* str, unsigned length)
{
assert(!m_inTable);
if(str && str->m_length != 0)
{
int newlen = m_length+str->m_length;
ASSERT(!m_inTable);
if (str && length != 0) {
int newlen = m_length + length;
UChar* c = newUCharVector(newlen);
memcpy(c, m_data, m_length * sizeof(UChar));
memcpy(c + m_length, str->m_data, str->m_length * sizeof(UChar));
memcpy(c + m_length, str, length * sizeof(UChar));
deleteUCharVector(m_data);
m_data = c;
m_length = newlen;
......@@ -163,6 +162,12 @@ void StringImpl::append(const StringImpl* str)
}
}
void StringImpl::append(const StringImpl* str)
{
if (str)
append(str->m_data, str->m_length);
}
void StringImpl::append(char c)
{
append(UChar(c));
......@@ -180,34 +185,14 @@ void StringImpl::append(UChar c)
m_hasTerminatingNullCharacter = false;
}
void StringImpl::insert(const StringImpl* str, unsigned pos)
{
assert(!m_inTable);
if (pos >= m_length) {
append(str);
return;
}
if (str && str->m_length != 0) {
int newlen = m_length + str->m_length;
UChar* c = newUCharVector(newlen);
memcpy(c, m_data, pos * sizeof(UChar));
memcpy(c + pos, str->m_data, str->m_length * sizeof(UChar));
memcpy(c + pos + str->m_length, m_data + pos, (m_length - pos) * sizeof(UChar));
deleteUCharVector(m_data);
m_data = c;
m_length = newlen;
m_hasTerminatingNullCharacter = false;
}
}
void StringImpl::insert(const UChar* str, unsigned length, unsigned pos)
{
assert(!m_inTable);
if (pos >= m_length) {
RefPtr<StringImpl> s = new StringImpl(str, length);
append(s.get());
append(str, length);
return;
}
if (str && length != 0) {
size_t newlen = m_length + length;
UChar* c = newUCharVector(newlen);
......@@ -221,6 +206,12 @@ void StringImpl::insert(const UChar* str, unsigned length, unsigned pos)
}
}
void StringImpl::insert(const StringImpl* str, unsigned pos)
{
if (str)
insert(str->m_data, str->m_length, pos);
}
void StringImpl::truncate(int len)
{
assert(!m_inTable);
......
......@@ -79,11 +79,14 @@ public:
static unsigned computeHash(const UChar*, unsigned len);
static unsigned computeHash(const char*);
void append(const UChar*, unsigned length);
void append(const StringImpl*);
void append(char);
void append(UChar);
void append(char);
void insert(const UChar*, unsigned length, unsigned pos);
void insert(const StringImpl*, unsigned pos);
void insert(const UChar* str, unsigned length, unsigned pos);
void truncate(int len);
void remove(unsigned pos, int len = 1);
......
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