OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 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 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 static bool isValidPropertyName(const String& name) | 100 static bool isValidPropertyName(const String& name) |
101 { | 101 { |
102 unsigned length = name.length(); | 102 unsigned length = name.length(); |
103 for (unsigned i = 0; i < length; ++i) { | 103 for (unsigned i = 0; i < length; ++i) { |
104 if (name[i] == '-' && (i + 1 < length) && isASCIILower(name[i + 1])) | 104 if (name[i] == '-' && (i + 1 < length) && isASCIILower(name[i + 1])) |
105 return false; | 105 return false; |
106 } | 106 } |
107 return true; | 107 return true; |
108 } | 108 } |
109 | 109 |
110 static String convertPropertyNameToAttributeName(const String& name) | 110 // This returns an AtomicString because attribute names are always stored |
| 111 // as AtomicString types in Element (see setAttribute()). |
| 112 static AtomicString convertPropertyNameToAttributeName(const String& name) |
111 { | 113 { |
112 StringBuilder builder; | 114 StringBuilder builder; |
113 builder.append("data-"); | 115 builder.append("data-"); |
114 | 116 |
115 unsigned length = name.length(); | 117 unsigned length = name.length(); |
116 for (unsigned i = 0; i < length; ++i) { | 118 for (unsigned i = 0; i < length; ++i) { |
117 UChar character = name[i]; | 119 UChar character = name[i]; |
118 if (isASCIIUpper(character)) { | 120 if (isASCIIUpper(character)) { |
119 builder.append('-'); | 121 builder.append('-'); |
120 builder.append(toASCIILower(character)); | 122 builder.append(toASCIILower(character)); |
121 } else | 123 } else |
122 builder.append(character); | 124 builder.append(character); |
123 } | 125 } |
124 | 126 |
125 return builder.toString(); | 127 return builder.toAtomicString(); |
126 } | 128 } |
127 | 129 |
128 void DatasetDOMStringMap::ref() | 130 void DatasetDOMStringMap::ref() |
129 { | 131 { |
130 m_element->ref(); | 132 m_element->ref(); |
131 } | 133 } |
132 | 134 |
133 void DatasetDOMStringMap::deref() | 135 void DatasetDOMStringMap::deref() |
134 { | 136 { |
135 m_element->deref(); | 137 m_element->deref(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 return false; | 180 return false; |
179 } | 181 } |
180 | 182 |
181 void DatasetDOMStringMap::setItem(const String& name, const String& value, Excep
tionState& exceptionState) | 183 void DatasetDOMStringMap::setItem(const String& name, const String& value, Excep
tionState& exceptionState) |
182 { | 184 { |
183 if (!isValidPropertyName(name)) { | 185 if (!isValidPropertyName(name)) { |
184 exceptionState.throwDOMException(SyntaxError, ExceptionMessages::failedT
oSet(name, "DOMStringMap", "'" + name + "' is not a valid property name.")); | 186 exceptionState.throwDOMException(SyntaxError, ExceptionMessages::failedT
oSet(name, "DOMStringMap", "'" + name + "' is not a valid property name.")); |
185 return; | 187 return; |
186 } | 188 } |
187 | 189 |
188 m_element->setAttribute(convertPropertyNameToAttributeName(name), value, exc
eptionState); | 190 m_element->setAttribute(convertPropertyNameToAttributeName(name), AtomicStri
ng(value), exceptionState); |
189 } | 191 } |
190 | 192 |
191 bool DatasetDOMStringMap::deleteItem(const String& name) | 193 bool DatasetDOMStringMap::deleteItem(const String& name) |
192 { | 194 { |
193 if (isValidPropertyName(name)) { | 195 if (isValidPropertyName(name)) { |
194 String attributeName = convertPropertyNameToAttributeName(name); | 196 AtomicString attributeName = convertPropertyNameToAttributeName(name); |
195 if (m_element->hasAttribute(attributeName)) { | 197 if (m_element->hasAttribute(attributeName)) { |
196 m_element->removeAttribute(attributeName); | 198 m_element->removeAttribute(attributeName); |
197 return true; | 199 return true; |
198 } | 200 } |
199 } | 201 } |
200 return false; | 202 return false; |
201 } | 203 } |
202 | 204 |
203 } // namespace WebCore | 205 } // namespace WebCore |
OLD | NEW |