| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008 Apple, Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple, 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 return CString(bytes, resultLength); | 94 return CString(bytes, resultLength); |
| 95 } | 95 } |
| 96 | 96 |
| 97 template <typename CharType> | 97 template <typename CharType> |
| 98 CString TextCodecUserDefined::encodeCommon(const CharType* characters, | 98 CString TextCodecUserDefined::encodeCommon(const CharType* characters, |
| 99 size_t length, | 99 size_t length, |
| 100 UnencodableHandling handling) { | 100 UnencodableHandling handling) { |
| 101 char* bytes; | 101 char* bytes; |
| 102 CString result = CString::newUninitialized(length, bytes); | 102 CString result = CString::newUninitialized(length, bytes); |
| 103 | 103 |
| 104 // Convert the string a fast way and simultaneously do an efficient check to s
ee if it's all ASCII. | 104 // Convert the string a fast way and simultaneously do an efficient check to |
| 105 // see if it's all ASCII. |
| 105 UChar ored = 0; | 106 UChar ored = 0; |
| 106 for (size_t i = 0; i < length; ++i) { | 107 for (size_t i = 0; i < length; ++i) { |
| 107 UChar c = characters[i]; | 108 UChar c = characters[i]; |
| 108 bytes[i] = static_cast<char>(c); | 109 bytes[i] = static_cast<char>(c); |
| 109 ored |= c; | 110 ored |= c; |
| 110 } | 111 } |
| 111 | 112 |
| 112 if (!(ored & 0xFF80)) | 113 if (!(ored & 0xFF80)) |
| 113 return result; | 114 return result; |
| 114 | 115 |
| 115 // If it wasn't all ASCII, call the function that handles more-complex cases. | 116 // If it wasn't all ASCII, call the function that handles more-complex cases. |
| 116 return encodeComplexUserDefined(characters, length, handling); | 117 return encodeComplexUserDefined(characters, length, handling); |
| 117 } | 118 } |
| 118 | 119 |
| 119 CString TextCodecUserDefined::encode(const UChar* characters, | 120 CString TextCodecUserDefined::encode(const UChar* characters, |
| 120 size_t length, | 121 size_t length, |
| 121 UnencodableHandling handling) { | 122 UnencodableHandling handling) { |
| 122 return encodeCommon(characters, length, handling); | 123 return encodeCommon(characters, length, handling); |
| 123 } | 124 } |
| 124 | 125 |
| 125 CString TextCodecUserDefined::encode(const LChar* characters, | 126 CString TextCodecUserDefined::encode(const LChar* characters, |
| 126 size_t length, | 127 size_t length, |
| 127 UnencodableHandling handling) { | 128 UnencodableHandling handling) { |
| 128 return encodeCommon(characters, length, handling); | 129 return encodeCommon(characters, length, handling); |
| 129 } | 130 } |
| 130 | 131 |
| 131 } // namespace WTF | 132 } // namespace WTF |
| OLD | NEW |