| ... | @@ -899,9 +899,18 @@ pub fn main() void { | ... | @@ -899,9 +899,18 @@ pub fn main() void { |
| 899 | The type of string literals encodes both the length, and the fact that they are null-terminated, | 899 | The type of string literals encodes both the length, and the fact that they are null-terminated, |
| 900 | and thus they can be {#link|coerced|Type Coercion#} to both {#link|Slices#} and | 900 | and thus they can be {#link|coerced|Type Coercion#} to both {#link|Slices#} and |
| 901 | {#link|Null-Terminated Pointers|Sentinel-Terminated Pointers#}. | 901 | {#link|Null-Terminated Pointers|Sentinel-Terminated Pointers#}. |
| 902 | Dereferencing string literals converts them to {#link|Arrays#}. | | |
| 903 | </p> | 902 | </p> |
| 904 | <p> | 903 | <p> |
| | 904 | Dereferencing string literals converts them to {#link|Arrays#}, allowing you to initialize a buffer with the contents of a string literal. |
| | 905 | </p> |
| | 906 | {#code_begin|syntax|mutable_string_buffer#} |
| | 907 | test { |
| | 908 | var buffer = [_]u8{0}**256; |
| | 909 | const home_dir = "C:/Users/root"; |
| | 910 | buffer[0..home_dir.len].* = home_dir.*; |
| | 911 | } |
| | 912 | {#code_end#} |
| | 913 | <p> |
| 905 | The encoding of a string in Zig is de-facto assumed to be UTF-8. | 914 | The encoding of a string in Zig is de-facto assumed to be UTF-8. |
| 906 | Because Zig source code is {#link|UTF-8 encoded|Source Encoding#}, any non-ASCII bytes appearing within a string literal | 915 | Because Zig source code is {#link|UTF-8 encoded|Source Encoding#}, any non-ASCII bytes appearing within a string literal |
| 907 | in source code carry their UTF-8 meaning into the content of the string in the Zig program; | 916 | in source code carry their UTF-8 meaning into the content of the string in the Zig program; |