| ... | @@ -762,30 +762,19 @@ pub fn main() void { | ... | @@ -762,30 +762,19 @@ pub fn main() void { |
| 762 | Dereferencing string literals converts them to {#link|Arrays#}. | 762 | Dereferencing string literals converts them to {#link|Arrays#}. |
| 763 | </p> | 763 | </p> |
| 764 | <p> | 764 | <p> |
| 765 | The encoding of a string in Zig is de-facto assumed to be UTF-8. | 765 | Because Zig source code is {#link|UTF-8 encoded|Source Encoding#}, any |
| 766 | Because Zig source code is {#link|UTF-8 encoded|Source Encoding#}, any non-ASCII bytes appearing within a string literal | 766 | non-ASCII bytes appearing within a string literal in source code carry |
| 767 | in source code carry their UTF-8 meaning into the content of the string in the Zig program; | 767 | their UTF-8 meaning into the content of the string in the Zig program; |
| 768 | the bytes are not modified by the compiler. | 768 | the bytes are not modified by the compiler. It is possible to embed |
| 769 | However, it is possible to embed non-UTF-8 bytes into a string literal using <code>\xNN</code> notation. | 769 | non-UTF-8 bytes into a string literal using <code>\xNN</code> notation. |
| 770 | </p> | | |
| 771 | <p> | | |
| 772 | Indexing into a string containing non-ASCII bytes will return individual bytes, whether valid | | |
| 773 | UTF-8 or not. | | |
| 774 | The {#link|Zig Standard Library#} provides routines for checking the validity of UTF-8 encoded | | |
| 775 | strings, accessing their code points and other encoding/decoding related tasks in | | |
| 776 | {#syntax#}std.unicode{#endsyntax#}. | | |
| 777 | </p> | 770 | </p> |
| | 771 | <p>Indexing into a string containing non-ASCII bytes returns individual |
| | 772 | bytes, whether valid UTF-8 or not.</p> |
| 778 | <p> | 773 | <p> |
| 779 | Unicode code point literals have type {#syntax#}comptime_int{#endsyntax#}, the same as | 774 | Unicode code point literals have type {#syntax#}comptime_int{#endsyntax#}, the same as |
| 780 | {#link|Integer Literals#}. All {#link|Escape Sequences#} are valid in both string literals | 775 | {#link|Integer Literals#}. All {#link|Escape Sequences#} are valid in both string literals |
| 781 | and Unicode code point literals. | 776 | and Unicode code point literals. |
| 782 | </p> | 777 | </p> |
| 783 | <p> | | |
| 784 | In many other programming languages, a Unicode code point literal is called a "character literal". | | |
| 785 | However, there is <a href="https://unicode.org/glossary">no precise technical definition of a "character"</a> | | |
| 786 | in recent versions of the Unicode specification (as of Unicode 13.0). | | |
| 787 | In Zig, a Unicode code point literal corresponds to the Unicode definition of a code point. | | |
| 788 | </p> | | |
| 789 | {#code_begin|exe|string_literals#} | 778 | {#code_begin|exe|string_literals#} |
| 790 | const print = @import("std").debug.print; | 779 | const print = @import("std").debug.print; |
| 791 | const mem = @import("std").mem; // will be used to compare bytes | 780 | const mem = @import("std").mem; // will be used to compare bytes |