core: Remove substring.

* string.c (substring): Remove.
* module/mes/scm.mes (substring): New function.
This commit is contained in:
Jan Nieuwenhuizen 2016-12-23 21:44:54 +01:00
parent 9e6d862c5b
commit d37232f39c
2 changed files with 6 additions and 24 deletions

View file

@ -194,6 +194,12 @@
(define (string-ref s k)
(list-ref (string->list s) k))
(define (substring s start . rest)
(let* ((end (and (pair? rest) (car rest)))
(lst (list-tail (string->list s) start)))
(list->string (if (not end) lst
(list-head lst (- end start))))))
(define (string-prefix? prefix string)
(and
(>= (string-length string) (string-length prefix))

View file

@ -18,30 +18,6 @@
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
*/
SCM
substring (SCM x) ///((arity . n))
{
assert (TYPE (x) == PAIR);
assert (TYPE (car (x)) == STRING);
SCM s = STRING (car (x));
assert (TYPE (cadr (x)) == NUMBER);
int start = VALUE (cadr (x));
int end = VALUE (length (s));
if (TYPE (cddr (x)) == PAIR) {
assert (TYPE (caddr (x)) == NUMBER);
assert (VALUE (caddr (x)) <= end);
end = VALUE (caddr (x));
}
int n = end - start;
while (start--) s = cdr (s);
SCM p = cell_nil;
while (n-- && s != cell_nil) {
p = append2 (p, cons (MAKE_CHAR (VALUE (car (s))), cell_nil));
s = cdr (s);
}
return MAKE_STRING (p);
}
SCM
number_to_string (SCM x)
{