]> gitweb.factorcode.org Git - factor.git/commitdiff
byte-arrays: Add a byte-sequence protocol for byte-{array,vector}
authorDoug Coleman <doug.coleman@gmail.com>
Sat, 11 Jan 2020 23:31:32 +0000 (17:31 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Fri, 17 Jan 2020 00:18:46 +0000 (18:18 -0600)
Allow hexdumping strings as utf8 for convenience.

basis/tools/hexdump/hexdump.factor
basis/urls/encoding/encoding.factor
core/byte-arrays/byte-arrays.factor
core/byte-vectors/byte-vectors.factor

index a5c4bec6193783fec3acdfa8cbcf9fef7c1d65b9..c5bb93a7c937efa398f698bbdc1eed0ace77619a 100644 (file)
@@ -3,9 +3,9 @@
 
 USING: accessors ascii byte-arrays byte-vectors combinators
 command-line destructors fry io io.encodings io.encodings.binary
-io.files io.streams.string kernel literals locals math
-math.parser namespaces sequences sequences.private strings typed
-;
+io.encodings.string io.encodings.utf8 io.files io.streams.string
+kernel literals locals math math.parser namespaces sequences
+sequences.private strings typed ;
 
 IN: tools.hexdump
 
@@ -78,6 +78,9 @@ M: byte-array hexdump. all-bytes hexdump-bytes ;
 
 M: byte-vector hexdump. all-bytes underlying>> hexdump-bytes ;
 
+M: string hexdump. utf8 encode hexdump. ;
+
+
 : hexdump ( byte-array -- str )
     [ hexdump. ] with-string-writer ;
 
index 33db055b48a964b5fd2e75f16d9eb1cd252ed2e0..7927fd83aabb17f00178e57d3a1ba3c698efe01d 100644 (file)
@@ -43,7 +43,7 @@ IN: urls.encoding
 
 : (url-encode) ( str quot: ( ch -- ? ) -- encoded )
     [
-        over byte-array? [
+        over byte-sequence? [
             '[ dup @ [ , ] [ hex% ] if ] each
         ] [
             [ present ] dip
index 36a54b9515b96e4413b1ee24b23aa090185b61fd..ee7f5d660e1ed1b6caaba570e5e6495e30cbc24f 100644 (file)
@@ -7,6 +7,8 @@ IN: byte-arrays
 BUILTIN: byte-array
 { length array-capacity read-only initial: 0 } ;
 
+MIXIN: byte-sequence
+
 PRIMITIVE: (byte-array) ( n -- byte-array )
 PRIMITIVE: <byte-array> ( n -- byte-array )
 PRIMITIVE: resize-byte-array ( n byte-array -- new-byte-array )
@@ -27,6 +29,7 @@ M: byte-array resize
     resize-byte-array ; inline
 
 INSTANCE: byte-array sequence
+INSTANCE: byte-array byte-sequence
 
 : 1byte-array ( x -- byte-array ) B{ } 1sequence ; inline
 
index b53fd3866d7c3b306c8761a36bda3fd3c5c2f40c..faf2c0c0d8b72c4a61665b0ae034be42c77a5da6 100644 (file)
@@ -46,3 +46,4 @@ M: byte-array new-resizable drop <byte-vector> ; inline
 M: byte-vector new-resizable drop <byte-vector> ; inline
 
 INSTANCE: byte-vector growable
+INSTANCE: byte-vector byte-sequence