Skip to content

Commit

Permalink
Allow checking for empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
benlangfeld committed Jan 7, 2014
1 parent 49cb35f commit 8b497d7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ lib_LTLIBRARIES = libcspeech-@[email protected]
## 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
Expand Down
17 changes: 17 additions & 0 deletions cspeech.cc
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*
* cspeech.cc
*
*/

static inline int cspeech_zstr(const char *s)
{
return !s || *s == '\0';
}
2 changes: 2 additions & 0 deletions cspeech.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#ifndef CSPEECH_H_
#define CSPEECH_H_

static inline int cspeech_zstr(const char *s);

#include <cspeech/srgs.h>
#include <cspeech/nlsml.h>

Expand Down
9 changes: 5 additions & 4 deletions cspeech/nlsml.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <map>
#include <stdlib.h>

#include "cspeech.h"
#include "nlsml.h"

struct nlsml_parser;
Expand Down Expand Up @@ -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]));
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand All @@ -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));
Expand Down

0 comments on commit 8b497d7

Please sign in to comment.