mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-26 06:10:56 +00:00
[ruamoko] Add str_lower builtin
This returns a string with all chars lower-cased.
This commit is contained in:
parent
31abf6f955
commit
b7b8df0801
3 changed files with 20 additions and 0 deletions
|
@ -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}
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue