Browse code

Remove old utf8 functions from re_ui. Add comments to utf8 functions in re_data header file.

Dario Rodriguez authored on 02/09/2020 22:14:50
Showing 4 changed files
... ...
@@ -1,6 +1,7 @@
1 1
 *.o
2 2
 re
3 3
 tests
4
+tests_utf8
4 5
 *.log
5 6
 re.valgrind
6 7
 sdl.supp
... ...
@@ -132,8 +132,13 @@ undostack_t *redata_getstack(redata_t *redata, undo_t *undo);
132 132
 
133 133
 char *redata_generic_genname(char *filename,char *prefix, char *postfix, char *buf, int bufsize);
134 134
 
135
+/* utf8 convenience functions */
136
+
137
+/* calculate the number of utf8-charaters in buffer */
135 138
 int redata_generic_utf8len(char *ptr, int size);
139
+/* return a pointer to the "n"th ("col"th) utf8-character in buffer */
136 140
 char *redata_generic_utf8col(char *ptr, int size, int col);
141
+/* returns the len in bytes of the character starting at ptr (zero on error)*/
137 142
 int redata_generic_utf8charlen(char *ptr, int maxsize);
138 143
 
139 144
 
... ...
@@ -195,61 +195,4 @@ reui_printf(reui_t *ui, int x, int y, char *rgba, char *format, ...)
195 195
         return(0);
196 196
 }
197 197
 
198
-int
199
-reui_utf8len(reui_t *ui, char *ptr, int size)
200
-{
201
-        int len,i;
202
-        /* calculate the number of utf8-charaters in buffer */
203
-        if(ui==NULL || size<0 || (ptr==NULL && size!=0))
204
-                return(-1);
205
-        /* for now we only count the number of code points */
206
-        /* in UTF8: 0x00-0x7f single byte chars
207
-         *          0xc0-0xff leading bytes
208
-         *          0x80-0xbf continuation bytes (ignore these for len)*/
209
-/*#warning TODO: XXX support combining code points (at least U+0300 - U+036F ( https://en.wikipedia.org/wiki/Combining_character ) */
210
-        for(len=0,i=0;i<size;i++)
211
-                len+=((ptr[i]&0xc0)!=0x80)?1:0;
212
-        return(len);
213
-/*#warning TODO: XXX Also consider tabs*/
214
-}
215
-
216
-char *
217
-reui_utf8col(reui_t *ui, char *ptr, int size, int col)
218
-{
219
-        int len,i;
220
-        /* return a pointer to the "n"th ("col"th) utf8-character in buffer */
221
-        if(ui==NULL || size<0 || (ptr==NULL && size!=0))
222
-                return(NULL); /* sanity check failed */
223
-        /* see reui_utf8len() for explanation of algorithm */
224
-/*#warning TODO: support combining code points (at least U+0300 - U+036F ( https://en.wikipedia.org/wiki/Combining_character ) */
225
-        if(col>=size)
226
-                return(NULL);/* col greater than maximum possible char. count */
227
-        /* skip "col" amount of single byte chars and leading bytes */
228
-        for(len=0,i=0;len<col && i<size;i++)
229
-                len+=((ptr[i]&0xc0)!=0x80)?1:0;
230
-        /* if we landed in a continuation byte, advance until next single byte chars or leading byte */
231
-        while(i<size && (ptr[i]&0xc0)==0x80)
232
-                i++;
233
-        if(i>=size)
234
-                return(NULL); /* col is beyond end of string */
235
-        return(ptr+i);
236
-/*#warning TODO: XXX Also consider tabs*/
237
-}
238
-
239
-int
240
-reui_utf8charlen(reui_t *ui, char *ptr, int maxsize)
241
-{
242
-        int i;
243
-        /* returns the len in bytes of the character starting at ptr (zero on error)*/
244
-        if(ui==NULL || ptr==NULL || maxsize<1)
245
-                return(0); /* sanity check failed */
246
-/*#warning TODO: support combining code points (at least U+0300 - U+036F ( https://en.wikipedia.org/wiki/Combining_character ) */
247
-        if(((unsigned char *)ptr)[0]<0x80)
248
-                return(1); /* single byte char */
249
-        if((ptr[0]&0xc0)==0x80)
250
-                return(0); /* error: this is continuation, not leading byte */
251
-        for(i=1;i<maxsize && (ptr[i]&0xc0)==0x80;i++)
252
-                ;
253
-        return(i);
254
-}
255 198
 
... ...
@@ -45,12 +45,3 @@ int reui_printf(reui_t *ui, int x, int y, char *rgba, char *format, ...) __attri
45 45
 int reui_printf(reui_t *ui, int x, int y, char *rgba, char *format, ...);
46 46
 #endif
47 47
 
48
-/* calculate the number of utf8-charaters in buffer */
49
-int reui_utf8len(reui_t *ui, char *ptr, int size);
50
-
51
-/* return a pointer to the "n"th ("col"th) utf8-character in buffer */
52
-char *reui_utf8col(reui_t *ui, char *ptr, int size, int col);
53
-
54
-/* returns the len in bytes of the character starting at ptr (zero on error)*/
55
-int reui_utf8charlen(reui_t *ui, char *ptr, int maxsize);
56
-