Ejemplo n.º 1
0
        private static void TextUtilitiesExample()
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            List <char>   chars   = new List <char>();
            List <string> strings = new List <string>();

            for (int i = 0; i < 65536; ++i)
            {
                char c = Convert.ToChar(i);
                if (TextSupport.IsCharacterEntity(c))
                {
                    chars.Add(c);
                    strings.Add(TextSupport.PutCharacterEntity(c));
                }
            }
            Console.WriteLine(chars.Count + " total character entities:");
            string s = new string(chars.ToArray());
            int    j = 0;

            do
            {
                int l = Math.Min(20, s.Length - j);
                Console.WriteLine("\t" + s.Substring(j, l));
                j += 20;
            } while (j < s.Length);

            Console.WriteLine();
            for (int k = 0; k < chars.Count; ++k)
            {
                Console.WriteLine("\t" + chars[k] + " = " + strings[k]);
            }
        }
Ejemplo n.º 2
0
        public void PutCharEntitiesTest()
        {
            string s0 = "<a>";
            string s1 = "&lt;a&gt;";
            string s  = TextSupport.PutCharacterEntities(s0);

            Assert.Equal(s1, s);
        }
Ejemplo n.º 3
0
        /// <summary>Copies the contents of buffer into the termBuffer array.</summary>
        /// <param name="buffer">the buffer to copy
        /// </param>
        public void  SetTermBuffer(System.String buffer)
        {
            int length = buffer.Length;

            GrowTermBuffer(length);
            TextSupport.GetCharsFromString(buffer, 0, length, termBuffer, 0);
            termLength = length;
        }
Ejemplo n.º 4
0
 /// <summary>Copies the contents of buffer, starting at offset and continuing
 /// for length characters, into the termBuffer array.
 /// </summary>
 /// <param name="buffer">the buffer to copy
 /// </param>
 /// <param name="offset">the index in the buffer of the first character to copy
 /// </param>
 /// <param name="length">the number of characters to copy
 /// </param>
 public void  SetTermBuffer(System.String buffer, int offset, int length)
 {
     System.Diagnostics.Debug.Assert(offset <= buffer.Length);
     System.Diagnostics.Debug.Assert(offset + length <= buffer.Length);
     GrowTermBuffer(length);
     TextSupport.GetCharsFromString(buffer, offset, offset + length, termBuffer, 0);
     termLength = length;
 }
Ejemplo n.º 5
0
        public void PutHexCharText()
        {
            for (int i = 0; i < 16; ++i)
            {
                char c1 = TextSupport.PutHexChar(i);
                Assert.Equal(c1, hexChars[i]);
            }

            Assert.Equal('\0', TextSupport.PutHexChar(100));
        }
Ejemplo n.º 6
0
        public void GetHexValueText()
        {
            for (int i = 0; i < hexChars.Length; ++i)
            {
                int v1 = TextSupport.GetHexValue(hexChars[i]);
                Assert.Equal(v1, hexValues[i]);
            }

            Assert.Equal(0, TextSupport.GetHexValue('Q'));
        }
Ejemplo n.º 7
0
        public void PutTaggedBlockTest(string tag, string l0, string l1)
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                l1 = l1.Replace("\r\n", Environment.NewLine);
            }
            string l = TextSupport.PutTaggedBlock(tag, l0, 1);

            Assert.Equal(l1, l);
        }
Ejemplo n.º 8
0
 public void CharacterEntitiesTest()
 {
     for (int i = 0; i < characterEntities.Length; ++i)
     {
         char c0 = characterEntities[i];
         Assert.True(TextSupport.IsCharacterEntity(c0), String.Format("{0} ({1}) at index {2} is not a character entity.", c0, Convert.ToInt32(c0), i));
         string s0 = TextSupport.PutCharacterEntity(c0);
         Assert.NotEmpty(s0);
         char c1 = TextSupport.GetCharacterEntity(s0);
         Assert.Equal(c0, c1);
     }
 }
Ejemplo n.º 9
0
        public void GetWrappedTextTest(string s0, int scol, int ecol, string s1)
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                s1 = s1.Replace("\r\n", Environment.NewLine);
            }
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                s1 = s1.Replace("\r\n", Environment.NewLine);
            }
            string s = TextSupport.GetWrappedText(s0, scol, ecol);

            Assert.Equal(s1, s);
        }
