Changeset 63343 in webkit
- Timestamp:
- Jul 14, 2010 12:26:26 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/CMakeLists.txt
r63325 r63343 1292 1292 platform/text/Base64.cpp 1293 1293 platform/text/BidiContext.cpp 1294 platform/text/LineEnding.cpp 1294 1295 platform/text/Hyphenation.cpp 1295 1296 platform/text/RegularExpression.cpp -
trunk/WebCore/ChangeLog
r63342 r63343 1 2010-07-14 Kinuko Yasuda <kinuko@chromium.org> 2 3 Reviewed by Jian Li. 4 5 Separate line-ending conversion code from BlobItem 6 https://bugs.webkit.org/show_bug.cgi?id=40932 7 8 Add common line-ending normalization code under platform/text. 9 No new tests as it doesn't change any functionality. 10 11 * CMakeLists.txt: 12 * GNUmakefile.am: 13 * WebCore.gypi: 14 * WebCore.pro: 15 * WebCore.vcproj/WebCore.vcproj: 16 * WebCore.xcodeproj/project.pbxproj: 17 * html/BlobBuilder.cpp: 18 (WebCore::BlobBuilder::appendString): 19 * html/FormDataList.cpp: 20 (WebCore::FormDataList::appendString): 21 * platform/BlobItem.cpp: 22 * platform/BlobItem.h: 23 * platform/text/LineEnding.cpp: Added. 24 * platform/text/LineEnding.h: Added. 25 1 26 2010-07-14 Erik Arvidsson <arv@chromium.org> 2 27 -
trunk/WebCore/GNUmakefile.am
r63324 r63343 2092 2092 WebCore/platform/text/Hyphenation.cpp \ 2093 2093 WebCore/platform/text/Hyphenation.h \ 2094 WebCore/platform/text/LineEnding.cpp \ 2095 WebCore/platform/text/LineEnding.h \ 2094 2096 WebCore/platform/text/ParserUtilities.h \ 2095 2097 WebCore/platform/text/PlatformString.h \ -
trunk/WebCore/WebCore.gypi
r63280 r63343 2837 2837 'platform/text/Hyphenation.cpp', 2838 2838 'platform/text/Hyphenation.h', 2839 'platform/text/LineEnding.cpp', 2840 'platform/text/LineEnding.h', 2839 2841 'platform/text/ParserUtilities.h', 2840 2842 'platform/text/PlatformString.h', -
trunk/WebCore/WebCore.pro
r63278 r63343 898 898 platform/KURL.cpp \ 899 899 platform/Length.cpp \ 900 platform/text/LineEnding.cpp \ 900 901 platform/LinkHash.cpp \ 901 902 platform/Logging.cpp \ … … 1673 1674 platform/KURL.h \ 1674 1675 platform/Length.h \ 1676 platform/text/LineEnding.h \ 1675 1677 platform/LinkHash.h \ 1676 1678 platform/Logging.h \ -
trunk/WebCore/WebCore.vcproj/WebCore.vcproj
r63278 r63343 27145 27145 </File> 27146 27146 <File 27147 RelativePath="..\platform\text\LineEnding.cpp" 27148 > 27149 </File> 27150 <File 27151 RelativePath="..\platform\text\LineEnding.h" 27152 > 27153 </File> 27154 <File 27147 27155 RelativePath="..\platform\text\ParserUtilities.h" 27148 27156 > -
trunk/WebCore/WebCore.xcodeproj/project.pbxproj
r63278 r63343 2312 2312 8988E10E11A3508B00DB732E /* BlobItem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8988E10C11A3508B00DB732E /* BlobItem.cpp */; }; 2313 2313 8988E10F11A3508B00DB732E /* BlobItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 8988E10D11A3508B00DB732E /* BlobItem.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2314 89B5EAA111E8003D00F2367E /* LineEnding.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 89B5EA9F11E8003D00F2367E /* LineEnding.cpp */; }; 2315 89B5EAA211E8003D00F2367E /* LineEnding.h in Headers */ = {isa = PBXBuildFile; fileRef = 89B5EAA011E8003D00F2367E /* LineEnding.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2314 2316 89BED5EB11BE11CE00448492 /* BlobBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 89BED5E911BE11CE00448492 /* BlobBuilder.cpp */; }; 2315 2317 89BED5EC11BE11CE00448492 /* BlobBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 89BED5EA11BE11CE00448492 /* BlobBuilder.h */; }; … … 8024 8026 8988E10C11A3508B00DB732E /* BlobItem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BlobItem.cpp; sourceTree = "<group>"; }; 8025 8027 8988E10D11A3508B00DB732E /* BlobItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlobItem.h; sourceTree = "<group>"; }; 8028 89B5EA9F11E8003D00F2367E /* LineEnding.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LineEnding.cpp; sourceTree = "<group>"; }; 8029 89B5EAA011E8003D00F2367E /* LineEnding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LineEnding.h; sourceTree = "<group>"; }; 8026 8030 89BED5E911BE11CE00448492 /* BlobBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BlobBuilder.cpp; sourceTree = "<group>"; }; 8027 8031 89BED5EA11BE11CE00448492 /* BlobBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlobBuilder.h; sourceTree = "<group>"; }; … … 15508 15512 B2C3D9F50D006C1D00EF6F26 /* CharacterNames.h */, 15509 15513 375CD231119D43C800A2A859 /* Hyphenation.h */, 15514 89B5EA9F11E8003D00F2367E /* LineEnding.cpp */, 15515 89B5EAA011E8003D00F2367E /* LineEnding.h */, 15510 15516 BC76AC110DD7AD5C00415F34 /* ParserUtilities.h */, 15511 15517 B2C3D9FB0D006C1D00EF6F26 /* PlatformString.h */, … … 18913 18919 B22279650D00BF220071B782 /* LinearGradientAttributes.h in Headers */, 18914 18920 AB31C91E10AE1B8E000C7B92 /* LineClampValue.h in Headers */, 18921 89B5EAA211E8003D00F2367E /* LineEnding.h in Headers */, 18915 18922 A7AD2F880EC89D07008AB002 /* LinkHash.h in Headers */, 18916 18923 BCB16C2D0979C3BD00467741 /* loader.h in Headers */, … … 21414 21421 BCE65BEA0EACDF16007E4533 /* Length.cpp in Sources */, 21415 21422 A7AD2F870EC89D07008AB002 /* LinkHash.cpp in Sources */, 21423 89B5EAA111E8003D00F2367E /* LineEnding.cpp in Sources */, 21416 21424 BCB16C2C0979C3BD00467741 /* loader.cpp in Sources */, 21417 21425 656D37330ADBA5DE00A4554D /* LoaderNSURLExtras.mm in Sources */, -
trunk/WebCore/html/BlobBuilder.cpp
r61650 r63343 36 36 #include "Blob.h" 37 37 #include "ExceptionCode.h" 38 #include "LineEnding.h" 38 39 #include "TextEncoding.h" 39 40 40 41 namespace WebCore { 41 42 42 static bool getLineEndingTypeFromString(const AtomicString& typeString, LineEnding& endingType)43 static CString convertToCString(const String& text, const String& endingType, ExceptionCode& ec) 43 44 { 44 45 DEFINE_STATIC_LOCAL(AtomicString, transparent, ("transparent")); 45 46 DEFINE_STATIC_LOCAL(AtomicString, native, ("native")); 46 47 47 if (typeString.isEmpty() || typeString == transparent) {48 endingType = EndingTransparent; 49 return true;50 }51 if ( typeString == native) {52 endingType = EndingNative;53 return true; 54 }55 return false;48 ec = 0; 49 50 if (endingType.isEmpty() || endingType == transparent) 51 return UTF8Encoding().encode(text.characters(), text.length(), EntitiesForUnencodables); 52 if (endingType == native) 53 return normalizeLineEndingsToNative(UTF8Encoding().encode(text.characters(), text.length(), EntitiesForUnencodables)); 54 55 ec = SYNTAX_ERR; 56 return CString(); 56 57 } 57 58 58 bool BlobBuilder::append(const String& text, const String& type, ExceptionCode& ec)59 bool BlobBuilder::append(const String& text, const String& endingType, ExceptionCode& ec) 59 60 { 60 ec = 0; 61 LineEnding endingType; 62 if (!getLineEndingTypeFromString(type, endingType)) { 63 ec = SYNTAX_ERR; 61 CString cstr = convertToCString(text, endingType, ec); 62 if (ec) 64 63 return false; 65 } 66 m_items.append(StringBlobItem::create( text, endingType, UTF8Encoding()));64 65 m_items.append(StringBlobItem::create(cstr)); 67 66 return true; 68 67 } -
trunk/WebCore/html/FormDataList.cpp
r60799 r63343 22 22 #include "FormDataList.h" 23 23 24 #include "LineEnding.h" 25 24 26 namespace WebCore { 25 27 … … 31 33 void FormDataList::appendString(const String& s) 32 34 { 33 m_items.append(StringBlobItem::create(s, EndingCRLF, m_encoding)); 35 CString cstr = m_encoding.encode(s.characters(), s.length(), EntitiesForUnencodables); 36 m_items.append(StringBlobItem::create(normalizeLineEndingsToCRLF(cstr))); 34 37 } 35 38 -
trunk/WebCore/platform/BlobItem.cpp
r62155 r63343 106 106 // StringBlobItem -------------------------------------------------------------- 107 107 108 PassRefPtr<BlobItem> StringBlobItem::create(const String& text, LineEnding ending, TextEncoding encoding)109 {110 return adoptRef(static_cast<BlobItem*>(new StringBlobItem(text, ending, encoding)));111 }112 113 108 PassRefPtr<BlobItem> StringBlobItem::create(const CString& text) 114 109 { … … 116 111 } 117 112 118 StringBlobItem::StringBlobItem(const String& text, LineEnding ending, TextEncoding encoding)119 : m_data(StringBlobItem::convertToCString(text, ending, encoding))120 {121 }122 123 113 StringBlobItem::StringBlobItem(const CString& text) 124 114 : m_data(text) 125 115 { 126 }127 128 // Normalize all line-endings to CRLF.129 static CString convertToCRLF(const CString& from)130 {131 unsigned newLen = 0;132 const char* p = from.data();133 while (char c = *p++) {134 if (c == '\r') {135 // Safe to look ahead because of trailing '\0'.136 if (*p != '\n') {137 // Turn CR into CRLF.138 newLen += 2;139 }140 } else if (c == '\n') {141 // Turn LF into CRLF.142 newLen += 2;143 } else {144 // Leave other characters alone.145 newLen += 1;146 }147 }148 if (newLen == from.length())149 return from;150 151 // Make a copy of the string.152 p = from.data();153 char* q;154 CString result = CString::newUninitialized(newLen, q);155 while (char c = *p++) {156 if (c == '\r') {157 // Safe to look ahead because of trailing '\0'.158 if (*p != '\n') {159 // Turn CR into CRLF.160 *q++ = '\r';161 *q++ = '\n';162 }163 } else if (c == '\n') {164 // Turn LF into CRLF.165 *q++ = '\r';166 *q++ = '\n';167 } else {168 // Leave other characters alone.169 *q++ = c;170 }171 }172 return result;173 }174 175 // Normalize all line-endings to CR or LF.176 static CString convertToCROrLF(const CString& from, bool toCR)177 {178 unsigned newLen = 0;179 bool needFix = false;180 const char* p = from.data();181 char fromEndingChar = toCR ? '\n' : '\r';182 char toEndingChar = toCR ? '\r' : '\n';183 while (char c = *p++) {184 if (c == '\r' && *p == '\n') {185 // Turn CRLF into CR or LF.186 p++;187 needFix = true;188 } else if (c == fromEndingChar) {189 // Turn CR/LF into LF/CR.190 needFix = true;191 }192 newLen += 1;193 }194 if (!needFix)195 return from;196 197 // Make a copy of the string.198 p = from.data();199 char* q;200 CString result = CString::newUninitialized(newLen, q);201 while (char c = *p++) {202 if (c == '\r' && *p == '\n') {203 // Turn CRLF or CR into CR or LF.204 p++;205 *q++ = toEndingChar;206 } else if (c == fromEndingChar) {207 // Turn CR/LF into LF/CR.208 *q++ = toEndingChar;209 } else {210 // Leave other characters alone.211 *q++ = c;212 }213 }214 return result;215 }216 217 CString StringBlobItem::convertToCString(const String& text, LineEnding ending, TextEncoding encoding)218 {219 CString from = encoding.encode(text.characters(), text.length(), EntitiesForUnencodables);220 221 if (ending == EndingNative) {222 #if OS(WINDOWS)223 ending = EndingCRLF;224 #else225 ending = EndingLF;226 #endif227 }228 229 switch (ending) {230 case EndingTransparent:231 return from;232 case EndingCRLF:233 return convertToCRLF(from);234 case EndingCR:235 return convertToCROrLF(from, true);236 case EndingLF:237 return convertToCROrLF(from, false);238 default:239 ASSERT_NOT_REACHED();240 }241 242 ASSERT_NOT_REACHED();243 return from;244 116 } 245 117 -
trunk/WebCore/platform/BlobItem.h
r61149 r63343 33 33 34 34 #include "PlatformString.h" 35 #include "TextEncoding.h"36 35 #include <wtf/OwnPtr.h> 37 36 #include <wtf/PassRefPtr.h> … … 41 40 42 41 namespace WebCore { 43 44 // String ending types.45 enum LineEnding {46 EndingTransparent = 0,47 EndingNative,48 EndingLF,49 EndingCR,50 EndingCRLF,51 };52 42 53 43 class ByteArrayBlobItem; … … 127 117 class StringBlobItem : public DataBlobItem { 128 118 public: 129 static PassRefPtr<BlobItem> create(const String&, LineEnding, TextEncoding);130 119 static PassRefPtr<BlobItem> create(const CString&); 131 120 const CString& cstr() const { return m_data; } … … 139 128 140 129 private: 141 StringBlobItem(const String&, LineEnding, TextEncoding);142 130 StringBlobItem(const CString&); 143 static CString convertToCString(const String&, LineEnding, TextEncoding);144 131 CString m_data; 145 132 };
Note: See TracChangeset
for help on using the changeset viewer.