sgf-tool

Crates.iosgf-tool
lib.rssgf-tool
version1.0.4
sourcesrc
created_at2024-01-19 21:46:56.603575
updated_at2024-01-20 14:46:16.021749
descriptionSGF Tool
homepage
repositoryhttps://github.com/erhanbaris/sgf-tool
max_upload_size
id1105767
size38,277
Erhan Barış (Ruslan Ognyanov Asenov) (erhanbaris)

documentation

https://docs.rs/sgf-tool

README

SGF-TOOL

Build & Test Latest Version Rust Documentation Crates.io Crates.io

SGF file format parser and builder.

Reference: https://red-bean.com/sgf/sgf4.html

Examples

use std::borrow::Cow;
use sgf_tool::*;

fn main() -> Result<(), SgfToolError> {
    // Parse sgf
    let source = "(;FF[4];C[root];SZ[19];B[aa];W[ab])";
    let base = parse(&source)?;

    for token in base.tokens.iter() {
        println!("Token: {:?}", token);
    }

    // Or

    assert_eq!(base.get(TokenType::FileFormat), Some(Cow::Owned(Token::FileFormat(4))).as_ref());

    /* Rebuild sgf and validage */
    let mut buffer = String::new();
    base.build(&mut buffer)?;
    assert_eq!(buffer, source);

    // Build sgf
    let mut base = sgf_tool::Base::default();
    base.add_token(Token::Application("sgf-tool"));
    base.add_token(Token::BlackMove(Move::Move(Point("ab"))));
    base.add_token(Token::WhiteMove(Move::Move(Point("bc"))));
    base.add_token(Token::BlackMove(Move::Pass));

    assert_eq!("(;AP[sgf-tool];B[ab];W[bc];B[])", &build(base)?);
    Ok(())
}
Commit count: 0

cargo fmt