| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved. |
| 3 * Copyright (C) 2006 Alexey Proskuryakov <ap@nypop.com> | 3 * Copyright (C) 2006 Alexey Proskuryakov <ap@nypop.com> |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "wtf/text/Unicode.h" | 33 #include "wtf/text/Unicode.h" |
| 34 #include "wtf/text/WTFString.h" | 34 #include "wtf/text/WTFString.h" |
| 35 | 35 |
| 36 namespace WTF { | 36 namespace WTF { |
| 37 | 37 |
| 38 class TextEncoding; | 38 class TextEncoding; |
| 39 | 39 |
| 40 // Specifies what will happen when a character is encountered that is | 40 // Specifies what will happen when a character is encountered that is |
| 41 // not encodable in the character set. | 41 // not encodable in the character set. |
| 42 enum UnencodableHandling { | 42 enum UnencodableHandling { |
| 43 // Substitutes the replacement character "?". | 43 // Substitutes the replacement character "?". |
| 44 QuestionMarksForUnencodables, | 44 QuestionMarksForUnencodables, |
| 45 | 45 |
| 46 // Encodes the character as an XML entity. For example, U+06DE | 46 // Encodes the character as an XML entity. For example, U+06DE |
| 47 // would be "۞" (0x6DE = 1758 in octal). | 47 // would be "۞" (0x6DE = 1758 in octal). |
| 48 EntitiesForUnencodables, | 48 EntitiesForUnencodables, |
| 49 | 49 |
| 50 // Encodes the character as en entity as above, but escaped | 50 // Encodes the character as en entity as above, but escaped |
| 51 // non-alphanumeric characters. This is used in URLs. | 51 // non-alphanumeric characters. This is used in URLs. |
| 52 // For example, U+6DE would be "%26%231758%3B". | 52 // For example, U+6DE would be "%26%231758%3B". |
| 53 URLEncodedEntitiesForUnencodables | 53 URLEncodedEntitiesForUnencodables |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 typedef char UnencodableReplacementArray[32]; | 56 typedef char UnencodableReplacementArray[32]; |
| 57 | 57 |
| 58 enum FlushBehavior { | 58 enum FlushBehavior { |
| 59 // More bytes are coming, don't flush the codec. | 59 // More bytes are coming, don't flush the codec. |
| 60 DoNotFlush = 0, | 60 DoNotFlush = 0, |
| 61 | 61 |
| 62 // A fetch has hit EOF. Some codecs handle fetches differently, for compat r
easons. | 62 // A fetch has hit EOF. Some codecs handle fetches differently, for compat rea
sons. |
| 63 FetchEOF, | 63 FetchEOF, |
| 64 | 64 |
| 65 // Do a full flush of the codec. | 65 // Do a full flush of the codec. |
| 66 DataEOF | 66 DataEOF |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 static_assert(!DoNotFlush, "DoNotFlush should be falsy"); | 69 static_assert(!DoNotFlush, "DoNotFlush should be falsy"); |
| 70 static_assert(FetchEOF, "FetchEOF should be truthy"); | 70 static_assert(FetchEOF, "FetchEOF should be truthy"); |
| 71 static_assert(DataEOF, "DataEOF should be truthy"); | 71 static_assert(DataEOF, "DataEOF should be truthy"); |
| 72 | 72 |
| 73 class TextCodec { |
| 74 WTF_MAKE_NONCOPYABLE(TextCodec); |
| 75 USING_FAST_MALLOC(TextCodec); |
| 73 | 76 |
| 74 class TextCodec { | 77 public: |
| 75 WTF_MAKE_NONCOPYABLE(TextCodec); USING_FAST_MALLOC(TextCodec); | 78 TextCodec() {} |
| 76 public: | 79 virtual ~TextCodec(); |
| 77 TextCodec() { } | |
| 78 virtual ~TextCodec(); | |
| 79 | 80 |
| 80 String decode(const char* str, size_t length, FlushBehavior flush = DoNotFlu
sh) | 81 String decode(const char* str, |
| 81 { | 82 size_t length, |
| 82 bool ignored; | 83 FlushBehavior flush = DoNotFlush) { |
| 83 return decode(str, length, flush, false, ignored); | 84 bool ignored; |
| 84 } | 85 return decode(str, length, flush, false, ignored); |
| 86 } |
| 85 | 87 |
| 86 virtual String decode(const char*, size_t length, FlushBehavior, bool stopOn
Error, bool& sawError) = 0; | 88 virtual String decode(const char*, |
| 87 virtual CString encode(const UChar*, size_t length, UnencodableHandling) = 0
; | 89 size_t length, |
| 88 virtual CString encode(const LChar*, size_t length, UnencodableHandling) = 0
; | 90 FlushBehavior, |
| 91 bool stopOnError, |
| 92 bool& sawError) = 0; |
| 93 virtual CString encode(const UChar*, size_t length, UnencodableHandling) = 0; |
| 94 virtual CString encode(const LChar*, size_t length, UnencodableHandling) = 0; |
| 89 | 95 |
| 90 // Fills a null-terminated string representation of the given | 96 // Fills a null-terminated string representation of the given |
| 91 // unencodable character into the given replacement buffer. | 97 // unencodable character into the given replacement buffer. |
| 92 // The length of the string (not including the null) will be returned. | 98 // The length of the string (not including the null) will be returned. |
| 93 static int getUnencodableReplacement(unsigned codePoint, UnencodableHandling
, UnencodableReplacementArray); | 99 static int getUnencodableReplacement(unsigned codePoint, |
| 100 UnencodableHandling, |
| 101 UnencodableReplacementArray); |
| 94 }; | 102 }; |
| 95 | 103 |
| 96 typedef void (*EncodingNameRegistrar)(const char* alias, const char* name); | 104 typedef void (*EncodingNameRegistrar)(const char* alias, const char* name); |
| 97 | 105 |
| 98 typedef PassOwnPtr<TextCodec> (*NewTextCodecFunction)(const TextEncoding&, const
void* additionalData); | 106 typedef PassOwnPtr<TextCodec> ( |
| 99 typedef void (*TextCodecRegistrar)(const char* name, NewTextCodecFunction, const
void* additionalData); | 107 *NewTextCodecFunction)(const TextEncoding&, const void* additionalData); |
| 108 typedef void (*TextCodecRegistrar)(const char* name, |
| 109 NewTextCodecFunction, |
| 110 const void* additionalData); |
| 100 | 111 |
| 101 } // namespace WTF | 112 } // namespace WTF |
| 102 | 113 |
| 103 using WTF::TextCodec; | 114 using WTF::TextCodec; |
| 104 | 115 |
| 105 #endif // TextCodec_h | 116 #endif // TextCodec_h |
| OLD | NEW |