shithub: libmujs

Download patch

ref: f12fe6c072b0a3b3037c1aab35bf1e31f4a911bf
parent: bfab4a4be407a0f68bef3f2d6ba6d8ea64241858
author: Tor Andersson <[email protected]>
date: Sat Jan 18 10:38:17 EST 2014

Constify libutf.

--- a/jsutf.c
+++ b/jsutf.c
@@ -46,7 +46,7 @@
 };
 
 int
-chartorune(Rune *rune, char *str)
+chartorune(Rune *rune, const char *str)
 {
 	int c, c1, c2;
 	long l;
@@ -102,7 +102,7 @@
 }
 
 int
-runetochar(char *str, Rune *rune)
+runetochar(char *str, const Rune *rune)
 {
 	long c;
 
@@ -147,7 +147,7 @@
 }
 
 int
-runenlen(Rune *r, int nrune)
+runenlen(const Rune *r, int nrune)
 {
 	int nb, c;
 
@@ -166,7 +166,7 @@
 }
 
 int
-fullrune(char *str, int n)
+fullrune(const char *str, int n)
 {
 	int c;
 
@@ -182,15 +182,14 @@
 }
 
 Rune*
-runestrcat(Rune *s1, Rune *s2)
+runestrcat(Rune *s1, const Rune *s2)
 {
-
 	runestrcpy(runestrchr(s1, 0), s2);
 	return s1;
 }
 
 Rune*
-runestrchr(Rune *s, Rune c)
+runestrchr(const Rune *s, Rune c)
 {
 	Rune c0 = c;
 	Rune c1;
@@ -198,17 +197,17 @@
 	if(c == 0) {
 		while(*s++)
 			;
-		return s-1;
+		return (Rune*) s-1;
 	}
 
 	while((c1 = *s++))
 		if(c1 == c0)
-			return s-1;
+			return (Rune*) s-1;
 	return 0;
 }
 
 int
-runestrcmp(Rune *s1, Rune *s2)
+runestrcmp(const Rune *s1, const Rune *s2)
 {
 	Rune c1, c2;
 
@@ -226,7 +225,7 @@
 }
 
 Rune*
-runestrcpy(Rune *s1, Rune *s2)
+runestrcpy(Rune *s1, const Rune *s2)
 {
 	Rune *os1;
 
@@ -237,7 +236,7 @@
 }
 
 Rune*
-runestrdup(Rune *s)
+runestrdup(const Rune *s)
 {
 	Rune *ns;
 
@@ -249,7 +248,7 @@
 }
 
 Rune*
-runestrecpy(Rune *s1, Rune *es1, Rune *s2)
+runestrecpy(Rune *s1, Rune *es1, const Rune *s2)
 {
 	if(s1 >= es1)
 		return s1;
@@ -264,7 +263,7 @@
 }
 
 long
-runestrlen(Rune *s)
+runestrlen(const Rune *s)
 {
 
 	return runestrchr(s, 0) - s;
@@ -271,7 +270,7 @@
 }
 
 Rune*
-runestrncat(Rune *s1, Rune *s2, long n)
+runestrncat(Rune *s1, const Rune *s2, long n)
 {
 	Rune *os1;
 
@@ -286,7 +285,7 @@
 }
 
 int
-runestrncmp(Rune *s1, Rune *s2, long n)
+runestrncmp(const Rune *s1, const Rune *s2, long n)
 {
 	Rune c1, c2;
 
@@ -306,7 +305,7 @@
 }
 
 Rune*
-runestrncpy(Rune *s1, Rune *s2, long n)
+runestrncpy(Rune *s1, const Rune *s2, long n)
 {
 	int i;
 	Rune *os1;
@@ -322,7 +321,7 @@
 }
 
 Rune*
-runestrrchr(Rune *s, Rune c)
+runestrrchr(const Rune *s, Rune c)
 {
 	Rune *r;
 
@@ -330,7 +329,7 @@
 		return runestrchr(s, 0);
 	r = 0;
 	while((s = runestrchr(s, c)))
-		r = s++;
+		r = (Rune*) s++;
 	return r;
 }
 
@@ -339,14 +338,14 @@
  * 0 if none
  */
 Rune*
