Skip to content
Draft

Rust #37

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
all:
+$(MAKE) -C python
+$(MAKE) -C js
+$(MAKE) -C rust
+$(MAKE) -C docs html

deps:
+$(MAKE) -C python deps
+$(MAKE) -C js deps
+$(MAKE) -C rust deps
+$(MAKE) -C docs deps

check:
+$(MAKE) -C python check
+$(MAKE) -C js check
+$(MAKE) -C rust check
+$(MAKE) -C docs doctest

clean:
+$(MAKE) -C python clean
+$(MAKE) -C js clean
+$(MAKE) -C rust clean
+$(MAKE) -C docs clean

.PHONY: all deps check clean
6 changes: 4 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ For example:
Languages
---------

|PyPI version| |npm version|
|PyPI version| |npm version| |crates.io version|

bistring is available in multiple languages, currently `Python <python>`_ and `JavaScript/TypeScript <js>`_.
bistring is available in multiple languages, currently `Python <python>`_, `JavaScript/TypeScript <js>`_, and `Rust <rust>`_.
Ports to other languages are planned for the near future.

The code is structured similarly in each language to make it easy to share algorithms, tests, and fixes between them.
Expand Down Expand Up @@ -65,3 +65,5 @@ For more information see the `Code of Conduct FAQ <https://opensource.microsoft.
:target: https://pypi.org/project/bistring/
.. |npm version| image:: https://badge.fury.io/js/bistring.svg
:target: https://www.npmjs.com/package/bistring
.. |crates.io version| image:: https://img.shields.io/crates/v/bistring
:target: https://crates.io/crates/bistring
10 changes: 10 additions & 0 deletions rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Generated by Cargo
# will have compiled files and executables
/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk
15 changes: 15 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "bistring"
version = "0.5.0"
authors = ["Tavian Barnes <[email protected]>"]
edition = "2018"
description = "Bidirectionally transformed strings"
readme = "README.md"
repository = "https://github.com/microsoft/bistring"
license = "MIT"
keywords = ["string", "text", "nlp"]
categories = ["text-processing", "data-structures"]

[dependencies]

[dev-dependencies]
13 changes: 13 additions & 0 deletions rust/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
all:
cargo build

deps:
cargo fetch

check:
cargo test

clean:
cargo clean

.PHONY: all deps check clean
27 changes: 27 additions & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
bistring
========

[![crates.io version](https://img.shields.io/crates/v/bistring)](https://crates.io/crates/bistring)

The bistring library provides non-destructive versions of common string processing operations like normalization, case folding, and find/replace.
Each bistring remembers the original string, and how its substrings map to substrings of the modified version.

For example:

```rust
use bistring::BiString;

let mut s = BiString::from("𝕿𝖍𝖊 𝖖𝖚𝖎𝖈𝖐, 𝖇𝖗𝖔𝖜𝖓 🦊 𝖏𝖚𝖒𝖕𝖘 𝖔𝖛𝖊𝖗 𝖙𝖍𝖊 𝖑𝖆𝖟𝖞 🐶");
s = s.nfkd(); // Unicode normalization
s = s.casefold(); // Case-insensitivity
s = s.replace("🦊", "fox"); // Replace emoji with text
s = s.replace("🐶", "dog");
s = s.replace(/[^\w\s]+/g, ""); // Strip everything but letters and spaces
let slice = &s[..19]; // Extract a substring
// The modified substring, after changes
assert_eq!(slice.modified(), "the quick brown fox");
// The original substring, before changes
assert_eq!(slice.original(), "𝕿𝖍𝖊 𝖖𝖚𝖎𝖈𝖐, 𝖇𝖗𝖔𝖜𝖓 🦊");
```

This allows you to perform very aggressive text processing completely invisibly.
Loading