mod grammar;
mod kind;
mod lexer;
mod parser;
mod parser_error;
mod probes;
mod symbols;
mod syntax;
mod text;
pub use grammar::doc::{
DocCommandArgs, DocCommandKind, DocCommandSpec, DocLink, DocReference, command_args,
command_kind, doc_links, doc_references, every_command,
};
pub use kind::*;
pub use lexer::{
CppLexer, CppTokenData, DocCommentStyle, DocToken, DocTokenKind, LexerConfig, is_block_comment,
is_doc_whitespace, is_documentation_comment, lex, lex_comment, lex_first,
};
pub use parser::{Checkpoint, CppParser, EventStreamAudit, MarkEvent, ParserConfig};
pub use parser_error::{CppParseError, CppParseErrorKind};
pub use symbols::{
BODY_CHAIN_LIMIT, BodyFacts, BodyShape, DefinitionFacts, InForceBody, IncludedMacro,
MacroBodies, MacroBody, MacroEnvironment, MacroFacts, NoSymbols, NothingAtAll, SymbolKind,
SymbolMap, SymbolTable, a_body_opens_an_inline_namespace, shape_of_a_body, shape_of_a_body_at,
};
pub use syntax::*;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub use text::{LineIndex, Reader, SourceRange};
#[macro_use]
extern crate rust_i18n;
rust_i18n::i18n!("./locales", fallback = "en");
pub fn set_locale(locale: &str) {
rust_i18n::set_locale(&normalise_locale(locale));
}
pub fn normalise_locale(locale: &str) -> String {
let trimmed = locale.trim().replace('_', "-");
let mut parts = trimmed.split('-');
let Some(language) = parts.next() else {
return String::from("en");
};
if language.is_empty() {
return String::from("en");
}
let mut normalised = language.to_ascii_lowercase();
if let Some(region) = parts.next()
&& !region.is_empty()
{
normalised.push('-');
normalised.push_str(®ion.to_ascii_uppercase());
}
normalised
}
pub use kind::features;
#[cfg(test)]
mod locale_tests {
use super::normalise_locale;
#[test]
fn a_locale_tag_is_normalised_to_the_name_of_its_file() {
for (written, expected) in [
("zh-CN", "zh-CN"),
("zh-cn", "zh-CN"),
("zh_CN", "zh-CN"),
("ZH-CN", "zh-CN"),
("en", "en"),
("en-US", "en-US"),
("pt_BR", "pt-BR"),
("ja", "ja"),
("", "en"),
(" ", "en"),
] {
assert_eq!(normalise_locale(written), expected, "{written:?}");
}
}
}