aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNot Zed <NotZed@HelixCode.com>2000-05-31 06:53:59 +0800
committerMichael Zucci <zucchi@src.gnome.org>2000-05-31 06:53:59 +0800
commit75353e0bff2661faf013f87aed65fbc58bb0ab68 (patch)
tree7c7c85ad7dc79b3d371ef0247a4fa5df8588a66d
parent7b37caa73423f9d8278892a72869c52432c2156e (diff)
downloadgsoc2013-evolution-75353e0bff2661faf013f87aed65fbc58bb0ab68.tar
gsoc2013-evolution-75353e0bff2661faf013f87aed65fbc58bb0ab68.tar.gz
gsoc2013-evolution-75353e0bff2661faf013f87aed65fbc58bb0ab68.tar.bz2
gsoc2013-evolution-75353e0bff2661faf013f87aed65fbc58bb0ab68.tar.lz
gsoc2013-evolution-75353e0bff2661faf013f87aed65fbc58bb0ab68.tar.xz
gsoc2013-evolution-75353e0bff2661faf013f87aed65fbc58bb0ab68.tar.zst
gsoc2013-evolution-75353e0bff2661faf013f87aed65fbc58bb0ab68.zip
Utility function to build a bool as part of an expression string.
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. svn path=/trunk/; revision=3300
-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 */