Skip to main content

chordsketch_core/
lib.rs

1//! ChordPro parser, AST definitions, and transforms.
2
3pub mod abc_importer;
4pub mod ast;
5pub mod chord;
6pub mod chord_diagram;
7pub mod config;
8pub mod escape;
9#[cfg(not(target_arch = "wasm32"))]
10pub mod external_tool;
11pub mod formatter;
12pub mod heuristic;
13pub mod image_path;
14pub mod inline_markup;
15pub mod lexer;
16pub mod parser;
17pub mod render_result;
18pub mod rrjson;
19pub mod selector;
20pub mod token;
21pub mod transpose;
22pub mod voicings;
23
24// Re-export key types for convenience.
25pub use abc_importer::convert_abc;
26pub use chord::{Accidental, ChordDetail, ChordQuality, Note, parse_chord};
27pub use chord_diagram::{canonical_chord_name, resolve_diagrams_instrument};
28// Aliased as `format_chordpro` to avoid ambiguity with the `format!` macro at
29// call sites that use glob imports.
30pub use formatter::{FormatOptions, format as format_chordpro};
31pub use heuristic::{
32    InputFormat, PlainTextImporter, convert_plain_text, detect_format, song_to_chordpro,
33};
34pub use lexer::Lexer;
35pub use parser::{
36    MultiParseResult, ParseError, ParseOptions, ParseResult, Parser, parse, parse_image_attributes,
37    parse_lenient, parse_lenient_with_options, parse_multi, parse_multi_lenient,
38    parse_multi_lenient_with_options, parse_multi_with_options, parse_with_options,
39};
40pub use render_result::RenderResult;
41pub use token::{Position, Span, Token, TokenKind};
42pub use voicings::{
43    guitar_voicing, keyboard_voicing, lookup_diagram, lookup_keyboard_voicing, ukulele_voicing,
44};
45
46/// Returns the library version.
47#[must_use]
48pub fn version() -> &'static str {
49    env!("CARGO_PKG_VERSION")
50}
51
52/// Capitalize the first character of a string.
53///
54/// Returns a new string with the first character uppercased and the
55/// rest unchanged. Returns an empty string for empty input.
56#[must_use]
57pub fn capitalize(s: &str) -> String {
58    let mut chars = s.chars();
59    match chars.next() {
60        None => String::new(),
61        Some(c) => c.to_uppercase().to_string() + chars.as_str(),
62    }
63}
64
65#[cfg(test)]
66mod tests {
67    use super::*;
68
69    #[test]
70    fn test_version() {
71        assert_eq!(version(), env!("CARGO_PKG_VERSION"));
72    }
73}