core: Add string-ref.
* src/strings.c (string_ref): New function. * mes/module/mes/scm.mes (string-ref): Remove.
This commit is contained in:
parent
6af0b49f09
commit
1ab054002c
|
@ -194,9 +194,6 @@
|
|||
(define (make-string n . fill)
|
||||
(list->string (apply make-list n fill)))
|
||||
|
||||
(define (string-ref s k)
|
||||
(list-ref (string->list s) k))
|
||||
|
||||
(define (string-set! s k v)
|
||||
(list->string (list-set! (string->list s) k v)))
|
||||
|
||||
|
|
|
@ -1258,6 +1258,8 @@ eval_apply ()
|
|||
goto begin;
|
||||
}
|
||||
}
|
||||
// write_error_ (CAR (r1));
|
||||
// eputs ("\n");
|
||||
push_cc (CAR (r1), r1, r0, cell_vm_apply2);
|
||||
goto eval;
|
||||
apply2:
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define MAX_STRING 4096
|
||||
|
||||
char const*
|
||||
|
@ -267,3 +269,16 @@ string_length (SCM string)
|
|||
assert (TYPE (string) == TSTRING);
|
||||
return MAKE_NUMBER (LENGTH (string));
|
||||
}
|
||||
|
||||
SCM
|
||||
string_ref (SCM str, SCM k)
|
||||
{
|
||||
assert (TYPE (str) == TSTRING);
|
||||
assert (TYPE (k) == TNUMBER);
|
||||
size_t size = LENGTH (str);
|
||||
size_t i = VALUE (k);
|
||||
if (i >= size)
|
||||
error (cell_symbol_system_error, cons (MAKE_STRING0 ("value out of range"), k));
|
||||
char const *p = CSTRING (str);
|
||||
return MAKE_CHAR (p[i]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue