Exemplo n.º 1
0
        public static int StringWidth(ref string text)
        {
            int size = 1;

            for (int i = 0; i < text.Length; i++)
            {
                try
                {
                    if (CharLibrary[(int)text[i]] < 1)
                    {
                        text = text.Remove(i, 1);
                        text = text.Insert(i, ConstChar.ToString());
                    }
                }
                catch
                {
                    text = text.Remove(i, 1);
                    text = text.Insert(i, ConstChar.ToString());
                }

                size += CharLibrary[(int)text[i]];
            }

            return(size);
        }
Exemplo n.º 2
0
        public void LCCTCConstCharIllegalMultiChar2()
        {
            string src = "L'\\0223'";
            var    ast = new ConstChar(new T_CONST_CHAR(1, src));

            ast.ToASTExpr(new lcc.SyntaxTree.Env());
        }
Exemplo n.º 3
0
 public void LCCTCConstCharIllegal2()
 {
     string src    = "\\777";
     var    values = ConstChar.Evaluate(new Position(1), src);
 }
Exemplo n.º 4
0
        public void LCCTCConstCharEvaluateLegal()
        {
            var tests = new Dictionary <string, LinkedList <ushort> > {
                {
                    "f",
                    new LinkedList <ushort>(new List <ushort> {
                        'f'
                    })
                },
                {
                    "\\n",
                    new LinkedList <ushort>(new List <ushort> {
                        '\n'
                    })
                },
                {
                    "\\'",
                    new LinkedList <ushort>(new List <ushort> {
                        '\''
                    })
                },
                {
                    "\\c",
                    new LinkedList <ushort>(new List <ushort> {
                        'c'
                    })
                },
                {
                    "\\377",
                    new LinkedList <ushort>(new List <ushort> {
                        255
                    })
                },
                {
                    "\\xff",
                    new LinkedList <ushort>(new List <ushort> {
                        255
                    })
                },
                {
                    "\\7",
                    new LinkedList <ushort>(new List <ushort> {
                        7
                    })
                },
                {
                    "\\76",
                    new LinkedList <ushort>(new List <ushort> {
                        7 * 8 + 6
                    })
                },
                {
                    "\\0223",
                    new LinkedList <ushort>(new List <ushort> {
                        0x12, '3'
                    })
                },
                {
                    "abcd",
                    new LinkedList <ushort>(new List <ushort> {
                        'a', 'b', 'c', 'd'
                    })
                }
            };

            foreach (var test in tests)
            {
                var values = ConstChar.Evaluate(new Position(1), test.Key);
                Assert.IsTrue(values.SequenceEqual(test.Value));
            }
        }