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

Side by Side Diff: third_party/WebKit/Source/wtf/text/TextEncoding.cpp

Issue 1407663004: Tweaking WebPageSerializerImpl to emit a BOM for UTF16/32. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Saving UTF16 with BOM. Leaving UTF32 in a broken state. Created 5 years 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2006 Alexey Proskuryakov <ap@nypop.com> 3 * Copyright (C) 2006 Alexey Proskuryakov <ap@nypop.com>
4 * Copyright (C) 2007-2009 Torch Mobile, Inc. 4 * Copyright (C) 2007-2009 Torch Mobile, Inc.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 OwnPtr<TextCodec> textCodec = newTextCodec(*this); 78 OwnPtr<TextCodec> textCodec = newTextCodec(*this);
79 CString encodedString; 79 CString encodedString;
80 if (string.is8Bit()) 80 if (string.is8Bit())
81 encodedString = textCodec->encode(string.characters8(), string.length(), handling); 81 encodedString = textCodec->encode(string.characters8(), string.length(), handling);
82 else 82 else
83 encodedString = textCodec->encode(string.characters16(), string.length() , handling); 83 encodedString = textCodec->encode(string.characters16(), string.length() , handling);
84 return encodedString; 84 return encodedString;
85 } 85 }
86 86
87 CString TextEncoding::encodeBOMifApplicable() const
88 {
89 // TODO(lukasza): Store |textCodec| in a member field, so it can be reused
90 // across repeated calls to encode and/or encodeBOMifApplicable.
jsbell 2015/12/07 22:53:51 That would change the behavior for stateful encodi
91 OwnPtr<TextCodec> textCodec = newTextCodec(*this);
92 if (!textCodec->shouldIncludeBOM())
93 return "";
94
95 const UChar bomCharacter = 0xFEFF;
96 return textCodec->encode(&bomCharacter, 1, QuestionMarksForUnencodables);
97 }
98
87 bool TextEncoding::usesVisualOrdering() const 99 bool TextEncoding::usesVisualOrdering() const
88 { 100 {
89 if (noExtendedTextEncodingNameUsed()) 101 if (noExtendedTextEncodingNameUsed())
90 return false; 102 return false;
91 103
92 static const char* const a = atomicCanonicalTextEncodingName("ISO-8859-8"); 104 static const char* const a = atomicCanonicalTextEncodingName("ISO-8859-8");
93 return m_name == a; 105 return m_name == a;
94 } 106 }
95 107
96 bool TextEncoding::isNonByteBasedEncoding() const 108 bool TextEncoding::isNonByteBasedEncoding() const
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 return globalUTF8Encoding; 188 return globalUTF8Encoding;
177 } 189 }
178 190
179 const TextEncoding& WindowsLatin1Encoding() 191 const TextEncoding& WindowsLatin1Encoding()
180 { 192 {
181 AtomicallyInitializedStaticReference(const TextEncoding, globalWindowsLatin1 Encoding, new TextEncoding("WinLatin1")); 193 AtomicallyInitializedStaticReference(const TextEncoding, globalWindowsLatin1 Encoding, new TextEncoding("WinLatin1"));
182 return globalWindowsLatin1Encoding; 194 return globalWindowsLatin1Encoding;
183 } 195 }
184 196
185 } // namespace WTF 197 } // namespace WTF
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698