OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 96 } |
97 | 97 |
98 size_t lengthOfEncodedCharacter = 1; | 98 size_t lengthOfEncodedCharacter = 1; |
99 if (requiresEncoding) | 99 if (requiresEncoding) |
100 lengthOfEncodedCharacter += 2; | 100 lengthOfEncodedCharacter += 2; |
101 if (!isLastCharacter) | 101 if (!isLastCharacter) |
102 lengthOfEncodedCharacter += 1; // + 1 for the = (soft line break). | 102 lengthOfEncodedCharacter += 1; // + 1 for the = (soft line break). |
103 | 103 |
104 // Insert a soft line break if necessary. | 104 // Insert a soft line break if necessary. |
105 if (currentLineLength + lengthOfEncodedCharacter > maximumLineLength) { | 105 if (currentLineLength + lengthOfEncodedCharacter > maximumLineLength) { |
106 out.append('='); | 106 out.push_back('='); |
107 out.append(crlfLineEnding, strlen(crlfLineEnding)); | 107 out.append(crlfLineEnding, strlen(crlfLineEnding)); |
108 currentLineLength = 0; | 108 currentLineLength = 0; |
109 } | 109 } |
110 | 110 |
111 // Finally, insert the actual character(s). | 111 // Finally, insert the actual character(s). |
112 if (requiresEncoding) { | 112 if (requiresEncoding) { |
113 out.append('='); | 113 out.push_back('='); |
114 out.append(upperNibbleToASCIIHexDigit(currentCharacter)); | 114 out.push_back(upperNibbleToASCIIHexDigit(currentCharacter)); |
115 out.append(lowerNibbleToASCIIHexDigit(currentCharacter)); | 115 out.push_back(lowerNibbleToASCIIHexDigit(currentCharacter)); |
116 currentLineLength += 3; | 116 currentLineLength += 3; |
117 } else { | 117 } else { |
118 out.append(currentCharacter); | 118 out.push_back(currentCharacter); |
119 currentLineLength++; | 119 currentLineLength++; |
120 } | 120 } |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 void quotedPrintableDecode(const Vector<char>& in, Vector<char>& out) { | 124 void quotedPrintableDecode(const Vector<char>& in, Vector<char>& out) { |
125 quotedPrintableDecode(in.data(), in.size(), out); | 125 quotedPrintableDecode(in.data(), in.size(), out); |
126 } | 126 } |
127 | 127 |
128 void quotedPrintableDecode(const char* data, | 128 void quotedPrintableDecode(const char* data, |
129 size_t dataLength, | 129 size_t dataLength, |
130 Vector<char>& out) { | 130 Vector<char>& out) { |
131 out.clear(); | 131 out.clear(); |
132 if (!dataLength) | 132 if (!dataLength) |
133 return; | 133 return; |
134 | 134 |
135 for (size_t i = 0; i < dataLength; ++i) { | 135 for (size_t i = 0; i < dataLength; ++i) { |
136 char currentCharacter = data[i]; | 136 char currentCharacter = data[i]; |
137 if (currentCharacter != '=') { | 137 if (currentCharacter != '=') { |
138 out.append(currentCharacter); | 138 out.push_back(currentCharacter); |
139 continue; | 139 continue; |
140 } | 140 } |
141 // We are dealing with a '=xx' sequence. | 141 // We are dealing with a '=xx' sequence. |
142 if (dataLength - i < 3) { | 142 if (dataLength - i < 3) { |
143 // Unfinished = sequence, append as is. | 143 // Unfinished = sequence, append as is. |
144 out.append(currentCharacter); | 144 out.push_back(currentCharacter); |
145 continue; | 145 continue; |
146 } | 146 } |
147 char upperCharacter = data[++i]; | 147 char upperCharacter = data[++i]; |
148 char lowerCharacter = data[++i]; | 148 char lowerCharacter = data[++i]; |
149 if (upperCharacter == '\r' && lowerCharacter == '\n') | 149 if (upperCharacter == '\r' && lowerCharacter == '\n') |
150 continue; | 150 continue; |
151 | 151 |
152 if (!isASCIIHexDigit(upperCharacter) || !isASCIIHexDigit(lowerCharacter)) { | 152 if (!isASCIIHexDigit(upperCharacter) || !isASCIIHexDigit(lowerCharacter)) { |
153 // Invalid sequence, = followed by non hex digits, just insert the | 153 // Invalid sequence, = followed by non hex digits, just insert the |
154 // characters as is. | 154 // characters as is. |
155 out.append('='); | 155 out.push_back('='); |
156 out.append(upperCharacter); | 156 out.push_back(upperCharacter); |
157 out.append(lowerCharacter); | 157 out.push_back(lowerCharacter); |
158 continue; | 158 continue; |
159 } | 159 } |
160 out.append( | 160 out.push_back( |
161 static_cast<char>(toASCIIHexValue(upperCharacter, lowerCharacter))); | 161 static_cast<char>(toASCIIHexValue(upperCharacter, lowerCharacter))); |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 } // namespace blink | 165 } // namespace blink |
OLD | NEW |