2010-07-14 Kinuko Yasuda <kinuko@chromium.org>
authorkinuko@chromium.org <kinuko@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Jul 2010 19:26:26 +0000 (19:26 +0000)
committerkinuko@chromium.org <kinuko@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Jul 2010 19:26:26 +0000 (19:26 +0000)
        Reviewed by Jian Li.

        Separate line-ending conversion code from BlobItem
        https://bugs.webkit.org/show_bug.cgi?id=40932

        Add common line-ending normalization code under platform/text.
        No new tests as it doesn't change any functionality.

        * CMakeLists.txt:
        * GNUmakefile.am:
        * WebCore.gypi:
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * html/BlobBuilder.cpp:
        (WebCore::BlobBuilder::appendString):
        * html/FormDataList.cpp:
        (WebCore::FormDataList::appendString):
        * platform/BlobItem.cpp:
        * platform/BlobItem.h:
        * platform/text/LineEnding.cpp: Added.
        * platform/text/LineEnding.h: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@63343 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
WebCore/CMakeLists.txt
WebCore/ChangeLog
WebCore/GNUmakefile.am
WebCore/WebCore.gypi
WebCore/WebCore.pro
WebCore/WebCore.vcproj/WebCore.vcproj
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/html/BlobBuilder.cpp
WebCore/html/FormDataList.cpp
WebCore/platform/BlobItem.cpp
WebCore/platform/BlobItem.h
WebCore/platform/text/LineEnding.cpp [new file with mode: 0644]
WebCore/platform/text/LineEnding.h [new file with mode: 0644]

index 2ec1525..42c8bb7 100644 (file)
@@ -1291,6 +1291,7 @@ SET(WebCore_SOURCES
 
     platform/text/Base64.cpp
     platform/text/BidiContext.cpp
+    platform/text/LineEnding.cpp
     platform/text/Hyphenation.cpp
     platform/text/RegularExpression.cpp
     platform/text/SegmentedString.cpp
index 433d7e7..a32ac85 100644 (file)
@@ -1,3 +1,28 @@
+2010-07-14  Kinuko Yasuda  <kinuko@chromium.org>
+
+        Reviewed by Jian Li.
+
+        Separate line-ending conversion code from BlobItem
+        https://bugs.webkit.org/show_bug.cgi?id=40932
+
+        Add common line-ending normalization code under platform/text.
+        No new tests as it doesn't change any functionality.
+
+        * CMakeLists.txt:
+        * GNUmakefile.am:
+        * WebCore.gypi:
+        * WebCore.pro:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * html/BlobBuilder.cpp:
+        (WebCore::BlobBuilder::appendString):
+        * html/FormDataList.cpp:
+        (WebCore::FormDataList::appendString):
+        * platform/BlobItem.cpp:
+        * platform/BlobItem.h:
+        * platform/text/LineEnding.cpp: Added.
+        * platform/text/LineEnding.h: Added.
+
 2010-07-14  Erik Arvidsson  <arv@chromium.org>
 
         Reviewed by Darin Adler.
index b2361c8..bec0ec5 100644 (file)
@@ -2091,6 +2091,8 @@ webcore_sources += \
        WebCore/platform/text/CharacterNames.h \
        WebCore/platform/text/Hyphenation.cpp \
        WebCore/platform/text/Hyphenation.h \
+       WebCore/platform/text/LineEnding.cpp \
+       WebCore/platform/text/LineEnding.h \
        WebCore/platform/text/ParserUtilities.h \
        WebCore/platform/text/PlatformString.h \
        WebCore/platform/text/RegularExpression.cpp \
index 00a04f1..5bd615b 100644 (file)
             'platform/text/CharacterNames.h',
             'platform/text/Hyphenation.cpp',
             'platform/text/Hyphenation.h',
+            'platform/text/LineEnding.cpp',
+            'platform/text/LineEnding.h',
             'platform/text/ParserUtilities.h',
             'platform/text/PlatformString.h',
             'platform/text/RegularExpression.cpp',
index 3f94ca7..c177603 100644 (file)
@@ -897,6 +897,7 @@ SOURCES += \
     platform/KillRingNone.cpp \
     platform/KURL.cpp \
     platform/Length.cpp \
+    platform/text/LineEnding.cpp \
     platform/LinkHash.cpp \
     platform/Logging.cpp \
     platform/MIMETypeRegistry.cpp \
@@ -1672,6 +1673,7 @@ HEADERS += \
     platform/KillRing.h \
     platform/KURL.h \
     platform/Length.h \
+    platform/text/LineEnding.h \
     platform/LinkHash.h \
     platform/Logging.h \
     platform/MIMETypeRegistry.h \
index c0473e9..0e477ca 100644 (file)
                                        >\r
                                </File>\r
                                <File\r
+                                       RelativePath="..\platform\text\LineEnding.cpp"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath="..\platform\text\LineEnding.h"\r
+                                       >\r
+                               </File>\r
+                               <File\r
                                        RelativePath="..\platform\text\ParserUtilities.h"\r
                                        >\r
                                </File>\r
index adefe7f..cadf3cc 100644 (file)
                895253DF116C4F0600CABF00 /* FileThreadTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 895253DE116C4F0600CABF00 /* FileThreadTask.h */; };
                8988E10E11A3508B00DB732E /* BlobItem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8988E10C11A3508B00DB732E /* BlobItem.cpp */; };
                8988E10F11A3508B00DB732E /* BlobItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 8988E10D11A3508B00DB732E /* BlobItem.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               89B5EAA111E8003D00F2367E /* LineEnding.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 89B5EA9F11E8003D00F2367E /* LineEnding.cpp */; };
