ref: a32850e030c8672030ab743b3dda31c90f925f18
parent: dc5b6960e03cf5ab558fdd5f19f782da1e734f60
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Mar 17 21:11:31 EDT 2025
remove rune string type References: https://todo.sr.ht/~ft/sl/30
--- a/src/cvalues.c
+++ b/src/cvalues.c
@@ -1326,9 +1326,6 @@
sl_strtypesym = mk_csym("*str-type*");
setc(sl_strtypesym, mk_list2(sl_arrsym, sl_bytesym));
- sl_runestrtypesym = mk_csym("*runestr-type*");
- setc(sl_runestrtypesym, mk_list2(sl_arrsym, sl_runesym));
-
mk_primtype(s8, s8int);
mk_primtype(u8, u8int);
mk_primtype(s16, s16int);
@@ -1349,5 +1346,4 @@
sl_strtype = get_type(sym_value(sl_strtypesym));
sl_emptystr = cvalue_from_ref(sl_strtype, (char*)"", 0);
- sl_runestrtype = get_type(sym_value(sl_runestrtypesym));
}
--- a/src/sl.c
+++ b/src/sl.c
@@ -29,7 +29,7 @@
sl_v sl_s8sym, sl_u8sym, sl_s16sym, sl_u16sym, sl_s32sym, sl_u32sym;
sl_v sl_s64sym, sl_u64sym, sl_bignumsym;
sl_v sl_bytesym, sl_runesym, sl_floatsym, sl_doublesym;
-sl_v sl_strtypesym, sl_runestrtypesym;
+sl_v sl_strtypesym;
sl_type *sl_mptype, *sl_builtintype;
sl_type *sl_s8type, *sl_u8type;
@@ -38,7 +38,7 @@
sl_type *sl_s64type, *sl_u64type;
sl_type *sl_floattype, *sl_doubletype;
sl_type *sl_bytetype, *sl_runetype;
-sl_type *sl_strtype, *sl_runestrtype;
+sl_type *sl_strtype;
sl_thread(Sl *slp);
Slg slg = {0};
--- a/src/sl.h
+++ b/src/sl.h
@@ -431,7 +431,7 @@
extern sl_v sl_s8sym, sl_u8sym, sl_s16sym, sl_u16sym, sl_s32sym, sl_u32sym;
extern sl_v sl_s64sym, sl_u64sym, sl_bignumsym;
extern sl_v sl_bytesym, sl_runesym, sl_floatsym, sl_doublesym;
-extern sl_v sl_strtypesym, sl_runestrtypesym;
+extern sl_v sl_strtypesym;
extern sl_type *sl_mptype, *sl_builtintype;
extern sl_type *sl_s8type, *sl_u8type;
--- a/src/str.c
+++ b/src/str.c
@@ -70,52 +70,6 @@
return ns;
}
-BUILTIN("str-encode", str_encode)
-{
- argcount(nargs, 1);
- if(iscvalue(args[0])){
- csl_v *cv = ptr(args[0]);
- sl_type *t = cv_class(cv);
- if(t->eltype == sl_runetype){
- usize nr = cv_len(cv) / sizeof(Rune);
- Rune *r = (Rune*)cv_data(cv);
- usize nb = runenlen(r, nr);
- sl_v str = cvalue_str(nb);
- char *s = cvalue_data(str);
- for(usize i = 0; i < nr; i++)
- s += runetochar(s, r+i);
- return str;
- }
- }
- type_error("arr rune", args[0]);
-}
-
-BUILTIN("str-decode", str_decode)
-{
- bool term = false;
- if(nargs == 2)
- term = args[1] != sl_nil;
- else
- argcount(nargs, 1);
- if(!sl_isstr(args[0]))
- type_error("str", args[0]);
- csl_v *cv = ptr(args[0]);
- char *ptr = (char*)cv_data(cv);
- usize nb = cv_len(cv);
- usize nc = u8_runelen(ptr, nb);
- usize newsz = nc*sizeof(Rune);
- if(term)
- newsz += sizeof(Rune);
- sl_v runestr = cvalue(sl_runestrtype, newsz);
- ptr = cvalue_data(args[0]); // relocatable pointer
- Rune *r = cvalue_data(runestr);
- for(usize i = 0; i < nb; i++)
- ptr += chartorune(r+i, ptr);
- if(term)
- r[nb] = 0;
- return runestr;
-}
-
BUILTIN("str", str)
{
if(nargs == 1 && sl_isstr(args[0]))
@@ -353,11 +307,6 @@
Rune r = *(Rune*)cp_data(cp);
needlesz = runetochar(cbuf, &r);
needle = cbuf;
- needle[needlesz] = 0;
- }else if(iscprim(v) && cp_class(cp) == sl_bytetype){
- needlesz = 1;
- needle = cbuf;
- needle[0] = *(char*)cp_data(cp);
needle[needlesz] = 0;
}else if(sl_isstr(v)){
csl_v *cv = ptr(v);
--- a/test/unittest.lsp
+++ b/test/unittest.lsp
@@ -498,20 +498,9 @@
(defmacro (!! x y z) (+ z (apply !! (list x y))))
(assert (eq? 4 (!! 5 2 1)))
-;; rune strings
-(let* ((b (buffer))
- (s "1э1ю1я") ; mixed ascii and non-ascii
- (es (str #\" s #\")))
- (write (str-decode s) b)
- (assert (equal? es (io->str b)))
- (io-close b))
-
(def s "привет\0пока")
(def s2 "hello \t \n world\n ")
-(assert (equal? s (str-encode (str-decode s))))
-(assert (equal? (str s "\0") (str-encode (str-decode s t))))
-
(assert (eq? 21 (sizeof s)))
(assert (eq? 21 (length s)))
(assert (eq? 11 (str-length s)))
@@ -616,7 +605,6 @@
(assert (= 10 (str-find s #\o 5)))
(assert (= 11 (str-find s #\o 11)))
(assert (not (str-find s #\o 12)))
-(assert (= 4 (str-find s (byte #\o))))
(assert (= 4 (str-find s "o")))
(assert (= 2 (str-find s "ll")))
(assert (not (str-find s "ll" 3)))
@@ -623,6 +611,7 @@
(assert (= 0 (str-find s "")))
(assert (= 7 (str-find s "" 7)))
(assert-fail (str-find s 0))
+(assert-fail (str-find s (byte #\o)))
(assert (equal? "1.5" (num->str 1.5)))
(assert (equal? "-3039" (num->str (s16 -12345) 16)))