Index: funcs/func_strings.c =================================================================== --- funcs/func_strings.c (revision 245493) +++ funcs/func_strings.c (working copy) @@ -644,6 +644,26 @@ .desc = "Example: ${KEYPADHASH(Les)} returns \"537\"\n", }; +static int trim(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +{ + if (ast_strlen_zero(data)) { + buf[0] = '\0'; + return 0; + } + + ast_copy_string(buf, ast_strip(data), len); + + return 0; +} + +static struct ast_custom_function trim_function = { + .name = "TRIM", + .synopsis = "Trim whitespace", + .desc = "Trims leaing and trailing whitespace from the specified string.", + .syntax = "TRIM()", + .read = trim, +}; + static int unload_module(void) { int res = 0; @@ -660,6 +680,7 @@ res |= ast_custom_function_unregister(&eval_function); res |= ast_custom_function_unregister(&keypadhash_function); res |= ast_custom_function_unregister(&sprintf_function); + res |= ast_custom_function_unregister(&trim_function); return res; } @@ -680,6 +701,7 @@ res |= ast_custom_function_register(&eval_function); res |= ast_custom_function_register(&keypadhash_function); res |= ast_custom_function_register(&sprintf_function); + res |= ast_custom_function_register(&trim_function); return res; }