예제 #1
0
        static string Render(Term t)
        {
            StringBuilder txt = new StringBuilder();

            // leave off seperator

            if (t.Type == TermType.Function)
            {
                txt.AppendFormat("<span class=\"value_function function\">{0}</span>", Render(t.Function));
            }
            else if (t.Type == TermType.Url)
            {
                txt.AppendFormat("<span class=\"value_url\">url('{0}')</span>", t.Value);
            }
            else if (t.Type == TermType.Unicode)
            {
                txt.AppendFormat("<span class=\"value_unicode\">U\\{0}</span>", t.Value.ToUpper());
            }
            else if (t.Type == TermType.Hex)
            {
                txt.AppendFormat("<span class=\"value_hex{1}\">{0}</span>", t.Value.ToUpper(), t.IsColor ? " value_color" : "");
            }
            else
            {
                if (t.Type == TermType.Number)
                {
                    txt.Append("<span class=\"value_number\">");
                }
                else
                {
                    txt.AppendFormat("<span class=\"value_string{0}\">", t.IsColor ? " value_color" : "");
                }
                if (t.Sign.HasValue)
                {
                    txt.AppendFormat("<span class=\"values_sign\">{0}</span>", t.Sign.Value);
                }
                txt.Append(t.Value);
                if (t.Unit.HasValue)
                {
                    txt.Append("<span class=\"values_unit\">");
                    if (t.Unit.Value == ActiveWare.CSS.Unit.Percent)
                    {
                        txt.Append("%");
                    }
                    else
                    {
                        txt.Append(UnitOutput.ToString(t.Unit.Value));
                    }
                    txt.Append("</span>");
                }
                txt.Append("</span>");
            }

            return(txt.ToString());
        }
예제 #2
0
        /// <summary></summary>
        /// <returns></returns>
        public override string ToString()
        {
            /*
             * term<out Term trm> =			(. trm = new Term();
             *                                              string val = "";
             *                                              Function func = null;
             *                                      .)
             * [ ('-'						(. trm.Sign = '-'; .)
             | '+'						(. trm.Sign = '+'; .)
             | ) ]
             | (
             | { digit					(. val += t.val; .)
             | }
             | [ (
             | "%"					(. trm.Unit = Unit.Percent; .)
             | "ex"				(. trm.Unit = Unit.EX; .)
             | "em"				(. trm.Unit = Unit.EM; .)
             | "px"				(. trm.Unit = Unit.PX; .)
             | "cm"				(. trm.Unit = Unit.CM; .)
             | "mm"				(. trm.Unit = Unit.MM; .)
             | "pc"				(. trm.Unit = Unit.PC; .)
             | "in"				(. trm.Unit = Unit.IN; .)
             | "pt"				(. trm.Unit = Unit.PT; .)
             | "deg"				(. trm.Unit = Unit.DEG; .)
             | ["g"				(. trm.Unit = Unit.GRAD; .)
             | ] "rad"				(. if (trm.Unit != Unit.GRAD) { trm.Unit = Unit.RAD; } .)
             | ["m"				(. trm.Unit = Unit.MS; .)
             | ] "s"				(. if (trm.Unit != Unit.MS) { trm.Unit = Unit.S; } .)
             | ["k"				(. trm.Unit = Unit.KHZ; .)
             | ] "hz"				(. if (trm.Unit != Unit.KHZ) { trm.Unit = Unit.HZ; } .)
             | ) ]						(. trm.Value = val; trm.Type = TermType.Number; .)
             |
             | function<out func>		(. trm.Function = func; trm.Type = TermType.Function; .)
             |
             | QuotedString<out val>	(. trm.Value = val; trm.Type = TermType.String; .)
             |
             | ident					(. trm.Value = t.val; trm.Type = TermType.String; .)
             |
             | URI<out val>			(. trm.Value = val; trm.Type = TermType.Url; .)
             |
             | "U\\"
             | { (digit|'A'|'B'|'C'|'D'|'E'|'F'|'a'|'b'|'c'|'d'|'e'|'f')
             |                                      (. val += t.val; .)
             | }						(. trm.Value = val; trm.Type = TermType.Unicode; .)
             |
             | hexdigit				(. trm.Value = t.val; trm.Type = TermType.Hex; .)
             | )
             | .
             */
            System.Text.StringBuilder txt = new System.Text.StringBuilder();
            //if (seperator.HasValue) { txt.Append(seperator.Value); txt.Append(" "); }

            if (type == TermType.Function)
            {
                txt.Append(function.ToString());
            }
            else if (type == TermType.Url)
            {
                txt.AppendFormat("url('{0}')", val);
            }
            else if (type == TermType.Unicode)
            {
                txt.AppendFormat("U\\{0}", val.ToUpper());
            }
            else if (type == TermType.Hex)
            {
                txt.Append(val.ToUpper());
            }
            else
            {
                if (sign.HasValue)
                {
                    txt.Append(sign.Value);
                }
                txt.Append(val);
                if (unit.HasValue)
                {
                    if (unit.Value == ActiveWare.CSS.Unit.Percent)
                    {
                        txt.Append("%");
                    }
                    else
                    {
                        txt.Append(UnitOutput.ToString(unit.Value));
                    }
                }
            }

            return(txt.ToString());
        }