| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2006 Alexey Proskuryakov <ap@nypop.com> | 3 * Copyright (C) 2006 Alexey Proskuryakov <ap@nypop.com> |
| 4 * Copyright (C) 2007-2009 Torch Mobile, Inc. | 4 * Copyright (C) 2007-2009 Torch Mobile, Inc. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 65 } |
| 66 | 66 |
| 67 CString TextEncoding::encode(const String& string, UnencodableHandling handling)
const | 67 CString TextEncoding::encode(const String& string, UnencodableHandling handling)
const |
| 68 { | 68 { |
| 69 if (!m_name) | 69 if (!m_name) |
| 70 return CString(); | 70 return CString(); |
| 71 | 71 |
| 72 if (string.isEmpty()) | 72 if (string.isEmpty()) |
| 73 return ""; | 73 return ""; |
| 74 | 74 |
| 75 OwnPtr<TextCodec> textCodec = newTextCodec(*this); |
| 76 CString encodedString; |
| 77 if (string.is8Bit()) |
| 78 encodedString = textCodec->encode(string.characters8(), string.length(),
handling); |
| 79 else |
| 80 encodedString = textCodec->encode(string.characters16(), string.length()
, handling); |
| 81 return encodedString; |
| 82 } |
| 83 |
| 84 CString TextEncoding::normalizeAndEncode(const String& string, UnencodableHandli
ng handling) const |
| 85 { |
| 86 if (!m_name) |
| 87 return CString(); |
| 88 |
| 89 if (string.isEmpty()) |
| 90 return ""; |
| 91 |
| 75 // Text exclusively containing Latin-1 characters (U+0000..U+00FF) is left | 92 // Text exclusively containing Latin-1 characters (U+0000..U+00FF) is left |
| 76 // unaffected by NFC. This is effectively the same as saying that all | 93 // unaffected by NFC. This is effectively the same as saying that all |
| 77 // Latin-1 text is already normalized to NFC. | 94 // Latin-1 text is already normalized to NFC. |
| 78 // Source: http://unicode.org/reports/tr15/ | 95 // Source: http://unicode.org/reports/tr15/ |
| 79 if (string.is8Bit()) | 96 if (string.is8Bit()) |
| 80 return newTextCodec(*this)->encode(string.characters8(), string.length()
, handling); | 97 return newTextCodec(*this)->encode(string.characters8(), string.length()
, handling); |
| 81 | 98 |
| 82 // FIXME: What's the right place to do normalization? | |
| 83 // It's a little strange to do it inside the encode function. | |
| 84 // Perhaps normalization should be an explicit step done before calling enco
de. | |
| 85 | |
| 86 const UChar* source = string.characters16(); | 99 const UChar* source = string.characters16(); |
| 87 size_t length = string.length(); | 100 size_t length = string.length(); |
| 88 | 101 |
| 89 Vector<UChar> normalizedCharacters; | 102 Vector<UChar> normalizedCharacters; |
| 90 | 103 |
| 91 UErrorCode err = U_ZERO_ERROR; | 104 UErrorCode err = U_ZERO_ERROR; |
| 92 if (unorm_quickCheck(source, length, UNORM_NFC, &err) != UNORM_YES) { | 105 if (unorm_quickCheck(source, length, UNORM_NFC, &err) != UNORM_YES) { |
| 93 // First try using the length of the original string, since normalizatio
n to NFC rarely increases length. | 106 // First try using the length of the original string, since normalizatio
n to NFC rarely increases length. |
| 94 normalizedCharacters.grow(length); | 107 normalizedCharacters.grow(length); |
| 95 int32_t normalizedLength = unorm_normalize(source, length, UNORM_NFC, 0,
normalizedCharacters.data(), length, &err); | 108 int32_t normalizedLength = unorm_normalize(source, length, UNORM_NFC, 0,
normalizedCharacters.data(), length, &err); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 return globalUTF8Encoding; | 240 return globalUTF8Encoding; |
| 228 } | 241 } |
| 229 | 242 |
| 230 const TextEncoding& WindowsLatin1Encoding() | 243 const TextEncoding& WindowsLatin1Encoding() |
| 231 { | 244 { |
| 232 static TextEncoding globalWindowsLatin1Encoding("WinLatin1"); | 245 static TextEncoding globalWindowsLatin1Encoding("WinLatin1"); |
| 233 return globalWindowsLatin1Encoding; | 246 return globalWindowsLatin1Encoding; |
| 234 } | 247 } |
| 235 | 248 |
| 236 } // namespace WTF | 249 } // namespace WTF |
| OLD | NEW |