authorgravatar for 77922942+expikr@users.noreply.github.comexpikr <77922942+expikr@users.noreply.github.com> 2023-11-21 19:54:13+08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-11-21 13:54:13+02:00
log27353bb936a161e6a09f1424ce38bf84e78e94e4
treef4431f9e345f4331d21585d047cf18ee67fd5499
parent15a6b279571a02b5b31451c0200d09578ea99995
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

langref: emphasize the use of dereferencing string literals


1 files changed, 10 insertions(+), 1 deletions(-)

doc/langref.html.in+10-1
...@@ -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#} and900 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#}
907test {
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 literal915 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;