summaryrefslogtreecommitdiffstats
path: root/src/String.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/String.vala')
-rw-r--r--src/String.vala39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/String.vala b/src/String.vala
new file mode 100644
index 0000000..50563c2
--- /dev/null
+++ b/src/String.vala
@@ -0,0 +1,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;
+ }
+ }
+
+ public void encode(Erl.Buffer buffer) {
+ char[]? array = string_to_array(value);
+ if(array != null) {
+ buffer.encode_string(array);
+ }
+ else {
+ string_to_list(value).encode(buffer);
+ }
+ }
+ }
+}