utf-16

Why must I specify charset attributes for by <script> tags?

。_饼干妹妹 提交于 2019-12-01 13:48:40
I have a bit of an odd situation: Main HTML page is served in UTF-16 character set (due to some requirements out-of-scope for this question) HTML page uses <script> tags to load external scripts (i.e. they have src attributes) Those external scripts are in US-ASCII/UTF-8 The web server is serving the scripts with the content-type "application/javascript" with no character set hints The scripts have no byte-order-mark (BOM) When loading the page described above, both Firefox and Chrome (current versions) throw errors saying that the first character of the script files are invalid. Looking at

Can't get git to play nice with iconv and utf-16

为君一笑 提交于 2019-12-01 13:07:54
I'm trying to get git to recognize UTF-16 as text to allow me to diff and patch as text natively, but I'm having trouble getting the textconv parameter to work. I can manually call iconv -f utf-16 -t utf-8 some-utf-16-file.rc and everything is fine. But if I configure my .gitconfig as follows [diff "utf16"] textconv = "iconv -f utf-16le -t utf-8" and my .gitattributes: # Custom for MFC *.rc text eol=crlf diff=utf16 However, if I then if I run git diff , the following is displayed: iconv: C:/Users/Mahmoud/AppData/Local/Temp/IjLBZ8_OemKey.rc:104:1: incomplete character or shift sequence With

Converting from utf-16 to utf-8 in Python 3

我是研究僧i 提交于 2019-12-01 12:30:35
I'm programming in Python 3 and I'm having a small problem which I can't find any reference to it on the net. As far as I understand the default string in is utf-16, but I must work with utf-8, I can't find the command that will convert from the default one to utf-8. I'd appreciate your help very much. In Python 3 there are two different datatypes important when you are working with string manipulation. First there is the string class, an object that represents unicode code points. Important to get is that this string is not some bytes, but really a sequence of characters. Secondly, there is

Is UTF-16 compatible with UTF-8?

一曲冷凌霜 提交于 2019-12-01 11:41:34
问题 I asked Google the question above and was sent to Difference between UTF-8 and UTF-16? which unfortunately doesn't answer the question. From my understanding UTF-8 should be a subset of UTF-16 meaning: if my code uses UTF-16 and I hand in a UTF-8 encoded string everything should always be fine. The other way around (expecting UTF-8 and getting UTF-16) may cause problems. Is that correct? EDIT: To clarify why the linked SO question doesn't answer my question: My problem arose when trying to

PHP - UTF-16 to UTF-8(hex) conversion

て烟熏妆下的殇ゞ 提交于 2019-12-01 11:41:25
问题 Is it possible to convert UTF-16 U+610F style character to UTF-8 (hex) E6848F using PHP ? UTF-8 character is '意' 回答1: From the comments in the chr man page, one quick hack for turning an ordinal character number into a UTF-8 byte sequence: function unichr($u) { return mb_convert_encoding('&#' . intval($u) . ';', 'UTF-8', 'HTML-ENTITIES'); } // unichr(0x610F) -> "\xE6\x84\x8F" 回答2: php have unicode encoding and decoding.. let u try on that utf8_decode(); or utf8_encode(); 来源: https:/

Can't get git to play nice with iconv and utf-16

牧云@^-^@ 提交于 2019-12-01 10:58:16
问题 I'm trying to get git to recognize UTF-16 as text to allow me to diff and patch as text natively, but I'm having trouble getting the textconv parameter to work. I can manually call iconv -f utf-16 -t utf-8 some-utf-16-file.rc and everything is fine. But if I configure my .gitconfig as follows [diff "utf16"] textconv = "iconv -f utf-16le -t utf-8" and my .gitattributes: # Custom for MFC *.rc text eol=crlf diff=utf16 However, if I then if I run git diff , the following is displayed: iconv: C:

How to reverse a string that contains surrogate pairs

泪湿孤枕 提交于 2019-12-01 07:31:18
I have written this method to reverse a string public string Reverse(string s) { if(string.IsNullOrEmpty(s)) return s; TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator(s); var elements = new List<char>(); while (enumerator.MoveNext()) { var cs = enumerator.GetTextElement().ToCharArray(); if (cs.Length > 1) { elements.AddRange(cs.Reverse()); } else { elements.AddRange(cs); } } elements.Reverse(); return string.Concat(elements); } Now, I don't want to start a discussion about how this code could be made more efficient or how there are one liners that I could use instead. I

How to convert Rust strings to UTF-16?

独自空忆成欢 提交于 2019-12-01 05:54:09
Editor's note: This code example is from a version of Rust prior to 1.0 and is not valid Rust 1.0 code, but the answers still contain valuable information. I want to pass a string literal to a Windows API. Many Windows functions use UTF-16 as the string encoding while Rust's native strings are UTF-8. I know Rust has utf16_units() to produce a UTF-16 character iterator, but I don't know how to use that function to produce a UTF-16 string with zero as last character. I'm producing the UTF-16 string like this, but I am sure there is a better method to produce it: extern "system" { pub fn

What could go wrong in switching HTML encoding from UTF-8 to UTF-16?

拜拜、爱过 提交于 2019-12-01 05:25:51
What are the implications of a change from UTF-8 to UTF-16 for HTML encoding? I would like to know your thoughts on the issue. Are there things I need to think of before making such a change? Note: Interested due to enormous amounts of japanese and chinese text I need to handle. I can think of a few things that will go wrong: You MUST specify that it's UTF-16 in the HTTP header. Unlike UTF-8, UTF-16 is not ASCII compatible, which means that everything needs to be in UTF-16 from the start. Older clients don't support UTF-16. For example, anything on Windows 9x. Possibly Mac OS9 as well. Oh,

What could go wrong in switching HTML encoding from UTF-8 to UTF-16?

旧城冷巷雨未停 提交于 2019-12-01 04:36:41
问题 What are the implications of a change from UTF-8 to UTF-16 for HTML encoding? I would like to know your thoughts on the issue. Are there things I need to think of before making such a change? Note: Interested due to enormous amounts of japanese and chinese text I need to handle. 回答1: I can think of a few things that will go wrong: You MUST specify that it's UTF-16 in the HTTP header. Unlike UTF-8, UTF-16 is not ASCII compatible, which means that everything needs to be in UTF-16 from the start