1.1 --- a/templates/native/unicode.c Sun Feb 12 23:24:42 2017 +0100
1.2 +++ b/templates/native/unicode.c Mon Feb 13 18:54:59 2017 +0100
1.3 @@ -72,11 +72,14 @@
1.4 __attr __fn_native_unicode_unicode_len(__attr __args[])
1.5 {
1.6 __attr * const _data = &__args[1];
1.7 + __attr * const _size = &__args[2];
1.8 /* _data interpreted as string */
1.9 char *s = _data->strvalue;
1.10 + /* _size interpreted as int */
1.11 + int size = _size->intvalue;
1.12 unsigned int i, c = 0;
1.13
1.14 - for (i = 0; s[i] != 0; i++)
1.15 + for (i = 0; i < size; i++)
1.16 if (boundary(s[i]))
1.17 c++;
1.18
1.19 @@ -87,11 +90,14 @@
1.20 __attr __fn_native_unicode_unicode_ord(__attr __args[])
1.21 {
1.22 __attr * const _data = &__args[1];
1.23 + __attr * const _size = &__args[2];
1.24 /* _data interpreted as string */
1.25 char *s = _data->strvalue;
1.26 + /* _size interpreted as int */
1.27 + int size = _size->intvalue;
1.28 unsigned int i, c = 0, v;
1.29
1.30 - for (i = 0; s[i] != 0; i++)
1.31 + for (i = 0; i < size; i++)
1.32 {
1.33 /* Evaluate the current character as a boundary. */
1.34
1.35 @@ -120,11 +126,14 @@
1.36 __attr __fn_native_unicode_unicode_substr(__attr __args[])
1.37 {
1.38 __attr * const _data = &__args[1];
1.39 - __attr * const start = &__args[2];
1.40 - __attr * const end = &__args[3];
1.41 - __attr * const step = &__args[4];
1.42 + __attr * const _size = &__args[2];
1.43 + __attr * const start = &__args[3];
1.44 + __attr * const end = &__args[4];
1.45 + __attr * const step = &__args[5];
1.46 /* _data interpreted as string */
1.47 char *s = _data->strvalue, *sub;
1.48 + /* _size interpreted as int */
1.49 + int ss = _size->intvalue;
1.50 /* start.__data__ interpreted as int */
1.51 int istart = __load_via_object(start->value, __pos___data__).intvalue;
1.52 /* end.__data__ interpreted as int */
1.53 @@ -137,7 +146,7 @@
1.54 unsigned int indexes[nchar];
1.55
1.56 unsigned int c, d, i, to, from, lastbyte = 0;
1.57 - size_t resultsize = 0, ss = strlen(_data->strvalue);
1.58 + int resultsize = 0;
1.59
1.60 /* Find the indexes of the characters. */
1.61 if (istep > 0)
1.62 @@ -190,7 +199,7 @@
1.63 } while (!boundary(s[from]));
1.64 }
1.65
1.66 - return __new_str(sub);
1.67 + return __new_str(sub, resultsize);
1.68 }
1.69
1.70 /* Module initialisation. */