-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DO NOT SUBMIT: ecma402 implementation.
- Loading branch information
Showing
15 changed files
with
548 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
target | ||
Cargo.lock | ||
tags | ||
target | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
authors = ["Google Inc."] | ||
default-features = false | ||
edition = "2018" | ||
keywords = ["ecma", "ecma402", "icu", "i18n", "l10n"] | ||
license = "Apache-2.0" | ||
name = "ecma402_traits" | ||
readme = "README.md" | ||
repository = "https://github.com/google/rust_icu" | ||
version = "0.1.0" | ||
|
||
description = """ | ||
Rust implementation of type traits to support ECMA 402 specification in Rust. | ||
""" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# WIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::fmt; | ||
|
||
/// This trait contains the common features of the Locale object that must be shared among | ||
/// all the implementations. Every implementor of `listformat` should provide their | ||
/// own version of [Locale], and should ensure that it implements [Locale]. as | ||
/// specified here. | ||
/// | ||
/// For the time being we agreed that a [Locale] *must* be convertible into its string | ||
/// form, using `Display`. | ||
pub trait Locale: fmt::Display {} | ||
|
||
/// A Rust implementation of ECMA 402 ListFormat API. | ||
/// | ||
/// The [listformat] mod contains all the needed implementation bits for `Intl.ListFormat`. | ||
/// | ||
pub mod listformat; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
#[test] | ||
fn it_works() { | ||
assert_eq!(2 + 2, 4); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/// Contains the API configuration as prescribed by ECMA 402. | ||
/// | ||
/// The meaning of the options is the same as in the similarly named | ||
/// options in the JS version. | ||
/// | ||
/// See [Options] for the contents of the options. See the [Format::try_new] | ||
/// for the use of the options. | ||
pub mod options { | ||
/// Chooses the list formatting approach. | ||
#[derive(Eq, PartialEq, Debug, Clone)] | ||
pub enum Style { | ||
Long, | ||
Short, | ||
Narrow, | ||
} | ||
/// Chooses between "this, that and other", and "this, that or other". | ||
#[derive(Eq, PartialEq, Debug, Clone)] | ||
pub enum Type { | ||
/// "This, that and other". | ||
Conjunction, | ||
/// "This, that or other". | ||
Disjunction, | ||
} | ||
} | ||
|
||
/// The options set by the user at construction time. See discussion at the top level | ||
/// about the name choice. Provides as a "bag of options" since we don't expect any | ||
/// implementations to be attached to this struct. | ||
/// | ||
/// The default values of all the options are prescribed in by the [TC39 report][tc39lf]. | ||
/// | ||
/// [tc39lf]: https://tc39.es/proposal-intl-list-format/#sec-Intl.ListFormat | ||
#[derive(Eq, PartialEq, Debug, Clone)] | ||
pub struct Options { | ||
/// Selects a [options::Style] for the formatted list. If unset, defaults | ||
/// to [options::Style::Long]. | ||
pub style: options::Style, | ||
/// Selects a [options::Type] for the formatted list. If unset, defaults to | ||
/// [options::Type::Conjunction]. | ||
pub in_type: options::Type, | ||
} | ||
|
||
/// Allows the use of `listformat::Format::try_new(..., Default::default())`. | ||
impl Default for Options { | ||
/// Gets the default values of [Options] if omitted at setup. The | ||
/// default values are prescribed in by the [TC39 report][tc39lf]. | ||
/// | ||
/// [tc39lf]: https://tc39.es/proposal-intl-list-format/#sec-Intl.ListFormat | ||
fn default() -> Self { | ||
Options { | ||
style: options::Style::Long, | ||
in_type: options::Type::Conjunction, | ||
} | ||
} | ||
} | ||
|
||
use std::fmt; | ||
|
||
/// The package workhorse: formats supplied pieces of text into an ergonomically formatted | ||
/// list. | ||
/// | ||
/// While ECMA 402 originally has functions under `Intl`, we probably want to | ||
/// obtain a separate factory from each implementor. | ||
/// | ||
/// Purposely omitted: | ||
/// | ||
/// - `supported_locales_of`. | ||
pub trait Format { | ||
/// The type of error reported, if any. | ||
type Error: std::error::Error; | ||
|
||
/// Creates a new [Format]. | ||
/// | ||
/// Creation may fail, for example, if the locale-specific data is not loaded, or if | ||
/// the supplied options are inconsistent. | ||
fn try_new<L>(l: L, opts: Options) -> Result<Self, Self::Error> | ||
where | ||
L: crate::Locale, | ||
Self: Sized; | ||
|
||
/// Formats `list` into the supplied standard `writer` [fmt::Write]. | ||
/// | ||
/// The original [ECMA 402 function][ecma402fmt] returns a string. This is likely the only | ||
/// reasonably generic option in JavaScript so it is adequate. In Rust, however, it is | ||
/// possible to pass in a standard formatting strategy (through `writer`). | ||
/// | ||
/// [ecma402fmt]: | ||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format | ||
/// | ||
/// This makes it unnecessary for [Format] to implement its own, and can | ||
/// completely avoid constructing any intermediary representation. This, in turn, | ||
/// allows the user to provide a purpose built formatter, or an "exotic" one if needed. | ||
/// | ||
/// A purpose built formatter could be one that formats into a fixed-size buffer; or | ||
/// another that knows how to format strings into a DOM. If ECMA 402 compatibility is | ||
/// needed, the user can force formatting into a string by passing the appropriate | ||
/// formatter. | ||
/// | ||
/// > Note: | ||
/// > - Should there be a convenience method that prints to string specifically? | ||
/// > - Do we need `format_into_parts`? | ||
fn format<I, L, W>(self, list: L, writer: &mut W) -> fmt::Result | ||
where | ||
I: fmt::Display, | ||
L: IntoIterator<Item = I>, | ||
W: fmt::Write; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
[package] | ||
authors = ["Google Inc."] | ||
default-features = false | ||
edition = "2018" | ||
keywords = ["icu", "unicode", "i18n", "l10n"] | ||
license = "Apache-2.0" | ||
name = "rust_icu_ecma402" | ||
readme = "README.md" | ||
repository = "https://github.com/google/rust_icu" | ||
version = "0.2.3" | ||
|
||
description = """ | ||
ECMA 402 standard implementation in Rust. | ||
""" | ||
[dependencies] | ||
anyhow = "1.0.25" | ||
ecma402_traits = { path = "../ecma402_traits", version = "0.1.0" } | ||
log = "0.4.6" | ||
paste = "0.1.5" | ||
rust_icu_common = { path = "../rust_icu_common", version = "0.2.3", default-features = false } | ||
rust_icu_sys = { path = "../rust_icu_sys", version = "0.2.3", default-features = false } | ||
rust_icu_uloc = { path = "../rust_icu_uloc", version = "0.2.3", default-features = false } | ||
rust_icu_ustring = { path = "../rust_icu_ustring", version = "0.2.3", default-features = false } | ||
rust_icu_ulistformatter = { path = "../rust_icu_ulistformatter", version = "0.2.3", default-features = false } | ||
|
||
[dev-dependencies] | ||
anyhow = "1.0.25" | ||
|
||
# See the feature description in ../rust_icu_sys/Cargo.toml for details. | ||
[features] | ||
default = ["use-bindgen", "renaming", "icu_config"] | ||
|
||
use-bindgen = [ | ||
"rust_icu_common/use-bindgen", | ||
"rust_icu_sys/use-bindgen", | ||
"rust_icu_ulistformatter/use-bindgen", | ||
"rust_icu_uloc/use-bindgen", | ||
"rust_icu_ustring/use-bindgen", | ||
] | ||
renaming = [ | ||
"rust_icu_common/renaming", | ||
"rust_icu_sys/renaming", | ||
"rust_icu_ulistformatter/renaming", | ||
"rust_icu_uloc/renaming", | ||
"rust_icu_ustring/renaming", | ||
] | ||
icu_config = [ | ||
"rust_icu_common/icu_config", | ||
"rust_icu_sys/icu_config", | ||
"rust_icu_ulistformatter/icu_config", | ||
"rust_icu_uloc/icu_config", | ||
"rust_icu_ustring/icu_config", | ||
] | ||
icu_version_in_env = [ | ||
"rust_icu_common/icu_version_in_env", | ||
"rust_icu_sys/icu_version_in_env", | ||
"rust_icu_ulistformatter/icu_version_in_env", | ||
"rust_icu_uloc/icu_version_in_env", | ||
"rust_icu_ustring/icu_version_in_env", | ||
] | ||
icu_version_64_plus = [ | ||
"rust_icu_common/icu_version_64_plus", | ||
"rust_icu_sys/icu_version_64_plus", | ||
"rust_icu_ustring/icu_version_64_plus", | ||
"rust_icu_uloc/icu_version_64_plus", | ||
"rust_icu_ulistformatter/icu_version_64_plus", | ||
] | ||
icu_version_67_plus = [ | ||
"rust_icu_common/icu_version_67_plus", | ||
"rust_icu_sys/icu_version_67_plus", | ||
"rust_icu_ustring/icu_version_67_plus", | ||
"rust_icu_uloc/icu_version_67_plus", | ||
"rust_icu_ulistformatter/icu_version_67_plus", | ||
] | ||
|
||
[badges] | ||
maintenance = { status = "actively-developed" } | ||
is-it-maintained-issue-resolution = { repository = "google/rust_icu" } | ||
is-it-maintained-open-issues = { repository = "google/rust_icu" } | ||
travis-ci = { repository = "google/rust_icu", branch = "master" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# WIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// The list formatter uses features that are not available in ICU versions prior | ||
// to 67. | ||
pub mod listformat; | ||
|
Oops, something went wrong.