aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
Diffstat (limited to 'e-util')
-rw-r--r--e-util/ChangeLog6
-rw-r--r--e-util/e-sexp.c42
-rw-r--r--e-util/e-sexp.h4
3 files changed, 52 insertions, 0 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index 29aace5994..ba3c5d6a1e 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,9 @@
+2000-05-30 Not Zed <NotZed@HelixCode.com>
+
+ * e-sexp.c (e_sexp_encode_bool): Utility function to build a bool
+ as part of an expression string.
+ (e_sexp_encode_string): Likewise for strings.
+
2000-05-30 Christopher James Lahey <clahey@helixcode.com>
* e-canvas-utils.c, e-canvas-utils.h: Added
diff --git a/e-util/e-sexp.c b/e-util/e-sexp.c
index 7d7b5f5f0f..22727f22c2 100644
--- a/e-util/e-sexp.c
+++ b/e-util/e-sexp.c
@@ -1089,6 +1089,48 @@ e_sexp_eval(ESExp *f)
return e_sexp_term_eval(f, f->tree);
}
+/**
+ * e_sexp_encode_bool:
+ * @s:
+ * @state:
+ *
+ * Encode a bool into an s-expression @s. Bools are
+ * encoded using #t #f syntax.
+ **/
+void
+e_sexp_encode_bool(GString *s, gboolean state)
+{
+ if (state)
+ g_string_append(s, " #t");
+ else
+ g_string_append(s, " #f");
+}
+
+/**
+ * e_sexp_encode_string:
+ * @s: Destination string.
+ * @string: String expression.
+ *
+ * Add a c string @string to the s-expression stored in
+ * the gstring @s. Quotes are added, and special characters
+ * are escaped appropriately.
+ **/
+void
+e_sexp_encode_string(GString *s, const char *string)
+{
+ char c;
+ const char *p;
+
+ p = string;
+ g_string_append(s, " \"");
+ while ( (c = *p++) ) {
+ if (c=='\\' || c=='\"' || c=='\'')
+ g_string_append_c(s, '\\');
+ g_string_append_c(s, c);
+ }
+ g_string_append(s, "\"");
+}
+
#ifdef TESTER
int main(int argc, char **argv)
{
diff --git a/e-util/e-sexp.h b/e-util/e-sexp.h
index 885a2369b9..1030531133 100644
--- a/e-util/e-sexp.h
+++ b/e-util/e-sexp.h
@@ -112,4 +112,8 @@ ESExpResult *e_sexp_term_eval (struct _ESExp *f, struct _ESExpTerm *t);
ESExpResult *e_sexp_result_new (int type);
void e_sexp_result_free (struct _ESExpResult *t);
+/* utility functions for creating s-exp strings. */
+void e_sexp_encode_bool(GString *s, gboolean state);
+void e_sexp_encode_string(GString *s, const char *string);
+
#endif /* _E_SEXP_H */