Rust Parser for The Sims Online's CST format.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Tony Bark 7ccaaa292f
Some checks failed
Rust / check (push) Has been cancelled
Rust / test (windows-latest) (push) Has been cancelled
Rust / test (macos-latest) (push) Has been cancelled
Rust / test (ubuntu-latest) (push) Has been cancelled
Manifest fix
2023-10-28 14:21:04 -04:00
.github If check fails, do not continue 2023-10-28 12:10:52 -04:00
.vscode Restructured workflow 2023-10-28 11:54:40 -04:00
examples Use options to handle return values 2022-07-22 05:47:39 -04:00
src Restructured workflow 2023-10-28 11:54:40 -04:00
uitext Updated docs and examples 2022-07-22 05:59:15 -04:00
.gitignore Initial commit 2022-07-21 11:08:37 -04:00
Cargo.toml Manifest fix 2023-10-28 14:21:04 -04:00
code_of_conduct.md Docs, badges and code of conduct 2022-07-21 19:24:07 -04:00
example.cst Test comments and large texts 2022-07-21 16:06:08 -04:00
LICENSE-APACHE Re-licensed to APACHE and MIT 2023-10-28 11:24:14 -04:00
LICENSE-MIT Re-licensed to APACHE and MIT 2023-10-28 11:24:14 -04:00
README.md Manifest fix 2023-10-28 14:21:04 -04:00

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.