| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008, 2010 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #define StringBuffer_h | 30 #define StringBuffer_h |
| 31 | 31 |
| 32 #include "wtf/Assertions.h" | 32 #include "wtf/Assertions.h" |
| 33 #include "wtf/text/StringImpl.h" | 33 #include "wtf/text/StringImpl.h" |
| 34 #include "wtf/text/Unicode.h" | 34 #include "wtf/text/Unicode.h" |
| 35 | 35 |
| 36 namespace WTF { | 36 namespace WTF { |
| 37 | 37 |
| 38 template <typename CharType> | 38 template <typename CharType> |
| 39 class StringBuffer { | 39 class StringBuffer { |
| 40 WTF_MAKE_NONCOPYABLE(StringBuffer); | 40 WTF_MAKE_NONCOPYABLE(StringBuffer); |
| 41 public: | |
| 42 StringBuffer() { } | |
| 43 | 41 |
| 44 explicit StringBuffer(unsigned length) | 42 public: |
| 45 { | 43 StringBuffer() {} |
| 46 CharType* characters; | |
| 47 m_data = StringImpl::createUninitialized(length, characters); | |
| 48 } | |
| 49 | 44 |
| 50 ~StringBuffer() | 45 explicit StringBuffer(unsigned length) { |
| 51 { | 46 CharType* characters; |
| 52 } | 47 m_data = StringImpl::createUninitialized(length, characters); |
| 48 } |
| 53 | 49 |
| 54 void shrink(unsigned newLength); | 50 ~StringBuffer() { |
| 51 } |
| 55 | 52 |
| 56 unsigned length() const { return m_data ? m_data->length() : 0; } | 53 void shrink(unsigned newLength); |
| 57 CharType* characters() { return length() ? const_cast<CharType*>(m_data->get
Characters<CharType>()) : 0; } | |
| 58 | 54 |
| 59 CharType& operator[](unsigned i) { ASSERT_WITH_SECURITY_IMPLICATION(i < leng
th()); return characters()[i]; } | 55 unsigned length() const { return m_data ? m_data->length() : 0; } |
| 56 CharType* characters() { return length() ? const_cast<CharType*>(m_data->getCh
aracters<CharType>()) : 0; } |
| 60 | 57 |
| 61 PassRefPtr<StringImpl> release() { return m_data.release(); } | 58 CharType& operator[](unsigned i) { |
| 59 ASSERT_WITH_SECURITY_IMPLICATION(i < length()); |
| 60 return characters()[i]; |
| 61 } |
| 62 | 62 |
| 63 private: | 63 PassRefPtr<StringImpl> release() { return m_data.release(); } |
| 64 RefPtr<StringImpl> m_data; | 64 |
| 65 private: |
| 66 RefPtr<StringImpl> m_data; |
| 65 }; | 67 }; |
| 66 | 68 |
| 67 template <typename CharType> | 69 template <typename CharType> |
| 68 void StringBuffer<CharType>::shrink(unsigned newLength) | 70 void StringBuffer<CharType>::shrink(unsigned newLength) { |
| 69 { | 71 ASSERT(m_data); |
| 70 ASSERT(m_data); | 72 if (m_data->length() == newLength) |
| 71 if (m_data->length() == newLength) | 73 return; |
| 72 return; | 74 m_data = m_data->substring(0, newLength); |
| 73 m_data = m_data->substring(0, newLength); | |
| 74 } | 75 } |
| 75 | 76 |
| 76 } // namespace WTF | 77 } // namespace WTF |
| 77 | 78 |
| 78 using WTF::StringBuffer; | 79 using WTF::StringBuffer; |
| 79 | 80 |
| 80 #endif // StringBuffer_h | 81 #endif // StringBuffer_h |
| OLD | NEW |