Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: third_party/WebKit/Source/wtf/text/StringBuffer.h

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 20 matching lines...) Expand all
31 31
32 #include "wtf/Allocator.h" 32 #include "wtf/Allocator.h"
33 #include "wtf/Assertions.h" 33 #include "wtf/Assertions.h"
34 #include "wtf/text/StringImpl.h" 34 #include "wtf/text/StringImpl.h"
35 #include "wtf/text/Unicode.h" 35 #include "wtf/text/Unicode.h"
36 36
37 namespace WTF { 37 namespace WTF {
38 38
39 template <typename CharType> 39 template <typename CharType>
40 class StringBuffer { 40 class StringBuffer {
41 DISALLOW_NEW(); 41 DISALLOW_NEW();
42 WTF_MAKE_NONCOPYABLE(StringBuffer); 42 WTF_MAKE_NONCOPYABLE(StringBuffer);
43 public:
44 StringBuffer() { }
45 43
46 explicit StringBuffer(unsigned length) 44 public:
47 { 45 StringBuffer() {}
48 CharType* characters;
49 m_data = StringImpl::createUninitialized(length, characters);
50 }
51 46
52 ~StringBuffer() 47 explicit StringBuffer(unsigned length) {
53 { 48 CharType* characters;
54 } 49 m_data = StringImpl::createUninitialized(length, characters);
50 }
55 51
56 void shrink(unsigned newLength); 52 ~StringBuffer() {}
57 53
58 unsigned length() const { return m_data ? m_data->length() : 0; } 54 void shrink(unsigned newLength);
59 CharType* characters() { return length() ? const_cast<CharType*>(m_data->get Characters<CharType>()) : 0; }
60 55
61 CharType& operator[](unsigned i) { ASSERT_WITH_SECURITY_IMPLICATION(i < leng th()); return characters()[i]; } 56 unsigned length() const { return m_data ? m_data->length() : 0; }
57 CharType* characters() {
58 return length() ? const_cast<CharType*>(m_data->getCharacters<CharType>())
59 : 0;
60 }
62 61
63 PassRefPtr<StringImpl> release() { return m_data.release(); } 62 CharType& operator[](unsigned i) {
63 ASSERT_WITH_SECURITY_IMPLICATION(i < length());
64 return characters()[i];
65 }
64 66
65 private: 67 PassRefPtr<StringImpl> release() { return m_data.release(); }
66 RefPtr<StringImpl> m_data; 68
69 private:
70 RefPtr<StringImpl> m_data;
67 }; 71 };
68 72
69 template <typename CharType> 73 template <typename CharType>
70 void StringBuffer<CharType>::shrink(unsigned newLength) 74 void StringBuffer<CharType>::shrink(unsigned newLength) {
71 { 75 ASSERT(m_data);
72 ASSERT(m_data); 76 if (m_data->length() == newLength)
73 if (m_data->length() == newLength) 77 return;
74 return; 78 m_data = m_data->substring(0, newLength);
75 m_data = m_data->substring(0, newLength);
76 } 79 }
77 80
78 } // namespace WTF 81 } // namespace WTF
79 82
80 using WTF::StringBuffer; 83 using WTF::StringBuffer;
81 84
82 #endif // StringBuffer_h 85 #endif // StringBuffer_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698