Ejemplo n.º 10
0
        public void  Set(Term term)
        {
            if (term == null)
            {
                Reset();
                return;
            }
            System.String termText = term.Text;
            int           termLen  = termText.Length;

            text.SetLength(termLen);
            TextSupport.GetCharsFromString(termText, 0, termLen, text.result, 0);
            dirty     = true;
            field     = term.Field;
            this.term = term;
        }
Ejemplo n.º 11
0
        public static int ParseCharacter(string line, int i0, out char c, char dv = '\0')
        {
            int i = i0;

            if (!String.IsNullOrEmpty(line))
            {
                char c0 = line[i++];
                if (c0 != '\\')
                {
                    c = c0;
                    return(i);
                }

                if (i < line.Length)
                {
                    char c1 = line[i++];
                    if (c1 == 'u')
                    {
                        i += 4;
                    }
                    else if (c1 == 'x')
                    {
                        int j0 = i;
                        for (int j = j0; j < j0 + 4 && j < line.Length; j++)
                        {
                            if ("0123456789abcdefABCDEF".IndexOf(line[i]) < 0)
                            {
                                break;
                            }
                            i++;
                        }
                    }

                    c = TextSupport.GetEscapedCharacter(line.Substring(i0, i - i0));
                    return(i);
                }
            }

            c = '\0';
            return(i0);
        }
Ejemplo n.º 12
0
 public void GetTaggedBlockTest(string l0, string l1, bool useFile, bool throws)
 {
     if (useFile)
     {
         using (StreamReader r = File.OpenText(_fixture.TaggedBlockFilePath))
         {
             if (throws)
             {
                 Assert.Throws <ApplicationException>(() => TextSupport.GetTaggedBlock(l0, r));
             }
             else
             {
                 string l = TextSupport.GetTaggedBlock(l0, r);
                 Assert.Equal(l1, l);
             }
         }
     }
     else
     {
         string l = TextSupport.GetTaggedBlock(l0);
         Assert.Equal(l1, l);
     }
 }
Ejemplo n.º 13
0
 public override int Read(System.Char[] c, int off, int len)
 {
     if (left > len)
     {
         TextSupport.GetCharsFromString(s, upto, upto + len, c, off);
         upto += len;
         left -= len;
         return(len);
     }
     else if (0 == left)
     {
         // don't keep a reference (s could have been very large)
         s = null;
         return(0);
     }
     else
     {
         TextSupport.GetCharsFromString(s, upto, upto + left, c, off);
         int r = left;
         left = 0;
         upto = s.Length;
         return(r);
     }
 }
Ejemplo n.º 14
0
        public void RemoveCommentTest(string l0, char comment, bool allowInline, string l1)
        {
            string l = TextSupport.RemoveComment(l0, comment, allowInline);

            Assert.Equal(l1, l);
        }
Ejemplo n.º 15
0
        public void UnquoteTest(string s0, char q, TextSupport.QuoteOptions q0, string s1)
        {
            string s = TextSupport.Unquote(s0, q, q0);

            Assert.Equal(s1, s);
        }
Ejemplo n.º 16
0
        public void DetabTest(string s0, int tabSize, string s1)
        {
            string s = TextSupport.Detab(s0, tabSize);

            Assert.Equal(s1, s);
        }
Ejemplo n.º 17
0
        public void GetColumnFromOffsetTest(string l0, int o0, int tabSize, int c1)
        {
            int c = TextSupport.GetColumnFromOffset(l0, o0, tabSize);

            Assert.Equal(c1, c);
        }
Ejemplo n.º 18
0
        public void GetOffsetFromColumnTest(string l0, int c0, int tabSize, int o1)
        {
            int c = TextSupport.GetOffsetFromColumn(l0, c0, tabSize);

            Assert.Equal(o1, c);
        }
Ejemplo n.º 19
0
        public void EvaluateCharacterEntitiesTest(string l0, string l1)
        {
            string l = TextSupport.EvaluateCharacterEntities(l0);

            Assert.Equal(l1, l);
        }