| ... | ... | @@ -762,30 +762,19 @@ pub fn main() void { |
| 762 | 762 | Dereferencing string literals converts them to {#link|Arrays#}. |
| 763 | 763 | </p> |
| 764 | 764 | <p> |
| 765 | | The encoding of a string in Zig is de-facto assumed to be UTF-8. |
| 766 | | Because Zig source code is {#link|UTF-8 encoded|Source Encoding#}, any non-ASCII bytes appearing within a string literal |
| 767 | | in source code carry their UTF-8 meaning into the content of the string in the Zig program; |
| 768 | | the bytes are not modified by the compiler. |
| 769 | | However, it is possible to embed 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#}. |
| 765 | Because Zig source code is {#link|UTF-8 encoded|Source Encoding#}, any |
| 766 | non-ASCII bytes appearing within a string literal in source code carry |
| 767 | their UTF-8 meaning into the content of the string in the Zig program; |
| 768 | the bytes are not modified by the compiler. It is possible to embed |
| 769 | non-UTF-8 bytes into a string literal using <code>\xNN</code> notation. |
| 777 | 770 | </p> |
| 771 | <p>Indexing into a string containing non-ASCII bytes returns individual |
| 772 | bytes, whether valid UTF-8 or not.</p> |
| 778 | 773 | <p> |
| 779 | 774 | Unicode code point literals have type {#syntax#}comptime_int{#endsyntax#}, the same as |
| 780 | 775 | {#link|Integer Literals#}. All {#link|Escape Sequences#} are valid in both string literals |
| 781 | 776 | and Unicode code point literals. |
| 782 | 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 | 778 | {#code_begin|exe|string_literals#} |
| 790 | 779 | const print = @import("std").debug.print; |
| 791 | 780 | const mem = @import("std").mem; // will be used to compare bytes |