[ruamoko] Add str_lower builtin

This returns a string with all chars lower-cased.
This commit is contained in:
Bill Currie 2020-04-08 21:53:53 +09:00
parent 31abf6f955
commit b7b8df0801
3 changed files with 20 additions and 0 deletions

View file

@ -38,6 +38,7 @@
# include <strings.h>
#endif
#include <stdlib.h>
#include <ctype.h>
#include "qfalloca.h"
@ -247,6 +248,22 @@ bi_str_quote (progs_t *pr)
RETURN_STRING (pr, quote);
}
static void
bi_str_lower (progs_t *pr)
{
const char *str = P_GSTRING (pr, 0);
char *lower = alloca (strlen (str) + 1);
char *l = lower;
byte c;
while ((c = *str++)) {
*l++ = tolower (c);
}
*l++ = 0;
RETURN_STRING (pr, lower);
}
static builtin_t builtins[] = {
{"strlen", bi_strlen, -1},
{"sprintf", bi_sprintf, -1},
@ -264,6 +281,7 @@ static builtin_t builtins[] = {
{"str_str", bi_str_str, -1},
{"str_char", bi_str_char, -1},
{"str_quote", bi_str_quote, -1},
{"str_lower", bi_str_lower, -1},
{0}
};

View file

@ -17,5 +17,6 @@
@extern string str_str (string haystack, string needle);
@extern int str_char (string str, int ind);
string str_quote (string str);
string str_lower (string str);
#endif//__ruamoko_string_h

View file

@ -16,3 +16,4 @@ string (string str, int start, int len) str_mid = #0;
string (string haystack, string needle) str_str = #0;
int str_char (string str, int ind) = #0;
string str_quote (string str) = #0;
string str_lower (string str) = #0;