| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 for (size_t i = 0; i < inputLength; ++i) { | 67 for (size_t i = 0; i < inputLength; ++i) { |
| 68 bool isLastCharacter = (i == inputLength - 1); | 68 bool isLastCharacter = (i == inputLength - 1); |
| 69 char currentCharacter = input[i]; | 69 char currentCharacter = input[i]; |
| 70 bool requiresEncoding = false; | 70 bool requiresEncoding = false; |
| 71 // All non-printable ASCII characters and = require encoding. | 71 // All non-printable ASCII characters and = require encoding. |
| 72 if ((currentCharacter < ' ' || currentCharacter > '~' || | 72 if ((currentCharacter < ' ' || currentCharacter > '~' || |
| 73 currentCharacter == '=') && | 73 currentCharacter == '=') && |
| 74 currentCharacter != '\t') | 74 currentCharacter != '\t') |
| 75 requiresEncoding = true; | 75 requiresEncoding = true; |
| 76 | 76 |
| 77 // Space and tab characters have to be encoded if they appear at the end of
a line. | 77 // Space and tab characters have to be encoded if they appear at the end of |
| 78 // a line. |
| 78 if (!requiresEncoding && | 79 if (!requiresEncoding && |
| 79 (currentCharacter == '\t' || currentCharacter == ' ') && | 80 (currentCharacter == '\t' || currentCharacter == ' ') && |
| 80 (isLastCharacter || | 81 (isLastCharacter || |
| 81 lengthOfLineEndingAtIndex(input, inputLength, i + 1))) | 82 lengthOfLineEndingAtIndex(input, inputLength, i + 1))) |
| 82 requiresEncoding = true; | 83 requiresEncoding = true; |
| 83 | 84 |
| 84 // End of line should be converted to CR-LF sequences. | 85 // End of line should be converted to CR-LF sequences. |
| 85 if (!isLastCharacter) { | 86 if (!isLastCharacter) { |
| 86 size_t lengthOfLineEnding = | 87 size_t lengthOfLineEnding = |
| 87 lengthOfLineEndingAtIndex(input, inputLength, i); | 88 lengthOfLineEndingAtIndex(input, inputLength, i); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 // Unfinished = sequence, append as is. | 143 // Unfinished = sequence, append as is. |
| 143 out.append(currentCharacter); | 144 out.append(currentCharacter); |
| 144 continue; | 145 continue; |
| 145 } | 146 } |
| 146 char upperCharacter = data[++i]; | 147 char upperCharacter = data[++i]; |
| 147 char lowerCharacter = data[++i]; | 148 char lowerCharacter = data[++i]; |
| 148 if (upperCharacter == '\r' && lowerCharacter == '\n') | 149 if (upperCharacter == '\r' && lowerCharacter == '\n') |
| 149 continue; | 150 continue; |
| 150 | 151 |
| 151 if (!isASCIIHexDigit(upperCharacter) || !isASCIIHexDigit(lowerCharacter)) { | 152 if (!isASCIIHexDigit(upperCharacter) || !isASCIIHexDigit(lowerCharacter)) { |
| 152 // Invalid sequence, = followed by non hex digits, just insert the charact
ers as is. | 153 // Invalid sequence, = followed by non hex digits, just insert the |
| 154 // characters as is. |
| 153 out.append('='); | 155 out.append('='); |
| 154 out.append(upperCharacter); | 156 out.append(upperCharacter); |
| 155 out.append(lowerCharacter); | 157 out.append(lowerCharacter); |
| 156 continue; | 158 continue; |
| 157 } | 159 } |
| 158 out.append( | 160 out.append( |
| 159 static_cast<char>(toASCIIHexValue(upperCharacter, lowerCharacter))); | 161 static_cast<char>(toASCIIHexValue(upperCharacter, lowerCharacter))); |
| 160 } | 162 } |
| 161 } | 163 } |
| 162 | 164 |
| 163 } // namespace blink | 165 } // namespace blink |
| OLD | NEW |