From 27353bb936a161e6a09f1424ce38bf84e78e94e4 Mon Sep 17 00:00:00 2001 From: expikr <77922942+expikr@users.noreply.github.com> Date: Tue, 21 Nov 2023 19:54:13 +0800 Subject: [PATCH] langref: emphasize the use of dereferencing string literals --- doc/langref.html.in | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/langref.html.in b/doc/langref.html.in index 41cd06a4a6..f3af17aa30 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -899,9 +899,18 @@ pub fn main() void { The type of string literals encodes both the length, and the fact that they are null-terminated, and thus they can be {#link|coerced|Type Coercion#} to both {#link|Slices#} and {#link|Null-Terminated Pointers|Sentinel-Terminated Pointers#}. - Dereferencing string literals converts them to {#link|Arrays#}.
+ Dereferencing string literals converts them to {#link|Arrays#}, allowing you to initialize a buffer with the contents of a string literal. +
+ {#code_begin|syntax|mutable_string_buffer#} +test { + var buffer = [_]u8{0}**256; + const home_dir = "C:/Users/root"; + buffer[0..home_dir.len].* = home_dir.*; +} + {#code_end#} +The encoding of a string in Zig is de-facto assumed to be UTF-8. Because Zig source code is {#link|UTF-8 encoded|Source Encoding#}, any non-ASCII bytes appearing within a string literal in source code carry their UTF-8 meaning into the content of the string in the Zig program;