-runestrstr(Rune *s1, Rune *s2)
+runestrstr(const Rune *s1, const Rune *s2)
 {
-	Rune *p, *pa, *pb;
+	const Rune *p, *pa, *pb;
 	int c0, c;
 
 	c0 = *s2;
 	if(c0 == 0)
-		return s1;
+		return (Rune*) s1;
 	s2++;
 	for(p=runestrchr(s1, c0); p; p=runestrchr(p+1, c0)) {
 		pa = p;
@@ -353,7 +352,7 @@
 		for(pb=s2;; pb++) {
 			c = *pb;
 			if(c == 0)
-				return p;
+				return (Rune*) p;
 			if(c != *++pa)
 				break;
 		}
@@ -362,7 +361,7 @@
 }
 
 char*
-utfecpy(char *to, char *e, char *from)
+utfecpy(char *to, char *e, const char *from)
 {
 	char *end;
 
@@ -381,7 +380,7 @@
 }
 
 int
-utflen(char *s)
+utflen(const char *s)
 {
 	int c;
 	long n;
@@ -401,12 +400,12 @@
 }
 
 int
-utfnlen(char *s, long m)
+utfnlen(const char *s, long m)
 {
 	int c;
 	long n;
 	Rune rune;
-	char *es;
+	const char *es;
 
 	es = s + m;
 	for(n = 0; s < es; n++) {
@@ -425,11 +424,11 @@
 }
 
 char*
-utfrrune(char *s, long c)
+utfrrune(const char *s, long c)
 {
 	long c1;
 	Rune r;
-	char *s1;
+	const char *s1;
 
 	if(c < Runesync)		/* not part of utf sequence */
 		return strrchr(s, c);
@@ -439,7 +438,7 @@
 		c1 = *(uchar*)s;
 		if(c1 < Runeself) {	/* one byte rune */
 			if(c1 == 0)
-				return s1;
+				return (char*) s1;
 			if(c1 == c)
 				s1 = s;
 			s++;
@@ -453,7 +452,7 @@
 }
 
 char*
-utfrune(char *s, long c)
+utfrune(const char *s, long c)
 {
 	long c1;
 	Rune r;
@@ -468,13 +467,13 @@
 			if(c1 == 0)
 				return 0;
 			if(c1 == c)
-				return s;
+				return (char*) s;
 			s++;
 			continue;
 		}
 		n = chartorune(&r, s);
 		if(r == c)
-			return s;
+			return (char*) s;
 		s += n;
 	}
 }
@@ -484,9 +483,9 @@
  * 0 if none
  */
 char*
-utfutf(char *s1, char *s2)
+utfutf(const char *s1, const char *s2)
 {
-	char *p;
+	const char *p;
 	long f, n1, n2;
 	Rune r;
 
@@ -498,6 +497,6 @@
 	n2 = strlen(s2);
 	for(p=s1; (p=utfrune(p, f)); p+=n1)
 		if(strncmp(p, s2, n2) == 0)
-			return p;
+			return (char*) p;
 	return 0;
 }
--- a/jsutf.h
+++ b/jsutf.h
@@ -43,8 +43,8 @@
 	Runeerror	= 0xFFFD,	/* decoding error in UTF */
 };
 
-int		chartorune(Rune *rune, char *str);
-int		fullrune(char *str, int n);
+int		chartorune(Rune *rune, const char *str);
+int		fullrune(const char *str, int n);
 int		isalpharune(Rune c);
 int		islowerrune(Rune c);
 int		isspacerune(Rune c);
@@ -51,28 +51,28 @@
 int		istitlerune(Rune c);
 int		isupperrune(Rune c);
 int		runelen(long c);
-int		runenlen(Rune *r, int nrune);
-Rune*		runestrcat(Rune *s1, Rune *s2);
-Rune*		runestrchr(Rune *s, Rune c);
-int		runestrcmp(Rune *s1, Rune *s2);
-Rune*		runestrcpy(Rune *s1, Rune *s2);
-Rune*		runestrdup(Rune *s) ;
-Rune*		runestrecpy(Rune *s1, Rune *es1, Rune *s2);
-long		runestrlen(Rune *s);
-Rune*		runestrncat(Rune *s1, Rune *s2, long n);
-int		runestrncmp(Rune *s1, Rune *s2, long n);
-Rune*		runestrncpy(Rune *s1, Rune *s2, long n);
-Rune*		runestrrchr(Rune *s, Rune c);
-Rune*		runestrstr(Rune *s1, Rune *s2);
-int		runetochar(char *str, Rune *rune);
+int		runenlen(const Rune *r, int nrune);
+Rune*		runestrcat(Rune *s1, const Rune *s2);
+Rune*		runestrchr(const Rune *s, Rune c);
+int		runestrcmp(const Rune *s1, const Rune *s2);
+Rune*		runestrcpy(Rune *s1, const Rune *s2);
+Rune*		runestrdup(const Rune *s) ;
+Rune*		runestrecpy(Rune *s1, Rune *es1, const Rune *s2);
+long		runestrlen(const Rune *s);
+Rune*		runestrncat(Rune *s1, const Rune *s2, long n);
+int		runestrncmp(const Rune *s1, const Rune *s2, long n);
+Rune*		runestrncpy(Rune *s1, const Rune *s2, long n);
+Rune*		runestrrchr(const Rune *s, Rune c);
+Rune*		runestrstr(const Rune *s1, const Rune *s2);
+int		runetochar(char *str, const Rune *rune);
 Rune		tolowerrune(Rune c);
 Rune		totitlerune(Rune c);
 Rune		toupperrune(Rune c);
-char*		utfecpy(char *to, char *e, char *from);
-int		utflen(char *s);
-int		utfnlen(char *s, long m);
-char*		utfrrune(char *s, long c);
-char*		utfrune(char *s, long c);
-char*		utfutf(char *s1, char *s2);
+char*		utfecpy(char *to, char *e, const char *from);
+int		utflen(const char *s);
+int		utfnlen(const char *s, long m);
+char*		utfrrune(const char *s, long c);
+char*		utfrune(const char *s, long c);
+char*		utfutf(const char *s1, const char *s2);
 
 #endif