feature. See also
. The project being documented here (as the example) is the Zig library itself.
disjoint_code_page.hasDisjointCodePage
pub fn hasDisjointCodePage(source: []const u8, source_mappings: ?*const SourceMappings, default_code_page: SupportedCodePage) bool
File
Code
pub fn hasDisjointCodePage(source: []const u8, source_mappings: ?*const SourceMappings, default_code_page: SupportedCodePage) bool {
var line_handler = lex.LineHandler{ .buffer = source };
var i: usize = 0;
while (i < source.len) {
const codepoint = default_code_page.codepointAt(i, source) orelse break;
const c = codepoint.value;
switch (c) {
'\r', '\n' => {
_ = line_handler.incrementLineNumber(i);
if (source_mappings != null and !source_mappings.?.isRootFile(line_handler.line_number)) return false;
},
' ',
'\t',
// due to a (misguided) special casing in the lexer, see the TODO in lex.zig
'\u{A0}',
=> {},
// means they are trimmed from the file during preprocessing. This means that these characters
// should be treated like ' ', '\t' above, but since the resinator preprocessor does not treat
// them as whitespace *or* trim whitespace, files with these characters are likely going to
// error. So, in the future some sort of emulation of/rejection of the Win32 behavior might
// make handling these codepoints specially make sense, but for now it doesn't really matter
// so they are not handled specially for simplicity's sake.
//'\u{1680}',
//'\u{180E}',
//'\u{2001}',
//'\u{2002}',
//'\u{2003}',
//'\u{2004}',
//'\u{2005}',
//'\u{2006}',
//'\u{2007}',
//'\u{2008}',
//'\u{2009}',
//'\u{200A}',
//'\u{2028}',
//'\u{2029}',
//'\u{202F}',
//'\u{205F}',
//'\u{3000}',
'#' => {
if (source_mappings != null and !source_mappings.?.isRootFile(line_handler.line_number)) {
return false;
}
const start_i = i;
while (i < source.len and source[i] != '\r' and source[i] != '\n') : (i += 1) {}
const line = source[start_i..i];
_ = (lex.parsePragmaCodePage(line) catch |err| switch (err) {
error.NotPragma => return false,
error.NotCodePagePragma => continue,
error.CodePagePragmaUnsupportedCodePage => continue,
else => continue,
}) orelse return false;
// If we got a code page, then it is a disjoint code page pragma
return true;
},
else => {
return false;
},
}
i += codepoint.byte_len;
}
return false;
}