Giter Club home page Giter Club logo

cstrs's Introduction

CST Parser

GitHub Workflow Status (branch)GitHub commit activityCaret-Separated Text (or CST) is a key-value pair format represented by digits or words as keys and the value as text enclosed between carets. (e.g. <key> ^<text>^) Any text which is not enclosed with carets is considered a comment and ignored. Neither strings nor comments may use the caret character. CST.NET is a library for parsing the CST format.

Requirements

Installation

[dependencies]
cst = "0.1"

Development

[dependencies]
cst = { git = "https://github.com/tonytins/cst.rs", branch = "develop" }

Usage

Basic Parsing

At it's core, CST.rs uses the get_entry() function to parse the CST format.

use cst::get_entry;

fn main() {
  let input = "1 ^The quick brown fox jumps over the lazy dog.^";
  let expect = "The quick brown fox jumps over the lazy dog.";
  let entry = get_entry(input, 1);

  assert_eq!(entry.unwrap(), expect);
}

In Production

Based on FreeSO's APIs, the UIText struct takes care of the heavy lifting of locating and parsing CST files.

use cst::UIText;

fn main() {
  let expect = "The quick brown fox jumps over the lazy dog.";
  let ui_text = UIText::new("example"); // uitext/example.dir
  let entry = ui_text.get_text(101, 1); // Entry 1 of _101_[name].cst

  assert_eq!(entry.unwrap(), expect);
}

The Sims Online required each translation file be prefixed with a number and underscores, known as the ID, that are located in uitext/[language].dir. The IDs were used to locate the file, regardless the name. CST.rs follows this convention because it's the only known use of the format.

  • uitext/english.dir/_154_miscstrings.cst
  • uitext/swedish.dir/_154_miscstrings.cst

Note that that UIText struct is simply a wrapper around the the above mentioned get_entry() function.

Examples

More complex stuff can be found in the examples directory.

To-do

  • Target Rust 2024 Edition

License

This project is dual-licensed under the MIT or Apache-2.0.

cstrs's People

Contributors

tonytins avatar

Stargazers

 avatar

cstrs's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.