From f8974f03f9f1b87a4bb1266c01460aa78a90f0b3 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 8 Mar 2010 08:12:12 +0000 Subject: [PATCH] move functions to strip commas and non-numeric chars to switch_utils git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16936 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_utils.h | 2 ++ src/mod/say/mod_say_de/mod_say_de.c | 47 ++------------------------ src/mod/say/mod_say_en/mod_say_en.c | 49 ++------------------------- src/mod/say/mod_say_es/mod_say_es.c | 47 ++------------------------ src/mod/say/mod_say_fr/mod_say_fr.c | 47 ++------------------------ src/mod/say/mod_say_hu/mod_say_hu.c | 47 ++------------------------ src/mod/say/mod_say_it/mod_say_it.c | 47 ++------------------------ src/mod/say/mod_say_nl/mod_say_nl.c | 47 ++------------------------ src/mod/say/mod_say_ru/mod_say_ru.c | 43 ++---------------------- src/mod/say/mod_say_th/mod_say_th.c | 50 ++-------------------------- src/mod/say/mod_say_zh/mod_say_zh.c | 51 ++--------------------------- src/switch_utils.c | 43 ++++++++++++++++++++++++ 12 files changed, 66 insertions(+), 454 deletions(-) diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index 10fba43094..925f3db592 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -545,6 +545,8 @@ SWITCH_DECLARE(unsigned int) switch_separate_string_string(char *buf, char *deli SWITCH_DECLARE(switch_bool_t) switch_is_number(const char *str); SWITCH_DECLARE(char *) switch_strip_spaces(const char *str); +SWITCH_DECLARE(char *) switch_strip_commas(char *in, char *out, switch_size_t len); +SWITCH_DECLARE(char *) switch_strip_nonnumerics(char *in, char *out, switch_size_t len); SWITCH_DECLARE(char *) switch_separate_paren_args(char *str); SWITCH_DECLARE(const char *) switch_stristr(const char *instr, const char *str); SWITCH_DECLARE(switch_bool_t) switch_is_lan_addr(const char *ip); diff --git a/src/mod/say/mod_say_de/mod_say_de.c b/src/mod/say/mod_say_de/mod_say_de.c index ccb06e286a..e36abbdb39 100644 --- a/src/mod/say/mod_say_de/mod_say_de.c +++ b/src/mod/say/mod_say_de/mod_say_de.c @@ -122,49 +122,6 @@ static switch_status_t play_group(switch_say_method_t method, int a, int b, int return SWITCH_STATUS_SUCCESS; } -static char *strip_commas(char *in, char *out, switch_size_t len) -{ - char *p = in, *q = out; - char *ret = out; - switch_size_t x = 0; - - for (; p && *p; p++) { - if ((*p > 47 && *p < 58)) { - *q++ = *p; - } else if (*p != ',') { - ret = NULL; - break; - } - - if (++x > len) { - ret = NULL; - break; - } - } - - return ret; -} - -static char *strip_nonnumerics(char *in, char *out, switch_size_t len) -{ - char *p = in, *q = out; - char *ret = out; - switch_size_t x = 0; - // valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others - for (; p && *p; p++) { - if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') { - *q++ = *p; - } - - if (++x > len) { - ret = NULL; - break; - } - } - - return ret; -} - static switch_status_t de_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) { int in; @@ -173,7 +130,7 @@ static switch_status_t de_say_general_count(switch_core_session_t *session, char char sbuf[13] = ""; switch_status_t status; - if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { + if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } @@ -408,7 +365,7 @@ static switch_status_t de_say_money(switch_core_session_t *session, char *tosay, char *dollars = NULL; char *cents = NULL; - if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { + if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } diff --git a/src/mod/say/mod_say_en/mod_say_en.c b/src/mod/say/mod_say_en/mod_say_en.c index e8e2b58477..450047ad67 100644 --- a/src/mod/say/mod_say_en/mod_say_en.c +++ b/src/mod/say/mod_say_en/mod_say_en.c @@ -117,49 +117,6 @@ static switch_status_t play_group(switch_say_method_t method, int a, int b, int return SWITCH_STATUS_SUCCESS; } -static char *strip_commas(char *in, char *out, switch_size_t len) -{ - char *p = in, *q = out; - char *ret = out; - switch_size_t x = 0; - - for (; p && *p; p++) { - if ((*p > 47 && *p < 58)) { - *q++ = *p; - } else if (*p != ',') { - ret = NULL; - break; - } - - if (++x > len) { - ret = NULL; - break; - } - } - - return ret; -} - -static char *strip_nonnumerics(char *in, char *out, switch_size_t len) -{ - char *p = in, *q = out; - char *ret = out; - switch_size_t x = 0; - // valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others - for (; p && *p; p++) { - if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') { - *q++ = *p; - } - - if (++x > len) { - ret = NULL; - break; - } - } - - return ret; -} - static switch_status_t en_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) { int in; @@ -169,7 +126,7 @@ static switch_status_t en_say_general_count(switch_core_session_t *session, char switch_status_t status; if (say_args->method == SSM_ITERATED) { - if ((tosay = strip_commas(tosay, sbuf, sizeof(sbuf)))) { + if ((tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf)))) { char *p; for (p = tosay; p && *p; p++) { say_file("digits/%c.wav", *p); @@ -181,7 +138,7 @@ static switch_status_t en_say_general_count(switch_core_session_t *session, char return SWITCH_STATUS_SUCCESS; } - if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { + if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } @@ -475,7 +432,7 @@ static switch_status_t en_say_money(switch_core_session_t *session, char *tosay, char *dollars = NULL; char *cents = NULL; - if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { + if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } diff --git a/src/mod/say/mod_say_es/mod_say_es.c b/src/mod/say/mod_say_es/mod_say_es.c index fdab4210ae..3ab3349618 100644 --- a/src/mod/say/mod_say_es/mod_say_es.c +++ b/src/mod/say/mod_say_es/mod_say_es.c @@ -142,49 +142,6 @@ static switch_status_t play_group(switch_say_method_t method, int a, int b, int return SWITCH_STATUS_SUCCESS; } -static char *strip_commas(char *in, char *out, switch_size_t len) -{ - char *p = in, *q = out; - char *ret = out; - switch_size_t x = 0; - - for (; p && *p; p++) { - if ((*p > 47 && *p < 58)) { - *q++ = *p; - } else if (*p != ',') { - ret = NULL; - break; - } - - if (++x > len) { - ret = NULL; - break; - } - } - - return ret; -} - -static char *strip_nonnumerics(char *in, char *out, switch_size_t len) -{ - char *p = in, *q = out; - char *ret = out; - switch_size_t x = 0; - // valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others - for (; p && *p; p++) { - if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') { - *q++ = *p; - } - - if (++x > len) { - ret = NULL; - break; - } - } - - return ret; -} - static switch_status_t es_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) { int in; @@ -193,7 +150,7 @@ static switch_status_t es_say_general_count(switch_core_session_t *session, char char sbuf[13] = ""; switch_status_t status; - if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { + if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } @@ -429,7 +386,7 @@ static switch_status_t es_say_money(switch_core_session_t *session, char *tosay, char *dollars = NULL; char *cents = NULL; - if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { + if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } diff --git a/src/mod/say/mod_say_fr/mod_say_fr.c b/src/mod/say/mod_say_fr/mod_say_fr.c index ac114e4f60..670746a8d3 100644 --- a/src/mod/say/mod_say_fr/mod_say_fr.c +++ b/src/mod/say/mod_say_fr/mod_say_fr.c @@ -139,49 +139,6 @@ static switch_status_t play_group(switch_say_method_t method, switch_say_gender_ return SWITCH_STATUS_SUCCESS; } -static char *strip_commas(char *in, char *out, switch_size_t len) -{ - char *p = in, *q = out; - char *ret = out; - switch_size_t x = 0; - - for (; p && *p; p++) { - if ((*p > 47 && *p < 58)) { - *q++ = *p; - } else if (*p != ',') { - ret = NULL; - break; - } - - if (++x > len) { - ret = NULL; - break; - } - } - - return ret; -} - -static char *strip_nonnumerics(char *in, char *out, switch_size_t len) -{ - char *p = in, *q = out; - char *ret = out; - switch_size_t x = 0; - /* valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others */ - for (; p && *p; p++) { - if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') { - *q++ = *p; - } - - if (++x > len) { - ret = NULL; - break; - } - } - - return ret; -} - static switch_status_t fr_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) { int in; @@ -190,7 +147,7 @@ static switch_status_t fr_say_general_count(switch_core_session_t *session, char char sbuf[13] = ""; switch_status_t status; - if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { + if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } @@ -480,7 +437,7 @@ static switch_status_t fr_say_money(switch_core_session_t *session, char *tosay, char *dollars = NULL; char *cents = NULL; - if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { + if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } diff --git a/src/mod/say/mod_say_hu/mod_say_hu.c b/src/mod/say/mod_say_hu/mod_say_hu.c index c0cc8b2874..5e92ff5cc8 100644 --- a/src/mod/say/mod_say_hu/mod_say_hu.c +++ b/src/mod/say/mod_say_hu/mod_say_hu.c @@ -117,49 +117,6 @@ static switch_status_t play_group(switch_say_method_t method, int a, int b, int return SWITCH_STATUS_SUCCESS; } -static char *strip_commas(char *in, char *out, switch_size_t len) -{ - char *p = in, *q = out; - char *ret = out; - switch_size_t x = 0; - - for (; p && *p; p++) { - if ((*p > 47 && *p < 58)) { - *q++ = *p; - } else if (*p != ',') { - ret = NULL; - break; - } - - if (++x > len) { - ret = NULL; - break; - } - } - - return ret; -} - -static char *strip_nonnumerics(char *in, char *out, switch_size_t len) -{ - char *p = in, *q = out; - char *ret = out; - switch_size_t x = 0; - // valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others - for (; p && *p; p++) { - if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') { - *q++ = *p; - } - - if (++x > len) { - ret = NULL; - break; - } - } - - return ret; -} - static switch_status_t hu_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) { int in; @@ -169,7 +126,7 @@ static switch_status_t hu_say_general_count(switch_core_session_t *session, char int number; switch_status_t status; - if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { + if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } @@ -437,7 +394,7 @@ static switch_status_t hu_say_money(switch_core_session_t *session, char *tosay, char sbuf[16] = ""; char *forint; - if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { + if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } diff --git a/src/mod/say/mod_say_it/mod_say_it.c b/src/mod/say/mod_say_it/mod_say_it.c index 5a615dfbd0..b42d084e8d 100644 --- a/src/mod/say/mod_say_it/mod_say_it.c +++ b/src/mod/say/mod_say_it/mod_say_it.c @@ -126,49 +126,6 @@ static switch_status_t play_group(switch_say_method_t method, int a, int b, int return SWITCH_STATUS_SUCCESS; } -static char *strip_commas(char *in, char *out, switch_size_t len) -{ - char *p = in, *q = out; - char *ret = out; - switch_size_t x = 0; - - for (; p && *p; p++) { - if ((*p > 47 && *p < 58)) { - *q++ = *p; - } else if (*p != ',') { - ret = NULL; - break; - } - - if (++x > len) { - ret = NULL; - break; - } - } - - return ret; -} - -static char *strip_nonnumerics(char *in, char *out, switch_size_t len) -{ - char *p = in, *q = out; - char *ret = out; - switch_size_t x = 0; - /* valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others */ - for (; p && *p; p++) { - if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') { - *q++ = *p; - } - - if (++x > len) { - ret = NULL; - break; - } - } - - return ret; -} - static switch_status_t it_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) { int in; @@ -177,7 +134,7 @@ static switch_status_t it_say_general_count(switch_core_session_t *session, char char sbuf[13] = ""; switch_status_t status; - if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { + if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } @@ -436,7 +393,7 @@ static switch_status_t it_say_money(switch_core_session_t *session, char *tosay, char *dollars = NULL; char *cents = NULL; - if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { + if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } diff --git a/src/mod/say/mod_say_nl/mod_say_nl.c b/src/mod/say/mod_say_nl/mod_say_nl.c index 8ef1c49f6b..2ee8b35473 100644 --- a/src/mod/say/mod_say_nl/mod_say_nl.c +++ b/src/mod/say/mod_say_nl/mod_say_nl.c @@ -113,49 +113,6 @@ static switch_status_t play_group(switch_say_method_t method, int a, int b, int return SWITCH_STATUS_SUCCESS; } -static char *strip_commas(char *in, char *out, switch_size_t len) -{ - char *p = in, *q = out; - char *ret = out; - switch_size_t x = 0; - - for (; p && *p; p++) { - if ((*p > 47 && *p < 58)) { - *q++ = *p; - } else if (*p != ',') { - ret = NULL; - break; - } - - if (++x > len) { - ret = NULL; - break; - } - } - - return ret; -} - -static char *strip_nonnumerics(char *in, char *out, switch_size_t len) -{ - char *p = in, *q = out; - char *ret = out; - switch_size_t x = 0; - // valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others - for (; p && *p; p++) { - if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') { - *q++ = *p; - } - - if (++x > len) { - ret = NULL; - break; - } - } - - return ret; -} - static switch_status_t nl_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) { int in; @@ -164,7 +121,7 @@ static switch_status_t nl_say_general_count(switch_core_session_t *session, char char sbuf[13] = ""; switch_status_t status; - if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { + if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } @@ -400,7 +357,7 @@ static switch_status_t nl_say_money(switch_core_session_t *session, char *tosay, char *dollars = NULL; char *cents = NULL; - if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { + if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } diff --git a/src/mod/say/mod_say_ru/mod_say_ru.c b/src/mod/say/mod_say_ru/mod_say_ru.c index b4e0d2ce82..7c260f971c 100644 --- a/src/mod/say/mod_say_ru/mod_say_ru.c +++ b/src/mod/say/mod_say_ru/mod_say_ru.c @@ -72,45 +72,6 @@ SWITCH_MODULE_DEFINITION(mod_say_ru, mod_say_ru_load, NULL, NULL); return SWITCH_STATUS_FALSE;\ }} -static char *strip_commas(char *in, char *out, switch_size_t len) -{ - char *p = in, *q = out; - char *ret = out; - switch_size_t x = 0; - - for (; p && *p; p++) { - if ((*p > 47 && *p < 58)) { - *q++ = *p; - } else if (*p != ',') { - ret = NULL; - break; - } - if (++x > len) { - ret = NULL; - break; - } - } - return ret; -} - -static char *strip_nonnumerics(char *in, char *out, switch_size_t len) -{ - char *p = in, *q = out; - char *ret = out; - switch_size_t x = 0; - /* valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others */ - for (; p && *p; p++) { - if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') { - *q++ = *p; - } - if (++x > len) { - ret = NULL; - break; - } - } - return ret; -} - static switch_status_t play_group(say_type_t say_type, casus_t casus, int a, int b, int c, unit_t what, switch_core_session_t *session, switch_input_args_t *args) { @@ -203,7 +164,7 @@ static switch_status_t ru_say_count(switch_core_session_t *session, char *tosay, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "ru_say_count %s!\n", tosay); - if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { + if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } @@ -300,7 +261,7 @@ static switch_status_t ru_say_money(switch_core_session_t *session, char *tosay, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " ru_say_money %s\n", tosay); - if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { + if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } diff --git a/src/mod/say/mod_say_th/mod_say_th.c b/src/mod/say/mod_say_th/mod_say_th.c index 2a60bd0612..95b2ff0833 100644 --- a/src/mod/say/mod_say_th/mod_say_th.c +++ b/src/mod/say/mod_say_th/mod_say_th.c @@ -87,52 +87,6 @@ SWITCH_MODULE_DEFINITION(mod_say_th, mod_say_th_load, NULL, NULL); return SWITCH_STATUS_FALSE; \ }} \ -static char *strip_commas(char *in, char *out, switch_size_t len) -{ - char *p = in; - char *q = out; - char *ret = out; - switch_size_t x = 0; - - for (; p && *p; p++) { - if ((*p >= '0' && *p <= '9')) { - *q++ = *p; - } else if (*p != ',') { - ret = NULL; - break; - } - - if (++x > len) { - ret = NULL; - break; - } - } - - return ret; -} - -static char *strip_nonnumerics(char *in, char *out, switch_size_t len) -{ - char *p = in; - char *q = out; - char *ret = out; - switch_size_t x = 0; - - /* valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others */ - for (; p && *p; p++) { - if ((*p >= '0' && *p <= '9') || *p == '.' || *p == '-' || *p == '+') { - *q++ = *p; - } - - if (++x > len) { - ret = NULL; - break; - } - } - - return ret; -} - static switch_status_t th_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) { int in; @@ -140,7 +94,7 @@ static switch_status_t th_say_general_count(switch_core_session_t *session, char char digits[11]; int i; - if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { + if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } @@ -505,7 +459,7 @@ static switch_status_t th_say_money(switch_core_session_t *session, char *tosay, char *dollars = NULL; char *cents = NULL; - if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { + if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } diff --git a/src/mod/say/mod_say_zh/mod_say_zh.c b/src/mod/say/mod_say_zh/mod_say_zh.c index deef5cc605..6432ded61c 100644 --- a/src/mod/say/mod_say_zh/mod_say_zh.c +++ b/src/mod/say/mod_say_zh/mod_say_zh.c @@ -86,53 +86,6 @@ SWITCH_MODULE_DEFINITION(mod_say_zh, mod_say_zh_load, NULL, NULL); return SWITCH_STATUS_FALSE; \ }} \ - -static char *strip_commas(char *in, char *out, switch_size_t len) -{ - char *p = in; - char *q = out; - char *ret = out; - switch_size_t x = 0; - - for (; p && *p; p++) { - if ((*p >= '0' && *p <= '9')) { - *q++ = *p; - } else if (*p != ',') { - ret = NULL; - break; - } - - if (++x > len) { - ret = NULL; - break; - } - } - - return ret; -} - -static char *strip_nonnumerics(char *in, char *out, switch_size_t len) -{ - char *p = in; - char *q = out; - char *ret = out; - switch_size_t x = 0; - - /* valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others */ - for (; p && *p; p++) { - if ((*p >= '0' && *p <= '9') || *p == '.' || *p == '-' || *p == '+') { - *q++ = *p; - } - - if (++x > len) { - ret = NULL; - break; - } - } - - return ret; -} - static switch_status_t zh_say_general_count(switch_core_session_t *session, char *tosay, switch_say_args_t *say_args, switch_input_args_t *args) { int in; @@ -140,7 +93,7 @@ static switch_status_t zh_say_general_count(switch_core_session_t *session, char char digits[11]; int i; - if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { + if (!(tosay = switch_strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } @@ -485,7 +438,7 @@ static switch_status_t zh_say_money(switch_core_session_t *session, char *tosay, char *dollars = NULL; char *cents = NULL; - if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { + if (strlen(tosay) > 15 || !(tosay = switch_strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); return SWITCH_STATUS_GENERR; } diff --git a/src/switch_utils.c b/src/switch_utils.c index 5bf661dcf9..7107518cfd 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -742,6 +742,49 @@ SWITCH_DECLARE(char *) switch_strip_spaces(const char *str) return s; } +SWITCH_DECLARE(char *) switch_strip_commas(char *in, char *out, switch_size_t len) +{ + char *p = in, *q = out; + char *ret = out; + switch_size_t x = 0; + + for (; p && *p; p++) { + if ((*p > 47 && *p < 58)) { + *q++ = *p; + } else if (*p != ',') { + ret = NULL; + break; + } + + if (++x > len) { + ret = NULL; + break; + } + } + + return ret; +} + +SWITCH_DECLARE(char *) switch_strip_nonnumerics(char *in, char *out, switch_size_t len) +{ + char *p = in, *q = out; + char *ret = out; + switch_size_t x = 0; + /* valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others */ + for (; p && *p; p++) { + if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') { + *q++ = *p; + } + + if (++x > len) { + ret = NULL; + break; + } + } + + return ret; +} + SWITCH_DECLARE(char *) switch_separate_paren_args(char *str) { char *e, *args;