+               89B5EAA211E8003D00F2367E /* LineEnding.h in Headers */ = {isa = PBXBuildFile; fileRef = 89B5EAA011E8003D00F2367E /* LineEnding.h */; settings = {ATTRIBUTES = (Private, ); }; };
                89BED5EB11BE11CE00448492 /* BlobBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 89BED5E911BE11CE00448492 /* BlobBuilder.cpp */; };
                89BED5EC11BE11CE00448492 /* BlobBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 89BED5EA11BE11CE00448492 /* BlobBuilder.h */; };
                89CD029311C85B870070B791 /* JSBlobBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 89CD029111C85B870070B791 /* JSBlobBuilder.cpp */; };
                895253DE116C4F0600CABF00 /* FileThreadTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileThreadTask.h; sourceTree = "<group>"; };
                8988E10C11A3508B00DB732E /* BlobItem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BlobItem.cpp; sourceTree = "<group>"; };
                8988E10D11A3508B00DB732E /* BlobItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlobItem.h; sourceTree = "<group>"; };
+               89B5EA9F11E8003D00F2367E /* LineEnding.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LineEnding.cpp; sourceTree = "<group>"; };
+               89B5EAA011E8003D00F2367E /* LineEnding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LineEnding.h; sourceTree = "<group>"; };
                89BED5E911BE11CE00448492 /* BlobBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BlobBuilder.cpp; sourceTree = "<group>"; };
                89BED5EA11BE11CE00448492 /* BlobBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlobBuilder.h; sourceTree = "<group>"; };
                89CD027911C859A80070B791 /* BlobBuilder.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = BlobBuilder.idl; sourceTree = "<group>"; };
                                B2C3D9F40D006C1D00EF6F26 /* BidiResolver.h */,
                                B2C3D9F50D006C1D00EF6F26 /* CharacterNames.h */,
                                375CD231119D43C800A2A859 /* Hyphenation.h */,
+                               89B5EA9F11E8003D00F2367E /* LineEnding.cpp */,
+                               89B5EAA011E8003D00F2367E /* LineEnding.h */,
                                BC76AC110DD7AD5C00415F34 /* ParserUtilities.h */,
                                B2C3D9FB0D006C1D00EF6F26 /* PlatformString.h */,
                                B2C3D9FC0D006C1D00EF6F26 /* RegularExpression.cpp */,
                                BCFF64920EAD15C200C1D6F7 /* LengthSize.h in Headers */,
                                B22279650D00BF220071B782 /* LinearGradientAttributes.h in Headers */,
                                AB31C91E10AE1B8E000C7B92 /* LineClampValue.h in Headers */,
+                               89B5EAA211E8003D00F2367E /* LineEnding.h in Headers */,
                                A7AD2F880EC89D07008AB002 /* LinkHash.h in Headers */,
                                BCB16C2D0979C3BD00467741 /* loader.h in Headers */,
                                656D37320ADBA5DE00A4554D /* LoaderNSURLExtras.h in Headers */,
                                51B2417B0D931F3F00E83F5C /* LegacyWebArchiveMac.mm in Sources */,
                                BCE65BEA0EACDF16007E4533 /* Length.cpp in Sources */,
                                A7AD2F870EC89D07008AB002 /* LinkHash.cpp in Sources */,
