| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  * Copyright (C) 2004, 2006, 2008, 2010 Apple Inc. All rights reserved. |    2  * Copyright (C) 2004, 2006, 2008, 2010 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   69  |   69  | 
|   70 String TextCodecUTF16::decode(const char* bytes, size_t length, FlushBehavior fl
     ush, bool, bool& sawError) |   70 String TextCodecUTF16::decode(const char* bytes, size_t length, FlushBehavior fl
     ush, bool, bool& sawError) | 
|   71 { |   71 { | 
|   72     // For compatibility reasons, ignore flush from fetch EOF. |   72     // For compatibility reasons, ignore flush from fetch EOF. | 
|   73     const bool reallyFlush = flush != DoNotFlush && flush != FetchEOF; |   73     const bool reallyFlush = flush != DoNotFlush && flush != FetchEOF; | 
|   74  |   74  | 
|   75     if (!length) { |   75     if (!length) { | 
|   76         if (!reallyFlush || !m_haveBufferedByte) |   76         if (!reallyFlush || !m_haveBufferedByte) | 
|   77             return String(); |   77             return String(); | 
|   78         sawError = true; |   78         sawError = true; | 
|   79         return String(&Unicode::replacementCharacter, 1); |   79         return String(&replacementCharacter, 1); | 
|   80     } |   80     } | 
|   81  |   81  | 
|   82     // FIXME: This should generate an error if there is an unpaired surrogate. |   82     // FIXME: This should generate an error if there is an unpaired surrogate. | 
|   83  |   83  | 
|   84     const unsigned char* p = reinterpret_cast<const unsigned char*>(bytes); |   84     const unsigned char* p = reinterpret_cast<const unsigned char*>(bytes); | 
|   85     size_t numBytes = length + m_haveBufferedByte; |   85     size_t numBytes = length + m_haveBufferedByte; | 
|   86     size_t numCharsIn = numBytes / 2; |   86     size_t numCharsIn = numBytes / 2; | 
|   87     size_t numCharsOut = ((numBytes & 1) && reallyFlush) ? numCharsIn + 1 : numC
     harsIn; |   87     size_t numCharsOut = ((numBytes & 1) && reallyFlush) ? numCharsIn + 1 : numC
     harsIn; | 
|   88  |   88  | 
|   89     StringBuffer<UChar> buffer(numCharsOut); |   89     StringBuffer<UChar> buffer(numCharsOut); | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
|  113             p += 2; |  113             p += 2; | 
|  114             *q++ = c; |  114             *q++ = c; | 
|  115         } |  115         } | 
|  116     } |  116     } | 
|  117  |  117  | 
|  118     if (numBytes & 1) { |  118     if (numBytes & 1) { | 
|  119         ASSERT(!m_haveBufferedByte); |  119         ASSERT(!m_haveBufferedByte); | 
|  120  |  120  | 
|  121         if (reallyFlush) { |  121         if (reallyFlush) { | 
|  122             sawError = true; |  122             sawError = true; | 
|  123             *q++ = Unicode::replacementCharacter; |  123             *q++ = replacementCharacter; | 
|  124         } else { |  124         } else { | 
|  125             m_haveBufferedByte = true; |  125             m_haveBufferedByte = true; | 
|  126             m_bufferedByte = p[0]; |  126             m_bufferedByte = p[0]; | 
|  127         } |  127         } | 
|  128     } |  128     } | 
|  129  |  129  | 
|  130     buffer.shrink(q - buffer.characters()); |  130     buffer.shrink(q - buffer.characters()); | 
|  131  |  131  | 
|  132     return String::adopt(buffer); |  132     return String::adopt(buffer); | 
|  133 } |  133 } | 
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  181         for (size_t i = 0; i < length; ++i) { |  181         for (size_t i = 0; i < length; ++i) { | 
|  182             bytes[i * 2] = 0; |  182             bytes[i * 2] = 0; | 
|  183             bytes[i * 2 + 1] = characters[i]; |  183             bytes[i * 2 + 1] = characters[i]; | 
|  184         } |  184         } | 
|  185     } |  185     } | 
|  186  |  186  | 
|  187     return result; |  187     return result; | 
|  188 } |  188 } | 
|  189  |  189  | 
|  190 } // namespace WTF |  190 } // namespace WTF | 
| OLD | NEW |