]> gitweb.factorcode.org Git - factor.git/commitdiff
io.buffers: fix buffer-until for iota (reported by Sascha Matzke)
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sat, 16 Jan 2010 05:42:33 +0000 (18:42 +1300)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sat, 16 Jan 2010 05:44:24 +0000 (18:44 +1300)
basis/io/buffers/buffers-tests.factor
basis/io/buffers/buffers.factor
core/io/files/files-tests.factor
core/io/test/read-until-test.txt [new file with mode: 0644]

index 93d2f5b2fc60ce3a1107c4b97918f9296a7660b4..836b4d0cc8aea7c273318d5d2028d0e7ebc64ddb 100644 (file)
@@ -58,3 +58,7 @@ strings accessors destructors ;
 100 <buffer> "b" set
 [ 1000 "b" get n>buffer >string ] must-fail
 "b" get dispose
+
+"hello world" string>buffer "b" set
+[ "hello" CHAR: \s ] [ " " "b" get buffer-until [ >string ] dip ] unit-test
+"b" get dispose
index f45d3bb06223ba8d1619921c081a5ebeb4f76ebe..23358d9a0e20c2fcfd61e331ba344da53ccc1434 100644 (file)
@@ -1,5 +1,5 @@
 ! Copyright (C) 2004, 2005 Mackenzie Straight.
-! Copyright (C) 2006, 2008 Slava Pestov.
+! Copyright (C) 2006, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien alien.accessors alien.c-types
 alien.data alien.syntax kernel libc math sequences byte-arrays
@@ -73,7 +73,9 @@ HINTS: >buffer byte-array buffer ;
     bi ; inline
 
 : search-buffer-until ( pos fill ptr separators -- n )
-    [ [ swap alien-unsigned-1 ] dip member-eq? ] 2curry find-from drop ; inline
+    [ iota ] 2dip
+    [ [ swap alien-unsigned-1 ] dip member-eq? ] 2curry
+    find-from drop ; inline
 
 : finish-buffer-until ( buffer n -- byte-array separator )
     [
index 23d974254de1255bb82d8f6cc0a38e6b83e0a2c6..da5d67065908a075f2fc24ea52530d8959b05866 100644 (file)
@@ -1,8 +1,8 @@
 USING: arrays debugger.threads destructors io io.directories
-io.encodings.ascii io.encodings.binary
-io.files io.files.private io.files.temp io.files.unique kernel
-make math sequences system threads tools.test generic.single
-io.encodings.8-bit.latin1 ;
+io.encodings.ascii io.encodings.binary io.encodings.string
+io.encodings.8-bit.latin1 io.files io.files.private
+io.files.temp io.files.unique kernel make math sequences system
+threads tools.test generic.single ;
 IN: io.files.tests
 
 [ ] [ "append-test" temp-file dup exists? [ delete-file ] [ drop ] if ] unit-test
@@ -23,6 +23,20 @@ IN: io.files.tests
     [ read1 ] with-file-reader >fixnum
 ] unit-test
 
+[
+    "This" CHAR: \s
+] [
+    "vocab:io/test/read-until-test.txt" ascii
+    [ " " read-until ] with-file-reader
+] unit-test
+
+[
+    "This" CHAR: \s
+] [
+    "vocab:io/test/read-until-test.txt" binary
+    [ " " read-until [ ascii decode ] dip ] with-file-reader
+] unit-test
+
 [ ] [
     "It seems Jobs has lost his grasp on reality again.\n"
     "separator-test.txt" temp-file latin1 set-file-contents
diff --git a/core/io/test/read-until-test.txt b/core/io/test/read-until-test.txt
new file mode 100644 (file)
index 0000000..a496efe
--- /dev/null
@@ -0,0 +1 @@
+This is a text file