I have to apologize. I think I’ve made it more confusing.
Definitions
- String Literal: literals that are enclosed with double quotes e.g `“へぅえ?”
- Unicode Literal: literals that are enclosed with single quotes e.g ‘啊’. This can be confused with “characters” in other languages (Like C), but it’s best not to think of them that way, as characters are not a good abstraction over unicode.
What is a string literal
As @dee0xeed points out, a string literal caries the type *const [N:0]u8
, where N is the number of bytes in the string. In shorthand we can consider them to be arrays or slices of u8’s.
What is a unicode literal
As you have found out, a unicode literal is really just a comptime_int, meaning it’s exact representation is determined at comptime based of what size will be needed. Based of the standard, a unicode literal can always fit in a u21,
Original Question
pub const cyrillic_abc = [_]u16{ 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я', 'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я' }
These values are all unicode literals, but since they only need 2 bytes to be represented, you can store them in an array of u16 (hence the type: [_]u16
).
"йил"
This is a String Literal. Even though it is made up of “characters” that require more than 1 byte to represent, they can be represented as an array of bytes
indeed another way to write this is:
[_]u8{ 208, 185, 208, 184, 208, 187 }
you can verify this by running the following:
const std = @import("std");
pub fn main() !void {
const text = [_]u8{208, 185, 208, 184, 208, 187 };
std.debug.print("{s}\n", .{text});
std.debug.print("{d}\n", .{text});
}
> zig build-exe test.zig && ./test
йил
{ 208, 185, 208, 184, 208, 187 }
So finally:
[_][]const u8{ "январ", "феврал", "март", "апрел", "май", "июн", "июл", "август", "сентябр", "октябр", "ноябр", "декабр", "йил" }
This is an array or slices (notice the two pairs of brakets [_][]const u8
). Simply you have an array of string literals. (technically they are slices that point to the string literals).