shithub: femtolisp

Download patch

ref: 1fff9ac1ed55d980db14dcd9c57795b6c11154bd
parent: f13f110f2d09c959fee5abe27d3cee3c7dfeddef
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Oct 24 22:20:27 EDT 2024

char.titlecase, char-{lower,upper,title}-case?, char-{numeric,whitespace}? (note: not necessarily correct)

--- a/aliases.scm
+++ b/aliases.scm
@@ -65,13 +65,12 @@
 (define (integer->char i) (rune i))
 (define char-upcase char.upcase)
 (define char-downcase char.downcase)
+(define char-titlecase char.titlecase)
 (define char=? eqv?)
 (define char<? <)
 (define char>? >)
 (define char<=? <=)
 (define char>=? >=)
-(define (char-whitespace? c) (not (not (string.find *whitespace* c))))
-(define (char-numeric? c) (not (not (string.find "0123456789" c))))
 
 (define string=? eqv?)
 (define string<? <)
--- a/string.c
+++ b/string.c
@@ -237,13 +237,67 @@
 	return mk_rune(tolowerrune(*(Rune*)cp_data(cp)));
 }
 
+BUILTIN("char.titlecase", char_titlecase)
+{
+	argcount(nargs, 1);
+	cprim_t *cp = ptr(args[0]);
+	if(!iscprim(args[0]) || cp_class(cp) != runetype)
+		type_error("rune", args[0]);
+	return mk_rune(totitlerune(*(Rune*)cp_data(cp)));
+}
+
 BUILTIN("char-alphabetic?", char_alphabeticp)
 {
 	argcount(nargs, 1);
-	cprim_t *cp = (cprim_t*)ptr(args[0]);
+	cprim_t *cp = ptr(args[0]);
 	if(!iscprim(args[0]) || cp_class(cp) != runetype)
 		type_error("rune", args[0]);
 	return isalpharune(*(Rune*)cp_data(cp)) ? FL_T : FL_F;
+}
+
+BUILTIN("char-lower-case?", char_lower_casep)
+{
+	argcount(nargs, 1);
+	cprim_t *cp = ptr(args[0]);
+	if(!iscprim(args[0]) || cp_class(cp) != runetype)
+		type_error("rune", args[0]);
+	return islowerrune(*(Rune*)cp_data(cp)) ? FL_T : FL_F;
+}
+
+BUILTIN("char-upper-case?", char_upper_casep)
+{
+	argcount(nargs, 1);
+	cprim_t *cp = ptr(args[0]);
+	if(!iscprim(args[0]) || cp_class(cp) != runetype)
+		type_error("rune", args[0]);
+	return isupperrune(*(Rune*)cp_data(cp)) ? FL_T : FL_F;
+}
+
+BUILTIN("char-title-case?", char_title_casep)
+{
+	argcount(nargs, 1);
+	cprim_t *cp = ptr(args[0]);
+	if(!iscprim(args[0]) || cp_class(cp) != runetype)
+		type_error("rune", args[0]);
+	return istitlerune(*(Rune*)cp_data(cp)) ? FL_T : FL_F;
+}
+
+BUILTIN("char-numeric?", char_numericp)
+{
+	argcount(nargs, 1);
+	cprim_t *cp = ptr(args[0]);
+	if(!iscprim(args[0]) || cp_class(cp) != runetype)
+		type_error("rune", args[0]);
+	return isdigitrune(*(Rune*)cp_data(cp)) ? FL_T : FL_F;
+}
+
+BUILTIN("char-whitespace?", char_whitespacep)
+{
+	argcount(nargs, 1);
+	cprim_t *cp = ptr(args[0]);
+	if(!iscprim(args[0]) || cp_class(cp) != runetype)
+		type_error("rune", args[0]);
+	return isspacerune(*(Rune*)cp_data(cp)) ? FL_T : FL_F;
 }
 
 BUILTIN("string.find", string_find)