]> gitweb.factorcode.org Git - factor.git/commitdiff
Move io.streams.string from core to basis
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 6 Feb 2009 07:58:51 +0000 (01:58 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 6 Feb 2009 07:58:51 +0000 (01:58 -0600)
12 files changed:
basis/io/streams/string/authors.txt [new file with mode: 0644]
basis/io/streams/string/string-docs.factor [new file with mode: 0644]
basis/io/streams/string/string-tests.factor [new file with mode: 0644]
basis/io/streams/string/string.factor [new file with mode: 0644]
basis/io/streams/string/summary.txt [new file with mode: 0644]
core/checksums/crc32/crc32.factor
core/io/streams/string/authors.txt [deleted file]
core/io/streams/string/string-docs.factor [deleted file]
core/io/streams/string/string-tests.factor [deleted file]
core/io/streams/string/string.factor [deleted file]
core/io/streams/string/summary.txt [deleted file]
core/parser/parser.factor

diff --git a/basis/io/streams/string/authors.txt b/basis/io/streams/string/authors.txt
new file mode 100644 (file)
index 0000000..1901f27
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
diff --git a/basis/io/streams/string/string-docs.factor b/basis/io/streams/string/string-docs.factor
new file mode 100644 (file)
index 0000000..b87e5ca
--- /dev/null
@@ -0,0 +1,29 @@
+USING: help.markup help.syntax io strings quotations sequences ;
+IN: io.streams.string
+
+ARTICLE: "io.streams.string" "String streams"
+"String streams:"
+{ $subsection <string-reader> }
+{ $subsection <string-writer> }
+"Utility combinators:"
+{ $subsection with-string-reader }
+{ $subsection with-string-writer } ;
+
+ABOUT: "io.streams.string"
+
+HELP: <string-writer>
+{ $values { "stream" "an output stream" } }
+{ $description "Creates an output stream that collects text into a string buffer. The contents of the buffer can be obtained by executing " { $link >string } "." } ;
+
+HELP: with-string-writer
+{ $values { "quot" quotation } { "str" string } }
+{ $description "Calls the quotation in a new dynamic scope with " { $link output-stream } " rebound to a new string writer. The accumulated string is output when the quotation returns." } ;
+
+HELP: <string-reader>
+{ $values { "str" string } { "stream" "an input stream" } }
+{ $description "Creates a new stream for reading " { $snippet "str" } " from beginning to end." }
+{ $notes "The implementation exploits the ability of string buffers to respond to the input stream protocol by reading characters from the end of the buffer." } ;
+
+HELP: with-string-reader
+{ $values { "str" string } { "quot" quotation } }
+{ $description "Calls the quotation in a new dynamic scope with " { $link input-stream } " rebound to an input stream reading " { $snippet "str" } " from beginning to end." } ;
diff --git a/basis/io/streams/string/string-tests.factor b/basis/io/streams/string/string-tests.factor
new file mode 100644 (file)
index 0000000..a650204
--- /dev/null
@@ -0,0 +1,59 @@
+USING: io.streams.string io kernel arrays namespaces make
+tools.test ;
+IN: io.streams.string.tests
+
+[ "line 1" CHAR: l ]
+[
+    "line 1\nline 2\nline 3" <string-reader>
+    dup stream-readln swap stream-read1
+]
+unit-test
+
+[ f ]
+[ "" <string-reader> stream-readln ]
+unit-test
+
+[ "xyzzy" ] [ [ "xyzzy" write ] with-string-writer ] unit-test
+
+[ "a" ] [ 1 SBUF" cba" stream-read ] unit-test
+[ "ab" ] [ 2 SBUF" cba" stream-read ] unit-test
+[ "abc" ] [ 3 SBUF" cba" stream-read ] unit-test
+[ "abc" ] [ 4 SBUF" cba" stream-read ] unit-test
+[ "abc" f ] [
+    3 SBUF" cba" [ stream-read ] keep stream-read1
+] unit-test
+
+[
+    {
+        { "It seems " CHAR: J }
+        { "obs has lost h" CHAR: i }
+        { "s grasp on reality again.\n" f }
+    }
+] [
+    [
+        "It seems Jobs has lost his grasp on reality again.\n"
+        <string-reader> [
+            "J" read-until 2array ,
+            "i" read-until 2array ,
+            "X" read-until 2array ,
+        ] with-input-stream
+    ] { } make
+] unit-test
+
+[ "hello" "hi" ] [
+    "hello\nhi" <string-reader>
+    dup stream-readln
+    2 rot stream-read
+] unit-test
+
+[ "hello" "hi" ] [
+    "hello\r\nhi" <string-reader>
+    dup stream-readln
+    2 rot stream-read
+] unit-test
+
+[ "hello" "hi" ] [
+    "hello\rhi" <string-reader>
+    dup stream-readln
+    2 rot stream-read
+] unit-test
diff --git a/basis/io/streams/string/string.factor b/basis/io/streams/string/string.factor
new file mode 100644 (file)
index 0000000..4582490
--- /dev/null
@@ -0,0 +1,67 @@
+! Copyright (C) 2003, 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors io kernel math namespaces sequences sbufs
+strings generic splitting continuations destructors
+io.streams.plain io.encodings math.order growable ;
+IN: io.streams.string
+
+<PRIVATE
+
+: harden-as ( seq growble-exemplar -- newseq )
+    underlying>> like ;
+
+: growable-read-until ( growable n -- str )
+    >fixnum dupd tail-slice swap harden-as dup reverse-here ;
+
+SINGLETON: null-encoding
+
+M: null-encoding decode-char drop stream-read1 ;
+
+PRIVATE>
+
+M: growable dispose drop ;
+
+M: growable stream-write1 push ;
+M: growable stream-write push-all ;
+M: growable stream-flush drop ;
+
+: <string-writer> ( -- stream )
+    512 <sbuf> ;
+
+: with-string-writer ( quot -- str )
+    <string-writer> swap [ output-stream get ] compose with-output-stream*
+    >string ; inline
+
+M: growable stream-read1 [ f ] [ pop ] if-empty ;
+
+: find-last-sep ( seq seps -- n )
+    swap [ memq? ] curry find-last drop ;
+
+M: growable stream-read-until
+    [ find-last-sep ] keep over [
+        [ swap 1+ growable-read-until ] 2keep [ nth ] 2keep
+        set-length
+    ] [
+        [ swap drop 0 growable-read-until f like f ] keep
+        delete-all
+    ] if ;
+
+M: growable stream-read
+    [
+        drop f
+    ] [
+        [ length swap - 0 max ] keep
+        [ swap growable-read-until ] 2keep
+        set-length
+    ] if-empty ;
+
+M: growable stream-read-partial
+    stream-read ;
+
+: <string-reader> ( str -- stream )
+    >sbuf dup reverse-here null-encoding <decoder> ;
+
+: with-string-reader ( str quot -- )
+    [ <string-reader> ] dip with-input-stream ; inline
+
+INSTANCE: growable plain-writer
diff --git a/basis/io/streams/string/summary.txt b/basis/io/streams/string/summary.txt
new file mode 100644 (file)
index 0000000..2567c6a
--- /dev/null
@@ -0,0 +1 @@
+Reading and writing strings as streams
index d373a96f39244c8d8881650849d76e7eacbb2c83..43f7a2b89e27fc5ea86c73c7514205dcf4aa0b57 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2006 Doug Coleman
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel math sequences sequences.private namespaces
-words io io.binary io.files io.streams.string quotations
+words io io.binary io.files quotations
 definitions checksums ;
 IN: checksums.crc32
 
diff --git a/core/io/streams/string/authors.txt b/core/io/streams/string/authors.txt
deleted file mode 100644 (file)
index 1901f27..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Slava Pestov
diff --git a/core/io/streams/string/string-docs.factor b/core/io/streams/string/string-docs.factor
deleted file mode 100644 (file)
index b87e5ca..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-USING: help.markup help.syntax io strings quotations sequences ;
-IN: io.streams.string
-
-ARTICLE: "io.streams.string" "String streams"
-"String streams:"
-{ $subsection <string-reader> }
-{ $subsection <string-writer> }
-"Utility combinators:"
-{ $subsection with-string-reader }
-{ $subsection with-string-writer } ;
-
-ABOUT: "io.streams.string"
-
-HELP: <string-writer>
-{ $values { "stream" "an output stream" } }
-{ $description "Creates an output stream that collects text into a string buffer. The contents of the buffer can be obtained by executing " { $link >string } "." } ;
-
-HELP: with-string-writer
-{ $values { "quot" quotation } { "str" string } }
-{ $description "Calls the quotation in a new dynamic scope with " { $link output-stream } " rebound to a new string writer. The accumulated string is output when the quotation returns." } ;
-
-HELP: <string-reader>
-{ $values { "str" string } { "stream" "an input stream" } }
-{ $description "Creates a new stream for reading " { $snippet "str" } " from beginning to end." }
-{ $notes "The implementation exploits the ability of string buffers to respond to the input stream protocol by reading characters from the end of the buffer." } ;
-
-HELP: with-string-reader
-{ $values { "str" string } { "quot" quotation } }
-{ $description "Calls the quotation in a new dynamic scope with " { $link input-stream } " rebound to an input stream reading " { $snippet "str" } " from beginning to end." } ;
diff --git a/core/io/streams/string/string-tests.factor b/core/io/streams/string/string-tests.factor
deleted file mode 100644 (file)
index a650204..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-USING: io.streams.string io kernel arrays namespaces make
-tools.test ;
-IN: io.streams.string.tests
-
-[ "line 1" CHAR: l ]
-[
-    "line 1\nline 2\nline 3" <string-reader>
-    dup stream-readln swap stream-read1
-]
-unit-test
-
-[ f ]
-[ "" <string-reader> stream-readln ]
-unit-test
-
-[ "xyzzy" ] [ [ "xyzzy" write ] with-string-writer ] unit-test
-
-[ "a" ] [ 1 SBUF" cba" stream-read ] unit-test
-[ "ab" ] [ 2 SBUF" cba" stream-read ] unit-test
-[ "abc" ] [ 3 SBUF" cba" stream-read ] unit-test
-[ "abc" ] [ 4 SBUF" cba" stream-read ] unit-test
-[ "abc" f ] [
-    3 SBUF" cba" [ stream-read ] keep stream-read1
-] unit-test
-
-[
-    {
-        { "It seems " CHAR: J }
-        { "obs has lost h" CHAR: i }
-        { "s grasp on reality again.\n" f }
-    }
-] [
-    [
-        "It seems Jobs has lost his grasp on reality again.\n"
-        <string-reader> [
-            "J" read-until 2array ,
-            "i" read-until 2array ,
-            "X" read-until 2array ,
-        ] with-input-stream
-    ] { } make
-] unit-test
-
-[ "hello" "hi" ] [
-    "hello\nhi" <string-reader>
-    dup stream-readln
-    2 rot stream-read
-] unit-test
-
-[ "hello" "hi" ] [
-    "hello\r\nhi" <string-reader>
-    dup stream-readln
-    2 rot stream-read
-] unit-test
-
-[ "hello" "hi" ] [
-    "hello\rhi" <string-reader>
-    dup stream-readln
-    2 rot stream-read
-] unit-test
diff --git a/core/io/streams/string/string.factor b/core/io/streams/string/string.factor
deleted file mode 100644 (file)
index 4582490..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-! Copyright (C) 2003, 2009 Slava Pestov.
-! See http://factorcode.org/license.txt for BSD license.
-USING: accessors io kernel math namespaces sequences sbufs
-strings generic splitting continuations destructors
-io.streams.plain io.encodings math.order growable ;
-IN: io.streams.string
-
-<PRIVATE
-
-: harden-as ( seq growble-exemplar -- newseq )
-    underlying>> like ;
-
-: growable-read-until ( growable n -- str )
-    >fixnum dupd tail-slice swap harden-as dup reverse-here ;
-
-SINGLETON: null-encoding
-
-M: null-encoding decode-char drop stream-read1 ;
-
-PRIVATE>
-
-M: growable dispose drop ;
-
-M: growable stream-write1 push ;
-M: growable stream-write push-all ;
-M: growable stream-flush drop ;
-
-: <string-writer> ( -- stream )
-    512 <sbuf> ;
-
-: with-string-writer ( quot -- str )
-    <string-writer> swap [ output-stream get ] compose with-output-stream*
-    >string ; inline
-
-M: growable stream-read1 [ f ] [ pop ] if-empty ;
-
-: find-last-sep ( seq seps -- n )
-    swap [ memq? ] curry find-last drop ;
-
-M: growable stream-read-until
-    [ find-last-sep ] keep over [
-        [ swap 1+ growable-read-until ] 2keep [ nth ] 2keep
-        set-length
-    ] [
-        [ swap drop 0 growable-read-until f like f ] keep
-        delete-all
-    ] if ;
-
-M: growable stream-read
-    [
-        drop f
-    ] [
-        [ length swap - 0 max ] keep
-        [ swap growable-read-until ] 2keep
-        set-length
-    ] if-empty ;
-
-M: growable stream-read-partial
-    stream-read ;
-
-: <string-reader> ( str -- stream )
-    >sbuf dup reverse-here null-encoding <decoder> ;
-
-: with-string-reader ( str quot -- )
-    [ <string-reader> ] dip with-input-stream ; inline
-
-INSTANCE: growable plain-writer
diff --git a/core/io/streams/string/summary.txt b/core/io/streams/string/summary.txt
deleted file mode 100644 (file)
index 2567c6a..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Reading and writing strings as streams
index d7f7bba7f617974fb81a043b2dd7f06dc76abf6b..f862885339da883f75de79eb37199ee16e6d88f7 100644 (file)
@@ -3,7 +3,7 @@
 USING: arrays definitions generic assocs kernel math namespaces
 sequences strings vectors words words.symbol quotations io
 combinators sorting splitting math.parser effects continuations
-io.files io.streams.string vocabs io.encodings.utf8 source-files
+io.files vocabs io.encodings.utf8 source-files
 classes hashtables compiler.errors compiler.units accessors sets
 lexer vocabs.parser ;
 IN: parser