Ejemplo n.º 1
0
    public CartoElement(Combinator combinator, Node value)
      : base(combinator, value)
    {
      string strValue = value.ToString().Trim();

      if (string.IsNullOrEmpty(strValue))
      {
        m_type = ElementType.Unknown;
        if (strValue != null)
          Value = "\"\"";
      }
      else if (strValue[0] == '#')
      {
        Value = strValue.Remove(0, 1);
        m_type = ElementType.Id;
      }
      else if (strValue[0] == '.')
      {
        Value = strValue.Remove(0, 1);
        m_type = ElementType.Class;
      }
      else if (strValue.Contains('*'))
      {
        m_type = ElementType.Wildchar;
      }
    }
    public CartoFilterElement(Node key, Node op, Node value, Combinator combinator, Env env)
      : base(combinator, value)
    {
      m_key = key;
      m_op = op;
      m_value = value;

      m_id = "[" + m_key.ToString() + "]" + m_op.ToString() + m_value.ToCSS(env).ToString();
    }
    private static string ToExpressionOperator(Node op)
    {
      string strOp = op.ToString();

      switch (strOp)
      {
        case "=":
          return "=";
        case "!=":
          return "!=";
        case ">=":
          return ">=";
        case "<=":
          return "<=";
        case ">":
          return ">";
        case "<":
          return "<";
        default:
          return strOp;
      }
    }
    private static string ToExpressionValue(Node value)
    {
      string result = null;

      Number num = value as Number;
      if (num != null)
        result = num.Value.ToString();
      else
      {
        Quoted quoted = value as Quoted;
        if (quoted != null)
          result = QuoteValue(quoted.Value.ToString());
        else
          result = value.ToString();
      }

      return result;
    }