Skip to content

Commit

Permalink
Merge pull request #3 from timothee-haudebourg/fix-readme
Browse files Browse the repository at this point in the history
Fix README links.
  • Loading branch information
timothee-haudebourg authored Oct 20, 2022
2 parents ccca814 + 71a205a commit 43d3a06
Show file tree
Hide file tree
Showing 21 changed files with 666 additions and 577 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
patreon: thaudebourg
60 changes: 60 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: CI

on: [push, pull_request]

env:
CARGO_TERM_COLORS: always

jobs:
test:
name: Test Suite
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
rustfmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
components: rustfmt
- name: Check formatting
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
components: clippy
- name: Clippy Check
uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
1 change: 1 addition & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hard_tabs = true
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "langtag"
version = "0.2.0"
version = "0.3.2"
authors = ["Timothée Haudebourg <author@haudebourg.net>"]
edition = "2018"
categories = ["parsing", "data-structures"]
Expand Down
45 changes: 21 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,52 @@
# Language Tags

<table><tr>
<td><a href="https://docs.rs/langtag">Documentation</a></td>
<td><a href="https://crates.io/crates/langtag">Crate informations</a></td>
<td><a href="https://github.com/timothee-haudebourg/langtag">Repository</a></td>
</tr></table>
[![CI](https://github.com/timothee-haudebourg/langtag/workflows/CI/badge.svg)](https://github.com/timothee-haudebourg/langtag/actions)
[![Crate informations](https://img.shields.io/crates/v/langtag.svg?style=flat-square)](https://crates.io/crates/langtag)
[![License](https://img.shields.io/crates/l/langtag.svg?style=flat-square)](https://github.com/timothee-haudebourg/langtag#license)
[![Documentation](https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square)](https://docs.rs/langtag)

This crate provides an implementation of *language tags* defined by
[RFC5646](https://tools.ietf.org/html/rfc5646) ([BCP47](https://tools.ietf.org/html/bcp47)).

## Usage
### Usage

You can easily parse new language from anything that provides a `[u8]` reference:
```rust
extern crate langtag;
use langtag::LanguageTag;

fn main() -> Result<(), langtag::Error> {
let tag = LanguageTag::parse("fr-FR")?;
assert_eq!(tag.language().unwrap().primary(), "fr");
assert!(tag == "Fr-fr"); // comparison is case-insensitive.
Ok(())
let tag = LanguageTag::parse("fr-FR")?;
assert_eq!(tag.language().unwrap().primary(), "fr");
assert!(tag == "Fr-fr"); // comparison is case-insensitive.
Ok(())
}
```

Note that [`LanguageTag::parse`][1] does *not* copy the data it is given,
Note that [`LanguageTag::parse`] does *not* copy the data it is given,
but only borrows it.
You can create an owning `LanguageTag` instance by using
[`LanguageTagBuf::parse_copy`][2] instead.
[`LanguageTagBuf::parse_copy`] to copy the data,
or simply [`LanguageTagBuf::new`] to move the data.

Once parsed, you can exlore every component of the language tag using the provided functions.
Once parsed, you can explore every component of the language tag using the provided functions.

[1]: https://docs.rs/langtag/latest/langtag/enum.LanguageTag.html#method.parse
[2]: https://docs.rs/langtag/latest/langtag/enum.LanguageTagBuf.html#method.parse_copy

### Mutable language tags
#### Mutable language tags

When the language tags owns its buffer through `Vec<u8>`,
it becomes possible to access the tag mutabily to modify it.
it becomes possible to access the tag mutably to modify it.
```rust
extern crate langtag;
use std::convert::TryInto;
use langtag::LangTag;

fn main() -> Result<(), langtag::Error> {
let mut tag = LangTag::parse_copy("fr-FR")?;
tag.language_mut().set_primary("jp".try_into()?);
tag.set_region(None);
tag.extensions_mut().insert('f'.try_into()?, "bar".try_into()?);
assert_eq!(tag, "jp-f-bar");
Ok(())
let mut tag = LangTag::parse_copy("fr-FR")?;
tag.language_mut().set_primary("jp".try_into()?);
tag.set_region(None);
tag.extensions_mut().insert('f'.try_into()?, "bar".try_into()?);
assert_eq!(tag, "jp-f-bar");
Ok(())
}
```

Expand Down
23 changes: 23 additions & 0 deletions README.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Language Tags

[![CI](https://github.com/timothee-haudebourg/{{crate}}/workflows/CI/badge.svg)](https://github.com/timothee-haudebourg/{{crate}}/actions)
[![Crate informations](https://img.shields.io/crates/v/{{crate}}.svg?style=flat-square)](https://crates.io/crates/{{crate}})
[![License](https://img.shields.io/crates/l/{{crate}}.svg?style=flat-square)](https://github.com/timothee-haudebourg/{{crate}}#license)
[![Documentation](https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square)](https://docs.rs/{{crate}})

{{readme}}

## License

Licensed under either of

* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
additional terms or conditions.
6 changes: 3 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub enum Error {
InvalidRegion,
InvalidScript,
InvalidVariant,
InvalidVariants
InvalidVariants,
}

impl fmt::Display for Error {
Expand All @@ -42,7 +42,7 @@ impl fmt::Display for Error {
InvalidRegion => write!(f, "invalid region subtag"),
InvalidScript => write!(f, "invalid script subtag"),
InvalidVariant => write!(f, "invalid variant subtag"),
InvalidVariants => write!(f, "invalid variants")
InvalidVariants => write!(f, "invalid variants"),
}
}
}
}
Loading

0 comments on commit 43d3a06

Please sign in to comment.