From 75353e0bff2661faf013f87aed65fbc58bb0ab68 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Tue, 30 May 2000 22:53:59 +0000 Subject: Utility function to build a bool as part of an expression string. 2000-05-30 Not Zed * 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 --- e-util/e-sexp.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'e-util/e-sexp.c') 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) { -- cgit v1.2.3