factor/library/collections/sbuf.factor

25 lines
629 B
Factor
Raw Normal View History

! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
2005-04-02 02:39:33 -05:00
IN: strings
2005-05-05 22:30:58 -04:00
USING: generic kernel kernel-internals math math-internals
sequences ;
2005-04-02 02:39:33 -05:00
2005-05-05 22:30:58 -04:00
M: string (grow) grow-string ;
2005-05-05 16:51:38 -04:00
2005-05-05 22:30:58 -04:00
BUILTIN: sbuf 13
[ 1 length set-capacity ]
[ 2 underlying set-underlying ] ;
2004-07-16 02:26:21 -04:00
2005-05-05 22:30:58 -04:00
M: sbuf set-length ( n sbuf -- )
growable-check 2dup grow set-capacity ;
2005-04-19 20:28:01 -04:00
2005-05-05 22:30:58 -04:00
M: sbuf nth ( n sbuf -- ch )
bounds-check underlying char-slot ;
2004-08-10 23:48:08 -04:00
2005-05-05 22:30:58 -04:00
M: sbuf set-nth ( ch n sbuf -- )
growable-check 2dup ensure underlying
>r >r >fixnum r> r> set-char-slot ;
2004-08-10 23:48:08 -04:00
2005-05-05 22:30:58 -04:00
M: sbuf >string
[ 0 swap length ] keep underlying substring ;