]> gitweb.factorcode.org Git - factor.git/commitdiff
io.crlf: the lf>crlf and crlf>lf words looks generally useful, lets put them in io...
authorBjörn Lindqvist <bjourne@gmail.com>
Mon, 3 Nov 2014 23:20:05 +0000 (00:20 +0100)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 12 May 2015 16:32:05 +0000 (09:32 -0700)
basis/furnace/actions/actions-tests.factor
basis/http/http-tests.factor
basis/http/server/requests/requests-tests.factor
basis/io/crlf/crlf-tests.factor
basis/io/crlf/crlf.factor
basis/ui/backend/windows/windows.factor

index 512469f4725575263ae40fc03548d6aa61209782..b5a8c6351cc9e32081c8bc417f84857f946a14fc 100644 (file)
@@ -1,4 +1,4 @@
-USING: kernel furnace.actions validators tools.test math math.parser
+USING: kernel furnace.actions io.crlf validators tools.test math math.parser
 multiline namespaces http io.streams.string http.server http.server.requests
 sequences splitting accessors ;
 IN: furnace.actions.tests
@@ -7,8 +7,6 @@ IN: furnace.actions.tests
     [ "a" param "b" param [ string>number ] bi@ + ] >>display
 "action-1" set
 
-: lf>crlf ( string -- string' ) "\n" split "\r\n" join ;
-
 STRING: action-request-test-1
 GET http://foo/bar?a=12&b=13 HTTP/1.1
 
index 8636b6e7f11efbcad097ad3d818d114e4fb3a8ce..fda88dd42aad8dad040de89a4e64b530308a2406 100644 (file)
@@ -1,8 +1,8 @@
 USING: destructors http http.server http.server.requests http.client
-http.client.private tools.test multiline fry io.streams.string io.encodings.utf8
-io.encodings.8-bit io.encodings.binary io.encodings.string io.encodings.ascii
-kernel arrays splitting sequences assocs io.sockets db db.sqlite make
-continuations urls hashtables accessors namespaces xml.data
+http.client.private tools.test multiline fry io.streams.string io.crlf
+io.encodings.utf8 io.encodings.8-bit io.encodings.binary io.encodings.string
+io.encodings.ascii kernel arrays splitting sequences assocs io.sockets db
+db.sqlite make continuations urls hashtables accessors namespaces xml.data
 io.encodings.8-bit.latin1 random combinators.short-circuit ;
 IN: http.tests
 
@@ -25,8 +25,6 @@ IN: http.tests
 [ "localhost:8080" ] [ T{ url { protocol "http" } { host "localhost" } { port 8080 } } unparse-host ] unit-test
 [ "localhost:8443" ] [ T{ url { protocol "https" } { host "localhost" } { port 8443 } } unparse-host ] unit-test
 
-: lf>crlf ( string -- string' ) "\n" split "\r\n" join ;
-
 STRING: read-request-test-1
 POST /bar HTTP/1.1
 Some-Header: 1
index afb3eb7b16c9073cef46155af11258c0929bacdf..bfa3acbc46de1e0b5305bf532e872cb55f0ac2c9 100644 (file)
@@ -1,11 +1,9 @@
 USING: accessors assocs continuations http http.client http.client.private
-http.server http.server.requests io.streams.limited io.streams.string kernel
-math math.parser multiline namespaces peg sequences splitting tools.test urls ;
+http.server http.server.requests io.crlf io.streams.limited io.streams.string
+kernel math math.parser multiline namespaces peg sequences splitting
+tools.test urls ;
 IN: http.server.requests.tests
 
-: normalize-nl ( str -- str' )
-    "\n" "\r\n" replace ;
-
 : request>string ( request -- string )
     [ write-request ] with-string-writer ;
 
@@ -59,7 +57,7 @@ hello
           "form-data; name=\"text\"; filename=\"upload.txt\"" }
     }
 } [
-    test-multipart/form-data normalize-nl string>request
+    test-multipart/form-data lf>crlf string>request
     post-data>> params>> "text" of [ filename>> ] [ headers>> ] bi
 ] unit-test
 
@@ -142,8 +140,7 @@ hello
         { redirects 10 }
     }
 ] [
-    "\r\n\r\n\r\nGET / HTTP/1.0\r\n\r\n"
-    [ read-request ] with-string-reader
+    "\r\n\r\n\r\nGET / HTTP/1.0\r\n\r\n" [ read-request ] with-string-reader
 ] unit-test
 
 ! RFC 2616: Section 19.3
