]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
move functions to strip commas and non-numeric chars to switch_utils
authorMichael Jerris <mike@jerris.com>
Mon, 8 Mar 2010 08:12:12 +0000 (08:12 +0000)
committerMichael Jerris <mike@jerris.com>
Mon, 8 Mar 2010 08:12:12 +0000 (08:12 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16936 d0543943-73ff-0310-b7d9-9358b9ac24b2

12 files changed:
src/include/switch_utils.h
src/mod/say/mod_say_de/mod_say_de.c
src/mod/say/mod_say_en/mod_say_en.c
src/mod/say/mod_say_es/mod_say_es.c
src/mod/say/mod_say_fr/mod_say_fr.c
src/mod/say/mod_say_hu/mod_say_hu.c
src/mod/say/mod_say_it/mod_say_it.c
src/mod/say/mod_say_nl/mod_say_nl.c
src/mod/say/mod_say_ru/mod_say_ru.c
src/mod/say/mod_say_th/mod_say_th.c
src/mod/say/mod_say_zh/mod_say_zh.c
src/switch_utils.c

index 10fba43094c17ca702bc6824eadfa0b0c6d3690f..925f3db59299e1e0eb853f7766eb6fa9239abe03 100644 (file)
@@ -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);
index ccb06e286adffa44c3cbe521ea1fe990bf0f20a1..e36abbdb39b6928463754c8a6583ce1bc1f389b5 100644 (file)
@@ -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;
        }
index e8e2b5847732d7015f3528b11a886b66f2be6a1c..450047ad674c458c00542ec6a4ddbb89f1d0546f 100644 (file)
@@ -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;
        }
index fdab4210ae7cfa16e6462d215159930188160a21..3ab33496180de12bb0e967750eddd31b6a0098ff 100644 (file)
@@ -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;
        }
index ac114e4f600cdd0fb3375888ddeec9af7fa6604f..670746a8d3fea62771730fcb293de317fb886181 100644 (file)
@@ -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;
        }
index c0cc8b287424ee7c0b520dc2558654970e36bccd..5e92ff5cc8e9871d9c7ff7010fd8feaaf1c876b6 100644 (file)
@@ -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;
        }
index 5a615dfbd0b5a4fde5493729ba41094e8ba4a472..b42d084e8de614cb646dc7255a54fedef1802025 100644 (file)
@@ -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;
        }
index 8ef1c49f6bafb9998363a82dffad1d2065d4f624..2ee8b35473184db1ab6b26c2b99d99511be4dd97 100644 (file)
@@ -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;
        }
index b4e0d2ce82f997727d091e2494a277fadc04cfec..7c260f971c5823c1799a19a0aaf7dc0e6600f14f 100644 (file)
@@ -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;
        }
index 2a60bd06129fcd8badc4e2d5b4e86d6595a2b987..95b2ff08336d80685b1f90f1ac95e10049898a9e 100644 (file)
@@ -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;
        }
index deef5cc605a84916bed3e587579986bc77b3b09f..6432ded61cb6aa8029c802f6686d7940b5e8777b 100644 (file)
@@ -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;
        }
index 5bf661dcf9dbdfb3b2704ac4e2a6200c6f525c68..7107518cfdde8e583a9beb4dd2f4d39b457ff38b 100644 (file)
@@ -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;