--- func_strings.c.old 2006-03-16 22:03:57.000000000 +0100 +++ func_strings.c 2006-03-16 22:09:18.000000000 +0100 @@ -422,6 +422,71 @@ .desc = "Example: ${KEYPADHASH(Les)} returns \"537\"\n", }; +static char *function_tolower(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +{ + int i = 0; + while (data[i]) + { + if (data[i] & 0x80) + { + unsigned char c = data[i]; + if (c >= 192 && c <= 223) + { + c += 32; + data[i] = (char)c; + } + } + else + { + data[i] = tolower(data[i]); + } + i++; + } + return data; +} + +static struct ast_custom_function tolower_function = { + .name = "TOLOWER", + .synopsis = "Returns the string in lowercase", + .syntax = "TOLOWER()", + .desc = "Using TOLOWER convert all ASCII characters from A to Z\n" + "to lowercase a to z.\n", + .read = function_tolower, +}; + +static char *function_toupper(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +{ + int i = 0; + while (data[i]) + { + if (data[i] & 0x80) + { + unsigned char c = data[i]; + if (c >= 224) + { + c -= 32; + data[i] = (char)c; + } + } + else + { + data[i] = toupper(data[i]); + } + i++; + } + return data; +} + + +static struct ast_custom_function toupper_function = { + .name = "TOUPPER", + .synopsis = "Returns the string in uppercase", + .syntax = "TOUPPER()", + .desc = "Using TOUPPER convert all ASCII characters from a to z\n" + "to uppercase A to Z.\n", + .read = function_toupper, +}; + static char *tdesc = "String handling dialplan functions"; int unload_module(void) @@ -438,6 +503,8 @@ res |= ast_custom_function_unregister(&strptime_function); res |= ast_custom_function_unregister(&eval_function); res |= ast_custom_function_unregister(&keypadhash_function); + res |= ast_custom_function_unregister(&tolower_function); + res |= ast_custom_function_unregister(&toupper_function); return res; } @@ -456,6 +523,8 @@ res |= ast_custom_function_register(&strptime_function); res |= ast_custom_function_register(&eval_function); res |= ast_custom_function_register(&keypadhash_function); + res |= ast_custom_function_register(&tolower_function); + res |= ast_custom_function_register(&toupper_function); return res; }