shithub: sl

Download patch

ref: c912ee4bd87676ee2360315f93bc933b36800648
parent: 38156baef2e1f2a3b02d9b8a99d8685be1964e42
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Mar 17 21:49:55 EDT 2025

str: {start,end}char → {start,end}rune

--- a/src/str.c
+++ b/src/str.c
@@ -166,17 +166,17 @@
 		argcount(nargs, 3);
 	char *s = tostr(args[0]);
 	usize lenbytes = cv_len(ptr(args[0]));
-	usize startbytes, n, startchar = tosize(args[1]);
-	for(startbytes = n = 0; n < startchar && startbytes < lenbytes; n++)
+	usize startbytes, n, startrune = tosize(args[1]);
+	for(startbytes = n = 0; n < startrune && startbytes < lenbytes; n++)
 		startbytes += u8_seqlen(s+startbytes);
-	if(n != startchar)
+	if(n != startrune)
 		bounds_error(args[0], args[1]);
 	usize endbytes = lenbytes;
 	if(nargs == 3){
-		usize endchar = tosize(args[2]);
-		for(endbytes = startbytes; n < endchar && endbytes < lenbytes; n++)
+		usize endrune = tosize(args[2]);
+		for(endbytes = startbytes; n < endrune && endbytes < lenbytes; n++)
 			endbytes += u8_seqlen(s+endbytes);
-		if(n != endchar)
+		if(n != endrune)
 			bounds_error(args[0], args[2]);
 	}
 	sl_v ns = cvalue_str(endbytes-startbytes);
@@ -190,10 +190,10 @@
 	argcount(nargs, 2);
 	char *s = tostr(args[0]);
 	usize lenbytes = cv_len(ptr(args[0]));
-	usize startbytes, n, startchar = tosize(args[1]);
-	for(startbytes = n = 0; n < startchar && startbytes < lenbytes; n++)
+	usize startbytes, n, startrune = tosize(args[1]);
+	for(startbytes = n = 0; n < startrune && startbytes < lenbytes; n++)
 		startbytes += u8_seqlen(s+startbytes);
-	if(n != startchar || startbytes >= lenbytes)
+	if(n != startrune || startbytes >= lenbytes)
 		bounds_error(args[0], args[1]);
 	Rune r;
 	chartorune(&r, s+startbytes);