OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "config.h" | 21 #include "config.h" |
22 #include "FormDataList.h" | 22 #include "FormDataList.h" |
23 | 23 |
24 namespace WebCore { | 24 namespace WebCore { |
25 | 25 |
26 FormDataList::FormDataList(const TextEncoding& c) | 26 FormDataList::FormDataList(const TextEncoding& c) |
27 : m_encoding(c) | 27 : m_encoding(c) |
28 { | 28 { |
29 } | 29 } |
30 | 30 |
| 31 void FormDataList::appendString(const String& s) |
| 32 { |
| 33 m_items.append(StringBlobItem::create(s, EndingCRLF, m_encoding)); |
| 34 } |
| 35 |
31 void FormDataList::appendString(const CString& s) | 36 void FormDataList::appendString(const CString& s) |
32 { | 37 { |
33 m_list.append(s); | 38 m_items.append(StringBlobItem::create(s)); |
34 } | 39 } |
35 | 40 |
36 // Change plain CR and plain LF to CRLF pairs. | 41 void FormDataList::appendBlob(const String& key, PassRefPtr<Blob> blob) |
37 static CString fixLineBreaks(const CString& s) | |
38 { | 42 { |
39 // Compute the length. | 43 appendString(key); |
40 unsigned newLen = 0; | 44 const BlobItemList& items = blob->items(); |
41 const char* p = s.data(); | 45 for (size_t i = 0; i < items.size(); ++i) |
42 while (char c = *p++) { | 46 m_items.append(items.at(i)); |
43 if (c == '\r') { | |
44 // Safe to look ahead because of trailing '\0'. | |
45 if (*p != '\n') { | |
46 // Turn CR into CRLF. | |
47 newLen += 2; | |
48 } | |
49 } else if (c == '\n') { | |
50 // Turn LF into CRLF. | |
51 newLen += 2; | |
52 } else { | |
53 // Leave other characters alone. | |
54 newLen += 1; | |
55 } | |
56 } | |
57 if (newLen == s.length()) { | |
58 return s; | |
59 } | |
60 | |
61 // Make a copy of the string. | |
62 p = s.data(); | |
63 char* q; | |
64 CString result = CString::newUninitialized(newLen, q); | |
65 while (char c = *p++) { | |
66 if (c == '\r') { | |
67 // Safe to look ahead because of trailing '\0'. | |
68 if (*p != '\n') { | |
69 // Turn CR into CRLF. | |
70 *q++ = '\r'; | |
71 *q++ = '\n'; | |
72 } | |
73 } else if (c == '\n') { | |
74 // Turn LF into CRLF. | |
75 *q++ = '\r'; | |
76 *q++ = '\n'; | |
77 } else { | |
78 // Leave other characters alone. | |
79 *q++ = c; | |
80 } | |
81 } | |
82 return result; | |
83 } | |
84 | |
85 void FormDataList::appendString(const String& s) | |
86 { | |
87 CString cstr = fixLineBreaks(m_encoding.encode(s.characters(), s.length(), E
ntitiesForUnencodables)); | |
88 m_list.append(cstr); | |
89 } | 47 } |
90 | 48 |
91 } // namespace | 49 } // namespace |
OLD | NEW |