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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 static CString encodeComplexUserDefined(const CharType* characters, size_t lengt
h, UnencodableHandling handling) | 66 static CString encodeComplexUserDefined(const CharType* characters, size_t lengt
h, UnencodableHandling handling) |
67 { | 67 { |
68 Vector<char> result(length); | 68 Vector<char> result(length); |
69 char* bytes = result.data(); | 69 char* bytes = result.data(); |
70 | 70 |
71 size_t resultLength = 0; | 71 size_t resultLength = 0; |
72 for (size_t i = 0; i < length; ) { | 72 for (size_t i = 0; i < length; ) { |
73 UChar32 c; | 73 UChar32 c; |
74 U16_NEXT(characters, i, length, c); | 74 U16_NEXT(characters, i, length, c); |
75 signed char signedByte = static_cast<signed char>(c); | 75 signed char signedByte = static_cast<signed char>(c); |
76 if ((signedByte & 0xF7FF) == c) | 76 if ((signedByte & 0xF7FF) == c) { |
77 bytes[resultLength++] = signedByte; | 77 bytes[resultLength++] = signedByte; |
78 else { | 78 } else { |
79 // No way to encode this character with x-user-defined. | 79 // No way to encode this character with x-user-defined. |
80 UnencodableReplacementArray replacement; | 80 UnencodableReplacementArray replacement; |
81 int replacementLength = TextCodec::getUnencodableReplacement(c, hand
ling, replacement); | 81 int replacementLength = TextCodec::getUnencodableReplacement(c, hand
ling, replacement); |
82 result.grow(resultLength + replacementLength + length - i); | 82 result.grow(resultLength + replacementLength + length - i); |
83 bytes = result.data(); | 83 bytes = result.data(); |
84 memcpy(bytes + resultLength, replacement, replacementLength); | 84 memcpy(bytes + resultLength, replacement, replacementLength); |
85 resultLength += replacementLength; | 85 resultLength += replacementLength; |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
(...skipping 25 matching lines...) Expand all Loading... |
114 { | 114 { |
115 return encodeCommon(characters, length, handling); | 115 return encodeCommon(characters, length, handling); |
116 } | 116 } |
117 | 117 |
118 CString TextCodecUserDefined::encode(const LChar* characters, size_t length, Une
ncodableHandling handling) | 118 CString TextCodecUserDefined::encode(const LChar* characters, size_t length, Une
ncodableHandling handling) |
119 { | 119 { |
120 return encodeCommon(characters, length, handling); | 120 return encodeCommon(characters, length, handling); |
121 } | 121 } |
122 | 122 |
123 } // namespace WTF | 123 } // namespace WTF |
OLD | NEW |