#typing #language #ime #african #lib #load #clafrica

deprecated clafrica-lib

This library contains a set of tools to make handling of clafrica code more convenient. NOTE: This crate was renamed to afrim-memory. Please use it under its new name

6 releases

0.3.2 Feb 7, 2024
0.3.1 Sep 16, 2023
0.3.0 Jun 3, 2023
0.2.0 May 8, 2023
0.1.1 Apr 28, 2023

#6 in #african


Used in 2 crates (via clafrica)

MIT license

12KB
235 lines

Clafrica Lib

clafrica-lib is a collection of utilities to make handling of clafrica code more convenient.

Example

use clafrica_lib::{text_buffer, utils};

// Build a TextBuffer
let root = text_buffer::Node::default();
root.insert(vec!['a', 'f'], "ɑ".to_owned());
root.insert(vec!['a', 'f', '1'], "ɑ̀".to_owned());

// Bulk insert of data in the TextBuffer
let data = vec![["af11", "ɑ̀ɑ̀"], ["?.", "ʔ"]];
utils::build_map(data);

// or directly from a file
let data = utils::load_data("data/sample.txt")
                  .expect("Failed to load the clafrica code file");
let data = data.iter()
               .map(|e| [e[0].as_str(), e[1].as_str()])
               .collect();

utils::build_map(data);

// Traverse the tree
let node = root.goto('a').and_then(|e| e.goto('f'));
assert_eq!(node.unwrap().take(), Some("ɑ".to_owned()));

// Test our cursor
let mut cursor = text_buffer::Cursor::new(root, 10);
let code = "af1";
code.chars().for_each(|c| {cursor.hit(c);});
assert_eq!(cursor.state(), (Some("ɑ̀".to_owned()), 3, '1'));
assert_eq!(cursor.undo(), Some("ɑ̀".to_owned()));

No runtime deps