@@ -157,5 +154,5 @@ hello
         "host: 127.0.0.1:55532"
         "user-agent: Factor http.client"
     } [ "\n" join ] [ "\r\n" join ] bi
-    [ [ read-request ] with-string-reader ] same?
+    [ string>request ] same?
 ] unit-test
index 780a32d5017cf44bca95eaa11539f12f33e20d9b..821d3a79312f86a36d28d9525509c72e3c01a542 100644 (file)
@@ -11,3 +11,6 @@ USING: io.crlf tools.test io.streams.string io ;
 [ f ] [ "" [ read-?crlf ] with-string-reader ] unit-test
 [ "" ] [ "\n" [ read-?crlf ] with-string-reader ] unit-test
 [ "foo" ] [ "foo\n" [ read-?crlf ] with-string-reader ] unit-test
+
+[ "foo\nbar" ] [ "foo\n\rbar" crlf>lf ] unit-test
+[ "foo\r\nbar" ] [ "foo\nbar" lf>crlf ] unit-test
index 25319200cde6ca6e4271e568bf45791c1f4f2443..f68c763422283a5b7a3285de7cf6a153a30c1d74 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2009 Daniel Ehrenberg, Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
-USING: io kernel sequences ;
+USING: io kernel sequences splitting ;
 IN: io.crlf
 
 : crlf ( -- )
@@ -13,3 +13,9 @@ IN: io.crlf
 : read-?crlf ( -- seq )
     "\r\n" read-until
     [ CHAR: \r = [ read1 CHAR: \n assert= ] when ] [ f like ] if* ;
+
+: crlf>lf ( str -- str' )
+    CHAR: \r swap remove ;
+
+: lf>crlf ( str -- str' )
+    "\n" split "\r\n" join ;
index 563ab5e44dc1cb422f7954293aef5777f6f84e49..03fb92bcfd8789de72722f5bf89522038fd38c83 100755 (executable)
@@ -10,7 +10,7 @@ windows.kernel32 windows.gdi32 windows.user32 windows.opengl32
 windows.messages windows.types windows.offscreen windows threads
 libc combinators fry combinators.short-circuit continuations
 command-line shuffle opengl ui.render math.bitwise locals
-accessors math.rectangles math.order calendar ascii sets
+accessors math.rectangles math.order calendar ascii sets io.crlf
 io.encodings.utf16n windows.errors literals ui.pixel-formats
 ui.pixel-formats.private memoize classes colors
 specialized-arrays classes.struct ;
@@ -172,12 +172,6 @@ PRIVATE>
 : GET_APPCOMMAND_LPARAM ( lParam -- appCommand )
     hi-word FAPPCOMMAND_MASK lo-word bitnot bitand ; inline
 
-: crlf>lf ( str -- str' )
-    CHAR: \r swap remove ;
-
-: lf>crlf ( str -- str' )
-    [ [ dup CHAR: \n = [ CHAR: \r , ] when , ] each ] "" make ;
-
 : enum-clipboard ( -- seq )
     0
     [ EnumClipboardFormats win32-error dup dup 0 > ]
@@ -209,7 +203,7 @@ PRIVATE>
         EmptyClipboard win32-error=0/f
         GMEM_MOVEABLE over length 1 + GlobalAlloc
             dup win32-error=0/f
-    
+
         dup GlobalLock dup win32-error=0/f
         rot binary-object memcpy
         dup GlobalUnlock win32-error=0/f
@@ -506,7 +500,7 @@ SYMBOL: nc-buttons
         { APPCOMMAND_BROWSER_FORWARD [ pick window right-action send-action ] }
         [ drop ]
     } case 3drop ;
-    
+
 : handle-wm-buttondown ( hWnd uMsg wParam lParam -- )
     [
         over set-capture
@@ -542,7 +536,7 @@ SYMBOL: nc-buttons
     4drop release-capture ;
 
 : handle-wm-mouseleave ( hWnd uMsg wParam lParam -- )
-    #! message sent if mouse leaves main application 
+    #! message sent if mouse leaves main application
     4drop forget-rollover ;
 
 : system-background-color ( -- color )
@@ -868,4 +862,3 @@ M: windows-ui-backend ui-backend-available?
     t ;
 
 windows-ui-backend ui-backend set-global
-