summaryrefslogtreecommitdiffstats
path: root/src/String.vala
blob: 2bee7dc025e33a3cfae0371cc4c86285b85193ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
namespace Eva {
  public class String : Object, Term {
    public string value {get; construct;}
    
    public String(string v) {
      Object(value: v);
    }
    
    public string to_string() {
      return "\"" + value.replace("\\", "\\\\").replace("\"", "\\\"") + "\"";
    }
    
    protected bool do_match(Term o, Gee.Map<string, Term> vars, Gee.Map<string, string> aliases) {
      if(o is Var) {
        return o.do_match(this, vars, aliases);
      }
      
      if(o is String) {
        return (value == (o as String).value);
      }
      else if(o is List) {
        return o.do_match(this, vars, aliases);
      }
      else {
        return false;
      }
    }
    
    internal void encode(Buffer buffer) {
      char[]? array = string_to_binary(value);
      if(array != null) {
        buffer.buffer.encode_string(array);
      }
      else {
        string_to_list(value).encode(buffer);
      }
    }
  }
}