Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Side by Side Diff: Source/wtf/text/TextCodec.h

Issue 23532016: Handle odd data lengths in UTF-16 decoder (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Simplify Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/modules/encoding/TextDecoder.cpp ('k') | Source/wtf/text/TextCodecICU.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 EntitiesForUnencodables, 49 EntitiesForUnencodables,
50 50
51 // Encodes the character as en entity as above, but escaped 51 // Encodes the character as en entity as above, but escaped
52 // non-alphanumeric characters. This is used in URLs. 52 // non-alphanumeric characters. This is used in URLs.
53 // For example, U+6DE would be "%26%231758%3B". 53 // For example, U+6DE would be "%26%231758%3B".
54 URLEncodedEntitiesForUnencodables 54 URLEncodedEntitiesForUnencodables
55 }; 55 };
56 56
57 typedef char UnencodableReplacementArray[32]; 57 typedef char UnencodableReplacementArray[32];
58 58
59 enum FlushBehavior {
60 // More bytes are coming, don't flush the codec.
61 DoNotFlush = 0,
62
63 // A fetch has hit EOF. Some codecs handle fetches differently, for compat r easons.
64 FetchEOF,
65
66 // Do a full flush of the codec.
67 DataEOF
68 };
69
70 COMPILE_ASSERT(!DoNotFlush, DoNotFlush_is_falsy);
71 COMPILE_ASSERT(FetchEOF, FetchEOF_is_truthy);
72 COMPILE_ASSERT(DataEOF, DataEOF_is_truthy);
73
74
59 class TextCodec { 75 class TextCodec {
60 WTF_MAKE_NONCOPYABLE(TextCodec); WTF_MAKE_FAST_ALLOCATED; 76 WTF_MAKE_NONCOPYABLE(TextCodec); WTF_MAKE_FAST_ALLOCATED;
61 public: 77 public:
62 TextCodec() { } 78 TextCodec() { }
63 virtual ~TextCodec(); 79 virtual ~TextCodec();
64 80
65 String decode(const char* str, size_t length, bool flush = false) 81 String decode(const char* str, size_t length, FlushBehavior flush = DoNotFlu sh)
66 { 82 {
67 bool ignored; 83 bool ignored;
68 return decode(str, length, flush, false, ignored); 84 return decode(str, length, flush, false, ignored);
69 } 85 }
70 86
71 virtual String decode(const char*, size_t length, bool flush, bool stopOnErr or, bool& sawError) = 0; 87 virtual String decode(const char*, size_t length, FlushBehavior, bool stopOn Error, bool& sawError) = 0;
72 virtual CString encode(const UChar*, size_t length, UnencodableHandling) = 0 ; 88 virtual CString encode(const UChar*, size_t length, UnencodableHandling) = 0 ;
73 virtual CString encode(const LChar*, size_t length, UnencodableHandling) = 0 ; 89 virtual CString encode(const LChar*, size_t length, UnencodableHandling) = 0 ;
74 90
75 // Fills a null-terminated string representation of the given 91 // Fills a null-terminated string representation of the given
76 // unencodable character into the given replacement buffer. 92 // unencodable character into the given replacement buffer.
77 // The length of the string (not including the null) will be returned. 93 // The length of the string (not including the null) will be returned.
78 static int getUnencodableReplacement(unsigned codePoint, UnencodableHandling , UnencodableReplacementArray); 94 static int getUnencodableReplacement(unsigned codePoint, UnencodableHandling , UnencodableReplacementArray);
79 }; 95 };
80 96
81 typedef void (*EncodingNameRegistrar)(const char* alias, const char* name); 97 typedef void (*EncodingNameRegistrar)(const char* alias, const char* name);
82 98
83 typedef PassOwnPtr<TextCodec> (*NewTextCodecFunction)(const TextEncoding&, const void* additionalData); 99 typedef PassOwnPtr<TextCodec> (*NewTextCodecFunction)(const TextEncoding&, const void* additionalData);
84 typedef void (*TextCodecRegistrar)(const char* name, NewTextCodecFunction, const void* additionalData); 100 typedef void (*TextCodecRegistrar)(const char* name, NewTextCodecFunction, const void* additionalData);
85 101
86 } // namespace WTF 102 } // namespace WTF
87 103
88 using WTF::TextCodec; 104 using WTF::TextCodec;
89 105
90 #endif // TextCodec_h 106 #endif // TextCodec_h
OLDNEW
« no previous file with comments | « Source/modules/encoding/TextDecoder.cpp ('k') | Source/wtf/text/TextCodecICU.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698