paul@403 | 1 | /* Native functions for Unicode operations. |
paul@403 | 2 | |
paul@403 | 3 | Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> |
paul@403 | 4 | |
paul@403 | 5 | This program is free software; you can redistribute it and/or modify it under |
paul@403 | 6 | the terms of the GNU General Public License as published by the Free Software |
paul@403 | 7 | Foundation; either version 3 of the License, or (at your option) any later |
paul@403 | 8 | version. |
paul@403 | 9 | |
paul@403 | 10 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@403 | 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@403 | 12 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@403 | 13 | details. |
paul@403 | 14 | |
paul@403 | 15 | You should have received a copy of the GNU General Public License along with |
paul@403 | 16 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@403 | 17 | */ |
paul@403 | 18 | |
paul@403 | 19 | #include <string.h> /* strcmp, memcpy */ |
paul@403 | 20 | #include "native/common.h" |
paul@403 | 21 | #include "types.h" |
paul@403 | 22 | #include "exceptions.h" |
paul@403 | 23 | #include "ops.h" |
paul@403 | 24 | #include "progconsts.h" |
paul@403 | 25 | #include "progops.h" |
paul@403 | 26 | #include "progtypes.h" |
paul@403 | 27 | #include "main.h" |
paul@403 | 28 | |
paul@403 | 29 | /* Unicode operations. */ |
paul@403 | 30 | |
paul@403 | 31 | __attr __fn_native_unicode_unicode_len(__attr __args[]) |
paul@403 | 32 | { |
paul@403 | 33 | __attr * const _data = &__args[1]; |
paul@403 | 34 | /* _data interpreted as string */ |
paul@403 | 35 | char *s = _data->strvalue; |
paul@403 | 36 | int i, c = 0; |
paul@403 | 37 | |
paul@403 | 38 | for (i = 0; i < _data->size; i++) |
paul@403 | 39 | if (((s[i] & 0xc0) == 0xc0) || !(s[i] & 0x80)) |
paul@403 | 40 | c++; |
paul@403 | 41 | |
paul@403 | 42 | /* Return the new integer. */ |
paul@403 | 43 | return __new_int(c); |
paul@403 | 44 | } |
paul@403 | 45 | |
paul@403 | 46 | /* Module initialisation. */ |
paul@403 | 47 | |
paul@403 | 48 | void __main_native_unicode() |
paul@403 | 49 | { |
paul@403 | 50 | } |