| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 , m_fatal(fatal) | 61 , m_fatal(fatal) |
| 62 { | 62 { |
| 63 } | 63 } |
| 64 | 64 |
| 65 TextDecoder::~TextDecoder() | 65 TextDecoder::~TextDecoder() |
| 66 { | 66 { |
| 67 } | 67 } |
| 68 | 68 |
| 69 String TextDecoder::encoding() const | 69 String TextDecoder::encoding() const |
| 70 { | 70 { |
| 71 return String(m_encoding.name()).lower(); | 71 String name = String(m_encoding.name()).lower(); |
| 72 // Where possible, encoding aliases should be handled by changes to Chromium
's ICU or Blink's WTF. |
| 73 // The same codec is used, but WTF maintains a different name/identity for t
hese. |
| 74 if (name == "iso-8859-1" || name == "us-ascii") |
| 75 return "windows-1252"; |
| 76 return name; |
| 72 } | 77 } |
| 73 | 78 |
| 74 String TextDecoder::decode(ArrayBufferView* input, const Dictionary& options, Ex
ceptionState& es) | 79 String TextDecoder::decode(ArrayBufferView* input, const Dictionary& options, Ex
ceptionState& es) |
| 75 { | 80 { |
| 76 bool stream = false; | 81 bool stream = false; |
| 77 options.get("stream", stream); | 82 options.get("stream", stream); |
| 78 | 83 |
| 79 const char* start = input ? static_cast<const char*>(input->baseAddress()) :
0; | 84 const char* start = input ? static_cast<const char*>(input->baseAddress()) :
0; |
| 80 size_t length = input ? input->byteLength() : 0; | 85 size_t length = input ? input->byteLength() : 0; |
| 81 | 86 |
| 82 bool flush = !stream; | 87 bool flush = !stream; |
| 83 | 88 |
| 84 // FIXME: Not all TextCodec implementations handle |flush| - notably TextCod
ecUTF16 | 89 // FIXME: Not all TextCodec implementations handle |flush| - notably TextCod
ecUTF16 |
| 85 // ignores it and never flushes! | 90 // ignores it and never flushes! |
| 86 | 91 |
| 87 bool sawError = false; | 92 bool sawError = false; |
| 88 String s = m_codec->decode(start, length, flush, m_fatal, sawError); | 93 String s = m_codec->decode(start, length, flush, m_fatal, sawError); |
| 89 | 94 |
| 90 if (m_fatal && sawError) { | 95 if (m_fatal && sawError) { |
| 91 es.throwDOMException(EncodingError, "The encoded data was not valid."); | 96 es.throwDOMException(EncodingError, "The encoded data was not valid."); |
| 92 return String(); | 97 return String(); |
| 93 } | 98 } |
| 94 | 99 |
| 95 return s; | 100 return s; |
| 96 } | 101 } |
| 97 | 102 |
| 98 } // namespace WebCore | 103 } // namespace WebCore |
| OLD | NEW |