@@ -8,7 +8,9 @@ that provides a string representation of any underlying array of bytes
88
99Unlike Julia's built-in ` String ` type (which also wraps UTF-8 data), the
1010` StringView ` type is a copy-free wrap of * any* ` AbstractVector{UInt8} `
11- instance, and does not take "ownership" of or modify the array. Otherwise,
11+ instance, and does not take "ownership" of or modify the array.
12+ You can also use ` StringView(buf) ` with a ` buf::IOBuffer ` , as
13+ a non-destructive alternative to ` String(take!(buf)) ` . Otherwise,
1214a ` StringView ` is intended to be usable in any context where you might
1315have otherwise used ` String ` .
1416
@@ -36,6 +38,25 @@ julia> abc = StringView(0x61:0x63) # and for other array types
3638" abc"
3739```
3840
41+ Or, with an ` IOBuffer ` :
42+
43+ ``` jl
44+ julia> buf = IOBuffer ();
45+
46+ julia> write (buf, b);
47+
48+ julia> print (buf, " baz" )
49+
50+ julia> StringView (buf) # does not modify buf
51+ " foobarbaz"
52+
53+ julia> String (take! (buf)) # clears buf
54+ " foobarbaz"
55+
56+ julia> StringView (buf) # now empty
57+ " "
58+ ```
59+
3960Other optimized (copy-free) operations include I/O, hashing, iteration/indexing,
4061comparisons, parsing, searching, and validation. Working with a ` SubString ` of
4162a ` StringView ` is similarly efficient.
0 commit comments