A parser for Minecraft's legacy formatting system, created with careful attention to the quirks of the vanilla client's implementation.
#![no_std]
usage (with default-features
set to false
)STRIKETHROUGH
style)Span
s to the terminal§
while many community tools use &
)Using SpanIter
:
```rust use mclegacyformatting::{SpanIter, Span, Color, Styles};
let s = "§4This will be dark red §oand italic"; let mut span_iter = SpanIter::new(s);
asserteq!(spaniter.next().unwrap(), Span::newstyled("This will be dark red ", Color::DarkRed, Styles::empty())); asserteq!(spaniter.next().unwrap(), Span::newstyled("and italic", Color::DarkRed, Styles::ITALIC)); assert!(spaniter.next().isnone()); ```
With a custom start character:
```rust use mclegacyformatting::{SpanIter, Span, Color, Styles};
let s = "&6It's a lot easier to type &b& &6than &b§"; let mut spaniter = SpanIter::new(s).withstart_char('&');
asserteq!(spaniter.next().unwrap(), Span::newstyled("It's a lot easier to type ", Color::Gold, Styles::empty())); asserteq!(spaniter.next().unwrap(), Span::newstyled("& ", Color::Aqua, Styles::empty())); asserteq!(spaniter.next().unwrap(), Span::newstyled("than ", Color::Gold, Styles::empty())); asserteq!(spaniter.next().unwrap(), Span::newstyled("§", Color::Aqua, Styles::empty())); assert!(spaniter.next().isnone()); ```
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.