@@ -8,7 +8,9 @@ that provides a string representation of any underlying array of bytes
8
8
9
9
Unlike Julia's built-in ` String ` type (which also wraps UTF-8 data), the
10
10
` 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,
12
14
a ` StringView ` is intended to be usable in any context where you might
13
15
have otherwise used ` String ` .
14
16
@@ -36,6 +38,25 @@ julia> abc = StringView(0x61:0x63) # and for other array types
36
38
" abc"
37
39
```
38
40
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
+
39
60
Other optimized (copy-free) operations include I/O, hashing, iteration/indexing,
40
61
comparisons, parsing, searching, and validation. Working with a ` SubString ` of
41
62
a ` StringView ` is similarly efficient.
0 commit comments