diff options
Diffstat (limited to 'WebCore/platform/BlobItem.cpp')
-rw-r--r-- | WebCore/platform/BlobItem.cpp | 142 |
1 files changed, 14 insertions, 128 deletions
diff --git a/WebCore/platform/BlobItem.cpp b/WebCore/platform/BlobItem.cpp index a12dd08..cc5e6c7 100644 --- a/WebCore/platform/BlobItem.cpp +++ b/WebCore/platform/BlobItem.cpp @@ -78,6 +78,20 @@ FileBlobItem::FileBlobItem(const String& path) { } +#if ENABLE(DIRECTORY_UPLOAD) +PassRefPtr<BlobItem> FileBlobItem::create(const String& path, const String& relativePath) +{ + return adoptRef(static_cast<BlobItem*>(new FileBlobItem(path, relativePath))); +} + +FileBlobItem::FileBlobItem(const String& path, const String& relativePath) + : m_path(path) + , m_fileName(pathGetFileName(m_path)) + , m_relativePath(relativePath) +{ +} +#endif + unsigned long long FileBlobItem::size() const { // FIXME: synchronized file call @@ -105,144 +119,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) |