Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bidi Data Adapter #1784

Merged
merged 21 commits into from
Apr 27, 2022
Merged

Bidi Data Adapter #1784

merged 21 commits into from
Apr 27, 2022

Conversation

younies
Copy link
Member

@younies younies commented Apr 7, 2022

Closes: #1784

@younies younies requested a review from a team as a code owner April 7, 2022 23:13
@younies younies changed the title Bidi Bidi Data Adopter Apr 7, 2022
@younies younies marked this pull request as draft April 7, 2022 23:14
use icu_codepointtrie::CodePointTrie;

pub struct BidiClassAdaptor {
code_point_trie: CodePointTrie;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
code_point_trie: CodePointTrie;
code_point_trie: CodePointTrie,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

use icu::properties::{maps, BidiClass};
use icu_codepointtrie::CodePointTrie;

pub struct BidiClassAdaptor {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Adapter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

maps::get_bidi_class(&provider)
.expect("The data should be valid");
let data_struct = payload.get();
BidiClassAdaptor{ data_struct.code_point_trie }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
BidiClassAdaptor{ data_struct.code_point_trie }
BidiClassAdaptor{ code_point_trie: data_struct.code_point_trie }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I added a reference to the provider. However, I would like to have a way to save a reference to the code_point_trie instead. Shall I pass a code_point_trie?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added it.

@@ -38,6 +38,7 @@ icu_provider = { version = "0.5", path = "../../provider/core", features = ["mac
icu_uniset = { version = "0.4.1", path = "../../utils/uniset"}
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"], optional = true }
zerovec = { version = "0.6", path = "../../utils/zerovec", features = ["derive"] }
unicode-bidi = "0.3.7"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: This should be an optional dependency. Enabling this dependency should enable the code that uses it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

@@ -0,0 +1,71 @@
// This file is part of ICU4X. For terms of use, please see the file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please, name this file src/bidi.rs - bc becomes very cryptic for readers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::BidiDataSource;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: where is BidiDataSource defined? Why do you need a trait?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it comes from the unicode-bidi crate. The import needs to be fixed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it comes from unicode-bidi and I have fixed the import.

@zbraniecki , we need to implement to plugin the data from ICU4X to unicode-bidi.

@younies younies marked this pull request as ready for review April 21, 2022 03:46
BidiClass::LeftToRightIsolate => DataSourceBidiClass::LRI,
BidiClass::RightToLeftIsolate => DataSourceBidiClass::RLI,
BidiClass::PopDirectionalIsolate => DataSourceBidiClass::PDI,
_ => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what shall we do here? unfortunately, BidiClass is not an enum?

@sffc , @Manishearth

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should return the neutral/undefined/default value.

Running this code is rare, but it can happen if old code runs with new data.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I have returned Other_Neutral

@@ -92,3 +93,5 @@ pub use props::{
BidiClass, CanonicalCombiningClass, EastAsianWidth, EnumeratedProperty, GeneralCategory,
GeneralCategoryGroup, GraphemeClusterBreak, LineBreak, Script, SentenceBreak, WordBreak,
};

pub use bidi::BidiClassAdapter;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Don't hoist this to the top. Leave it exported under the bidi module.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not get this, could you illustrate more?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should clients write

use icu_properties::BidiClassAdapter;

or

use icu_properties::bidi::BidiClassAdapter;

I think we should lean toward putting this into a child namespace rather than the top level, but I can be convinced otherwise.

CC @Manishearth @echeran

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think child module makes sense

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

components/properties/src/bidi.rs Show resolved Hide resolved
@younies younies requested a review from sffc April 21, 2022 13:44
@jira-pull-request-webhook
Copy link

Notice: the branch changed across the force-push!

  • Cargo.lock is different
  • components/properties/Cargo.toml is different
  • components/properties/src/lib.rs is different

View Diff Across Force-Push

~ Your Friendly Jira-GitHub PR Checker Bot

@sffc sffc changed the title Bidi Data Adopter Bidi Data Adapter Apr 21, 2022
components/properties/src/lib.rs Show resolved Hide resolved
@@ -52,3 +54,4 @@ std = ["icu_provider/std"]
default = []
serde = ["dep:serde", "zerovec/serde", "icu_uniset/serde", "icu_codepointtrie/serde"]
datagen = ["serde", "zerovec/serde_serialize", "icu_uniset/serde_serialize", "icu_codepointtrie/serde_serialize"]
unicode-bidi = [ "dep:unicode-bidi" ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: name the feature just "bidi"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@younies younies requested a review from sffc April 25, 2022 13:15
icu_uniset = { version = "0.4.1", path = "../../utils/uniset"}
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"], optional = true }
zerovec = { version = "0.6", path = "../../utils/zerovec", features = ["derive"] }
unicode-bidi = { git = "https://github.com/servo/unicode-bidi", optional = true , deafault-features = false }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've made servo/unicode-bidi#78 to get this published, since we have a working PR now and are close to landing it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I am waiting to merge it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@younies younies requested a review from Manishearth April 26, 2022 15:44
@younies younies closed this Apr 26, 2022
@younies younies reopened this Apr 26, 2022
components/properties/src/bidi.rs Outdated Show resolved Hide resolved
components/properties/src/bidi.rs Show resolved Hide resolved
@younies younies requested a review from sffc April 26, 2022 18:22
Manishearth
Manishearth previously approved these changes Apr 27, 2022
components/properties/src/bidi.rs Outdated Show resolved Hide resolved

[dev-dependencies]
icu = { path = "../icu", default-features = false }
icu_testdata = { version = "0.5", path = "../../provider/testdata" }
icu_provider_fs = {version = "0.5.0", path = "../../provider/fs" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I do not think you are using this dependency, so you should remove it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@younies younies requested a review from sffc April 27, 2022 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants