| OLD | NEW |
| 1 /* | 1 /* |
| 2 * (C) 1999 Lars Knoll (knoll@kde.org) | 2 * (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2012 Apple Inc. All rights
reserved. | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2012 Apple Inc. All rights
reserved. |
| 4 * Copyright (C) 2007-2009 Torch Mobile, Inc. | 4 * Copyright (C) 2007-2009 Torch Mobile, Inc. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 memcpy(data, m_impl->characters8(), position * sizeof(LChar)); | 241 memcpy(data, m_impl->characters8(), position * sizeof(LChar)); |
| 242 m_impl = newImpl.release(); | 242 m_impl = newImpl.release(); |
| 243 } else { | 243 } else { |
| 244 UChar* data; | 244 UChar* data; |
| 245 RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(position, d
ata); | 245 RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(position, d
ata); |
| 246 memcpy(data, m_impl->characters16(), position * sizeof(UChar)); | 246 memcpy(data, m_impl->characters16(), position * sizeof(UChar)); |
| 247 m_impl = newImpl.release(); | 247 m_impl = newImpl.release(); |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 | 250 |
| 251 template <typename CharacterType> | 251 void String::remove(unsigned start, unsigned lengthToRemove) |
| 252 inline void String::removeInternal(const CharacterType* characters, unsigned pos
ition, int lengthToRemove) | |
| 253 { | 252 { |
| 254 CharacterType* data; | 253 if (m_impl) |
| 255 RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(length() - leng
thToRemove, data); | 254 m_impl = m_impl->remove(start, lengthToRemove); |
| 256 memcpy(data, characters, position * sizeof(CharacterType)); | |
| 257 memcpy(data + position, characters + position + lengthToRemove, | |
| 258 (length() - lengthToRemove - position) * sizeof(CharacterType)); | |
| 259 | |
| 260 m_impl = newImpl.release(); | |
| 261 } | |
| 262 | |
| 263 void String::remove(unsigned position, int lengthToRemove) | |
| 264 { | |
| 265 if (lengthToRemove <= 0) | |
| 266 return; | |
| 267 if (position >= length()) | |
| 268 return; | |
| 269 if (static_cast<unsigned>(lengthToRemove) > length() - position) | |
| 270 lengthToRemove = length() - position; | |
| 271 | |
| 272 if (is8Bit()) { | |
| 273 removeInternal(characters8(), position, lengthToRemove); | |
| 274 | |
| 275 return; | |
| 276 } | |
| 277 | |
| 278 removeInternal(characters16(), position, lengthToRemove); | |
| 279 } | 255 } |
| 280 | 256 |
| 281 String String::substring(unsigned pos, unsigned len) const | 257 String String::substring(unsigned pos, unsigned len) const |
| 282 { | 258 { |
| 283 if (!m_impl) | 259 if (!m_impl) |
| 284 return String(); | 260 return String(); |
| 285 return m_impl->substring(pos, len); | 261 return m_impl->substring(pos, len); |
| 286 } | 262 } |
| 287 | 263 |
| 288 String String::lower() const | 264 String String::lower() const |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 buffer.append('\0'); | 912 buffer.append('\0'); |
| 937 return buffer; | 913 return buffer; |
| 938 } | 914 } |
| 939 | 915 |
| 940 Vector<char> asciiDebug(String& string) | 916 Vector<char> asciiDebug(String& string) |
| 941 { | 917 { |
| 942 return asciiDebug(string.impl()); | 918 return asciiDebug(string.impl()); |
| 943 } | 919 } |
| 944 | 920 |
| 945 #endif | 921 #endif |
| OLD | NEW |