From 8b497d79febac01aec0f11896c24a519ad953e00 Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Tue, 7 Jan 2014 17:57:25 -0200 Subject: [PATCH] Allow checking for empty strings #3 --- Makefile.am | 3 ++- cspeech.cc | 17 +++++++++++++++++ cspeech.h | 2 ++ cspeech/nlsml.cc | 9 +++++---- 4 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 cspeech.cc diff --git a/Makefile.am b/Makefile.am index c9ad4e3..d968ed4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -26,7 +26,8 @@ lib_LTLIBRARIES = libcspeech-@CSPEECH_API_VERSION@.la ## rules which invoke the C++ compiler to produce a libtool object file (.lo) ## from each source file. Note that it is not necessary to list header files ## which are already listed elsewhere in a _HEADERS variable assignment. -libcspeech_@CSPEECH_API_VERSION@_la_SOURCES = cspeech/nlsml.cc \ +libcspeech_@CSPEECH_API_VERSION@_la_SOURCES = cspeech.cc \ + cspeech/nlsml.cc \ cspeech/srgs.cc ## Instruct libtool to include ABI version information in the generated shared diff --git a/cspeech.cc b/cspeech.cc new file mode 100644 index 0000000..295f926 --- /dev/null +++ b/cspeech.cc @@ -0,0 +1,17 @@ +/* + * cspeech - Speech document (SSML, SRGS, NLSML) modelling and matching for C + * Copyright (C) 2013, Grasshopper + * + * License: MIT + * + * Contributor(s): + * Chris Rienzo + * + * cspeech.cc + * + */ + +static inline int cspeech_zstr(const char *s) +{ + return !s || *s == '\0'; +} diff --git a/cspeech.h b/cspeech.h index 14b3b05..e0b3581 100644 --- a/cspeech.h +++ b/cspeech.h @@ -14,6 +14,8 @@ #ifndef CSPEECH_H_ #define CSPEECH_H_ +static inline int cspeech_zstr(const char *s); + #include #include diff --git a/cspeech/nlsml.cc b/cspeech/nlsml.cc index 50344a0..1cd1d76 100644 --- a/cspeech/nlsml.cc +++ b/cspeech/nlsml.cc @@ -15,6 +15,7 @@ #include #include +#include "cspeech.h" #include "nlsml.h" struct nlsml_parser; @@ -97,7 +98,7 @@ struct nlsml_parser { static struct tag_def *add_tag_def(const char *tag, tag_attribs_fn attribs_fn, tag_cdata_fn cdata_fn, const char *children_tags) { struct tag_def *def = switch_core_alloc(globals.pool, sizeof(*def)); - if (!zstr(children_tags)) { + if (!cspeech_zstr(children_tags)) { char *children_tags_dup = switch_core_strdup(globals.pool, children_tags); char *tags[32] = { 0 }; int tag_count = switch_separate_string(children_tags_dup, ',', tags, sizeof(tags) / sizeof(tags[0])); @@ -327,7 +328,7 @@ enum nlsml_match_type nlsml_parse(const char *result, const char *uuid) { struct nlsml_parser parser = { 0 }; parser.uuid = uuid; - if (!zstr(result)) { + if (!cspeech_zstr(result)) { iksparser *p = iks_sax_new(&parser, tag_hook, cdata_hook); if (iks_parse(p, result, 0, 1) == IKS_OK) { /* check result */ @@ -426,7 +427,7 @@ iks *nlsml_create_dtmf_match(const char *digits, const char *interpretation) iks *result = iks_new("result"); iks_insert_attrib(result, "xmlns", NLSML_NS); iks_insert_attrib(result, "xmlns:xf", "http://www.w3.org/2000/xforms"); - if (!zstr(digits)) { + if (!cspeech_zstr(digits)) { int first = 1; int i; int num_digits = strlen(digits); @@ -451,7 +452,7 @@ iks *nlsml_create_dtmf_match(const char *digits, const char *interpretation) } iks_insert_cdata(input_node, stream.data, strlen(stream.data)); - if (zstr(interpretation)) { + if (cspeech_zstr(interpretation)) { iks_insert_cdata(instance_node, stream.data, strlen(stream.data)); } else { iks_insert_cdata(instance_node, interpretation, strlen(interpretation));