+                               89B5EAA111E8003D00F2367E /* LineEnding.cpp in Sources */,
                                BCB16C2C0979C3BD00467741 /* loader.cpp in Sources */,
                                656D37330ADBA5DE00A4554D /* LoaderNSURLExtras.mm in Sources */,
                                06E81EEC0AB5DA9700C87837 /* LocalCurrentGraphicsContext.mm in Sources */,
index cda1568..b2684fc 100644 (file)
 #include "AtomicString.h"
 #include "Blob.h"
 #include "ExceptionCode.h"
+#include "LineEnding.h"
 #include "TextEncoding.h"
 
 namespace WebCore {
 
-static bool getLineEndingTypeFromString(const AtomicString& typeString, LineEnding& endingType)
+static CString convertToCString(const String& text, const String& endingType, ExceptionCode& ec)
 {
     DEFINE_STATIC_LOCAL(AtomicString, transparent, ("transparent"));
     DEFINE_STATIC_LOCAL(AtomicString, native, ("native"));
 
-    if (typeString.isEmpty() || typeString == transparent) {
-        endingType = EndingTransparent;
-        return true;
-    }
-    if (typeString == native) {
-        endingType = EndingNative;
-        return true;
-    }
-    return false;
+    ec = 0;
+
+    if (endingType.isEmpty() || endingType == transparent)
+        return UTF8Encoding().encode(text.characters(), text.length(), EntitiesForUnencodables);
+    if (endingType == native)
+        return normalizeLineEndingsToNative(UTF8Encoding().encode(text.characters(), text.length(), EntitiesForUnencodables));
+
+    ec = SYNTAX_ERR;
+    return CString();
 }
 
-bool BlobBuilder::append(const String& text, const String& type, ExceptionCode& ec)
+bool BlobBuilder::append(const String& text, const String& endingType, ExceptionCode& ec)
 {
-    ec = 0;
-    LineEnding endingType;
-    if (!getLineEndingTypeFromString(type, endingType)) {
-        ec = SYNTAX_ERR;
+    CString cstr = convertToCString(text, endingType, ec);
+    if (ec)
         return false;
-    }
-    m_items.append(StringBlobItem::create(text, endingType, UTF8Encoding()));
+
+    m_items.append(StringBlobItem::create(cstr));
     return true;
 }
 
index 0f62595..94d0031 100644 (file)
@@ -21,6 +21,8 @@
 #include "config.h"
 #include "FormDataList.h"
 
+#include "LineEnding.h"
+
 namespace WebCore {
 
 FormDataList::FormDataList(const TextEncoding& c)
@@ -30,7 +32,8 @@ FormDataList::FormDataList(const TextEncoding& c)
 
 void FormDataList::appendString(const String& s)
 {
-    m_items.append(StringBlobItem::create(s, EndingCRLF, m_encoding));
+    CString cstr = m_encoding.encode(s.characters(), s.length(), EntitiesForUnencodables);
+    m_items.append(StringBlobItem::create(normalizeLineEndingsToCRLF(cstr)));
 }
 
 void FormDataList::appendString(const CString& s)
index a12dd08..9eeebcd 100644 (file)
@@ -105,144 +105,16 @@ PassRefPtr<BlobItem> FileBlobItem::slice(long long start, long long length)
 
 // StringBlobItem --------------------------------------------------------------
 
-PassRefPtr<BlobItem> StringBlobItem::create(const String& text, LineEnding ending, TextEncoding encoding)
-{
-    return adoptRef(static_cast<BlobItem*>(new StringBlobItem(text, ending, encoding)));
-}
-
 PassRefPtr<BlobItem> StringBlobItem::create(const CString& text)
 {
     return adoptRef(static_cast<BlobItem*>(new StringBlobItem(text)));
 }
 
-StringBlobItem::StringBlobItem(const String& text, LineEnding ending, TextEncoding encoding)
-    : m_data(StringBlobItem::convertToCString(text, ending, encoding))
-{
-}
-
 StringBlobItem::StringBlobItem(const CString& text)
     : m_data(text)
 {
 }
 
-// Normalize all line-endings to CRLF.
-static CString convertToCRLF(const CString& from)
-{
-    unsigned newLen = 0;
-    const char* p = from.data();
-    while (char c = *p++) {
-        if (c == '\r') {
-            // Safe to look ahead because of trailing '\0'.
-            if (*p != '\n') {
-                // Turn CR into CRLF.
-                newLen += 2;
-            }
-        } else if (c == '\n') {
-            // Turn LF into CRLF.
-            newLen += 2;
-        } else {
-            // Leave other characters alone.
-            newLen += 1;
-        }
-    }
-    if (newLen == from.length())
-        return from;
-
-    // Make a copy of the string.
-    p = from.data();
-    char* q;
-    CString result = CString::newUninitialized(newLen, q);
-    while (char c = *p++) {
-        if (c == '\r') {
-            // Safe to look ahead because of trailing '\0'.
-            if (*p != '\n') {
-                // Turn CR into CRLF.
-                *q++ = '\r';
-                *q++ = '\n';
-            }
-        } else if (c == '\n') {
-            // Turn LF into CRLF.
-            *q++ = '\r';
-            *q++ = '\n';
-        } else {
-            // Leave other characters alone.
-            *q++ = c;
-        }
-    }
-    return result;
-}
-
-// Normalize all line-endings to CR or LF.
-static CString convertToCROrLF(const CString& from, bool toCR)
-{
-    unsigned newLen = 0;
-    bool needFix = false;
-    const char* p = from.data();
-    char fromEndingChar = toCR ? '\n' : '\r';
-    char toEndingChar = toCR ? '\r' : '\n';
-    while (char c = *p++) {
-        if (c == '\r' && *p == '\n') {
-            // Turn CRLF into CR or LF.
-            p++;
-            needFix = true;
-        } else if (c == fromEndingChar) {
-            // Turn CR/LF into LF/CR.
-            needFix = true;
-        }
-        newLen += 1;
-    }
-    if (!needFix)
-        return from;
-
-    // Make a copy of the string.
-    p = from.data();
-    char* q;
-    CString result = CString::newUninitialized(newLen, q);
-    while (char c = *p++) {
-        if (c == '\r' && *p == '\n') {
-            // Turn CRLF or CR into CR or LF.
-            p++;
-            *q++ = toEndingChar;
-        } else if (c == fromEndingChar) {
-            // Turn CR/LF into LF/CR.
-            *q++ = toEndingChar;
-        } else {
-            // Leave other characters alone.
-            *q++ = c;
-        }
-    }
-    return result;
-}
-
-CString StringBlobItem::convertToCString(const String& text, LineEnding ending, TextEncoding encoding)
-{
-    CString from = encoding.encode(text.characters(), text.length(), EntitiesForUnencodables);
-
-    if (ending == EndingNative) {
-#if OS(WINDOWS)
-        ending = EndingCRLF;
-#else
-        ending = EndingLF;
-#endif
-    }
-
-    switch (ending) {
-    case EndingTransparent:
-        return from;
-    case EndingCRLF:
-        return convertToCRLF(from);
-    case EndingCR:
-        return convertToCROrLF(from, true);
-    case EndingLF:
-        return convertToCROrLF(from, false);
-    default:
-        ASSERT_NOT_REACHED();
-    }
-
-    ASSERT_NOT_REACHED();
-    return from;
-}
-
 // ByteArrayBlobItem ----------------------------------------------------------
 
 PassRefPtr<BlobItem> ByteArrayBlobItem::create(const char* data, size_t size)
index 1d34c59..e6cc2dc 100644 (file)
@@ -32,7 +32,6 @@
 #define BlobItem_h
 
 #include "PlatformString.h"
-#include "TextEncoding.h"
 #include <wtf/OwnPtr.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 
 namespace WebCore {
 
-// String ending types.
-enum LineEnding {
-    EndingTransparent = 0,
-    EndingNative,
-    EndingLF,
-    EndingCR,
-    EndingCRLF,
-};
-
 class ByteArrayBlobItem;
 class DataBlobItem;
 class DataRangeBlobItem;
@@ -126,7 +116,6 @@ protected:
 
 class StringBlobItem : public DataBlobItem {
 public:
-    static PassRefPtr<BlobItem> create(const String&, LineEnding, TextEncoding);
     static PassRefPtr<BlobItem> create(const CString&);
     const CString& cstr() const { return m_data; }
 
@@ -138,9 +127,7 @@ public:
     virtual const char* data() const { return m_data.data(); }
 
 private:
-    StringBlobItem(const String&, LineEnding, TextEncoding);
     StringBlobItem(const CString&);
-    static CString convertToCString(const String&, LineEnding, TextEncoding);
     CString m_data;
 };
 
diff --git a/WebCore/platform/text/LineEnding.cpp b/WebCore/platform/text/LineEnding.cpp
new file mode 100644 (file)
index 0000000..545f22b
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "LineEnding.h"
+
+#include "PlatformString.h"
+#include <wtf/text/CString.h>
+
+namespace WebCore {
+
+// Normalize all line-endings to CRLF.
+CString normalizeLineEndingsToCRLF(const CString& from)
+{
+    unsigned newLen = 0;
+    const char* p = from.data();
+    while (char c = *p++) {
+        if (c == '\r') {
+            // Safe to look ahead because of trailing '\0'.
+            if (*p != '\n') {
+                // Turn CR into CRLF.
+                newLen += 2;
+            }
+        } else if (c == '\n') {
+            // Turn LF into CRLF.
+            newLen += 2;
+        } else {
+            // Leave other characters alone.
+            newLen += 1;
+        }
+    }
+    if (newLen == from.length())
+        return from;
+
+    // Make a copy of the string.
+    p = from.data();
+    char* q;
+    CString result = CString::newUninitialized(newLen, q);
+    while (char c = *p++) {
+        if (c == '\r') {
+            // Safe to look ahead because of trailing '\0'.
+            if (*p != '\n') {
+                // Turn CR into CRLF.
+                *q++ = '\r';
+                *q++ = '\n';
+            }
+        } else if (c == '\n') {
+            // Turn LF into CRLF.
+            *q++ = '\r';
+            *q++ = '\n';
+        } else {
+            // Leave other characters alone.
+            *q++ = c;
+        }
+    }
+    return result;
+}
+
+// Normalize all line-endings to CR or LF.
+static CString normalizeToCROrLF(const CString& from, bool toCR)
+{
+    unsigned newLen = 0;
+    bool needFix = false;
+    const char* p = from.data();
+    char fromEndingChar = toCR ? '\n' : '\r';
+    char toEndingChar = toCR ? '\r' : '\n';
+    while (char c = *p++) {
+        if (c == '\r' && *p == '\n') {
+            // Turn CRLF into CR or LF.
+            p++;
+            needFix = true;
+        } else if (c == fromEndingChar) {
+            // Turn CR/LF into LF/CR.
+            needFix = true;
+        }
+        newLen += 1;
+    }
+    if (!needFix)
+        return from;
+
+    // Make a copy of the string.
+    p = from.data();
+    char* q;
+    CString result = CString::newUninitialized(newLen, q);
+    while (char c = *p++) {
+        if (c == '\r' && *p == '\n') {
+            // Turn CRLF or CR into CR or LF.
+            p++;
+            *q++ = toEndingChar;
+        } else if (c == fromEndingChar) {
+            // Turn CR/LF into LF/CR.
+            *q++ = toEndingChar;
+        } else {
+            // Leave other characters alone.
+            *q++ = c;
+        }
+    }
+    return result;
+}
+
+// Normalize all line-endings to CR.
+CString normalizeLineEndingsToCR(const CString& from)
+{
+    return normalizeToCROrLF(from, true);
+}
+
+// Normalize all line-endings to LF.
+CString normalizeLineEndingsToLF(const CString& from)
+{
+    return normalizeToCROrLF(from, false);
+}
+
+CString normalizeLineEndingsToNative(const CString& from)
+{
+#if OS(WINDOWS)
+    return normalizeLineEndingsToCRLF(from);
+#else
+    return normalizeLineEndingsToLF(from);
+#endif
+}
+
+} // namespace WebCore
diff --git a/WebCore/platform/text/LineEnding.h b/WebCore/platform/text/LineEnding.h
new file mode 100644 (file)
index 0000000..9c3e2aa
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef LineEnding_h
+#define LineEnding_h
+
+namespace WTF {
+class CString;
+}
+
+namespace WebCore {
+
+// Normalize all line-endings in the given string to CRLF.
+WTF::CString normalizeLineEndingsToCRLF(const WTF::CString&);
+
+// Normalize all line-endings in the given string to CR.
+WTF::CString normalizeLineEndingsToCR(const WTF::CString&);
+
+// Normalize all line-endings in the given string to LF.
+WTF::CString normalizeLineEndingsToLF(const WTF::CString&);
+
+// Normalize all line-endings in the given string to the native line-endings.
+// (Normalize to CRLF on Windows and normalize to LF on all other platforms.)
+WTF::CString normalizeLineEndingsToNative(const WTF::CString&);
+
+} // namespace WebCore
+
+#endif // LineEnding_h