Ejemplo n.º 1
0
        private void DoText(string text)
        {
            var  list = new List <Unicode.Summary>(text.Length);
            bool after_high_surrogate = false;

            foreach (var c in text)
            {
                if (IsCancelled())
                {
                    return;
                }
                int code = c;

                if (after_high_surrogate && Unicode.IsLowSurrogate(code))
                {
                    var high = list[list.Count - 1];
                    code = Unicode.DecodeSurrogatePair((int)high.Code, code);
                    list[list.Count - 1] = Unicode.GetSummary(code);
                }
                else
                {
                    list.Add(Unicode.GetSummary(c));
                }

                after_high_surrogate = Unicode.IsHighSurroate(code);
            }

            OnUpdated(list.ToArray());
        }
Ejemplo n.º 2
0
        private void DoCode(string text)
        {
            var  list = new List <Unicode.Summary>(text.Length);
            bool after_high_surrogate = false;

            var a = text
                    .Replace(";", "; ").Replace("\\", " \\").Replace("&#", " &#")
                    .Split((char[])null, StringSplitOptions.RemoveEmptyEntries);

            foreach (var s in a)
            {
                if (IsCancelled())
                {
                    return;
                }
                int code = ParseCodepointNotation(s);

                if (after_high_surrogate && Unicode.IsLowSurrogate(code) && !s.StartsWith("&#"))
                {
                    var high = list[list.Count - 1] as UnicodeSummaryEx;
                    code = Unicode.DecodeSurrogatePair((int)high.Code, code);
                    list[list.Count - 1] = new UnicodeSummaryEx(Unicode.GetSummary(code), high.Orig + " " + s);
                }
                else
                {
                    list.Add(new UnicodeSummaryEx(Unicode.GetSummary(code), s));
                }

                after_high_surrogate = Unicode.IsHighSurroate(code) && !s.StartsWith("&#");
            }
            OnUpdated(list.ToArray());
        }
Ejemplo n.º 3
0
        public void DecodeSurrogatePair()
        {
            uint codepoint;

            Assert.False(Unicode.DecodeSurrogatePair('\0', '\0', out codepoint));
            Assert.AreEqual(0, codepoint);
            Assert.False(Unicode.DecodeSurrogatePair('a', '\0', out codepoint));
            Assert.AreEqual((uint)'a', codepoint);
            Assert.False(Unicode.DecodeSurrogatePair('a', 'b', out codepoint));
            Assert.AreEqual((uint)'a', codepoint);
            Assert.True(Unicode.DecodeSurrogatePair("\U0002F8B6"[0], "\U0002F8B6"[1], out codepoint));
            Assert.AreEqual((uint)0x2F8B6, codepoint);
            Assert.False(Unicode.DecodeSurrogatePair("\U0002F8B6"[0], '\0', out codepoint));
            Assert.AreEqual(0xFFFD, codepoint);
        }