Skip to content

Commit

Permalink
chore: tweak tab spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Jan 10, 2024
1 parent 3d48a87 commit 81b022f
Show file tree
Hide file tree
Showing 17 changed files with 1,145 additions and 1,145 deletions.
66 changes: 33 additions & 33 deletions benches/parse_language_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion};
use unicode_locale_parser::parse_language_id;

fn language_identifier_parser_bench(c: &mut Criterion) {
let strings = [
"en-US",
"en-GB",
"es-AR",
"it",
"zh-Hans-CN",
"de-AT",
"pl",
"fr-FR",
"de-AT",
"sr-Cyrl-SR",
"nb-NO",
"fr-FR",
"mk",
"uk",
"en-US",
"en-GB",
"es-AR",
"th",
"de",
"zh-Cyrl-HN",
"en-Latn-US",
];
let strings = [
"en-US",
"en-GB",
"es-AR",
"it",
"zh-Hans-CN",
"de-AT",
"pl",
"fr-FR",
"de-AT",
"sr-Cyrl-SR",
"nb-NO",
"fr-FR",
"mk",
"uk",
"en-US",
"en-GB",
"es-AR",
"th",
"de",
"zh-Cyrl-HN",
"en-Latn-US",
];

c.bench_function(
"unicode_locale_id_parser::lang:::parse_unicode_language_id",
|b| {
b.iter(|| {
for s in strings {
let _ = parse_language_id(black_box(s));
}
})
},
);
c.bench_function(
"unicode_locale_id_parser::lang:::parse_unicode_language_id",
|b| {
b.iter(|| {
for s in strings {
let _ = parse_language_id(black_box(s));
}
})
},
);
}

criterion_group!(benches, language_identifier_parser_bench);
Expand Down
66 changes: 33 additions & 33 deletions benches/parse_locale_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion};
use unicode_locale_parser::parse_locale_id;

fn locale_identifier_parser_bench(c: &mut Criterion) {
let strings = [
"en-US",
"en-GB",
"es-AR",
"it",
"zh-Hans-CN",
"de-AT",
"pl",
"fr-FR",
"de-AT",
"sr-Cyrl-SR",
"nb-NO",
"fr-FR",
"mk",
"uk",
"en-US",
"en-GB",
"es-AR",
"th",
"de",
"zh-Cyrl-HN",
"en-Latn-US",
];
let strings = [
"en-US",
"en-GB",
"es-AR",
"it",
"zh-Hans-CN",
"de-AT",
"pl",
"fr-FR",
"de-AT",
"sr-Cyrl-SR",
"nb-NO",
"fr-FR",
"mk",
"uk",
"en-US",
"en-GB",
"es-AR",
"th",
"de",
"zh-Cyrl-HN",
"en-Latn-US",
];

c.bench_function(
"unicode_locale_id_parser::locale::parse_unicode_locale_id",
|b| {
b.iter(|| {
for s in strings {
let _ = parse_locale_id(black_box(s));
}
})
},
);
c.bench_function(
"unicode_locale_id_parser::locale::parse_unicode_locale_id",
|b| {
b.iter(|| {
for s in strings {
let _ = parse_locale_id(black_box(s));
}
})
},
);
}

criterion_group!(benches, locale_identifier_parser_bench);
Expand Down
12 changes: 6 additions & 6 deletions examples/parse.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use unicode_locale_parser::parse_locale_id;

fn main() {
// simple language
let locale = parse_locale_id("ja-JP");
println!("{:#?}", locale);
// simple language
let locale = parse_locale_id("ja-JP");
println!("{:#?}", locale);

// language & unicode locale extension
let locale = parse_locale_id("de-Latn-DE-u-ca-buddhist");
println!("{:#?}", locale);
// language & unicode locale extension
let locale = parse_locale_id("de-Latn-DE-u-ca-buddhist");
println!("{:#?}", locale);
}
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tab_spaces = 2
46 changes: 23 additions & 23 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@ use std::fmt::{Display, Formatter, Result};
/// Enum representing the possible errors that can occur when parsing [Unicode UTS #35 Language and Locale Identifiers](https://unicode.org/reports/tr35/#Identifiers).
#[derive(Debug, PartialEq)]
pub enum ParserError {
/// A missing identifier error.
Missing,
/// An invalid language identifier error.
InvalidLanguage,
/// An invalid subtag error.
InvalidSubtag,
/// An invalid unicode extensions error.
InvalidExtension,
/// An invalid unicode subdivision error.
InvalidSubdivision,
/// An unexpected error.
Unexpected,
/// A missing identifier error.
Missing,
/// An invalid language identifier error.
InvalidLanguage,
/// An invalid subtag error.
InvalidSubtag,
/// An invalid unicode extensions error.
InvalidExtension,
/// An invalid unicode subdivision error.
InvalidSubdivision,
/// An unexpected error.
Unexpected,
}

impl Error for ParserError {}

impl Display for ParserError {
fn fmt(&self, f: &mut Formatter) -> Result {
let value = match self {
ParserError::Missing => "Missing identifier",
ParserError::InvalidLanguage => "Invalid language identifier",
ParserError::InvalidSubtag => "Invalid subtag",
ParserError::InvalidExtension => "Invalid extension",
ParserError::InvalidSubdivision => "Invalid subdivision",
ParserError::Unexpected => "Unexpected error",
};
f.write_str(value)
}
fn fmt(&self, f: &mut Formatter) -> Result {
let value = match self {
ParserError::Missing => "Missing identifier",
ParserError::InvalidLanguage => "Invalid language identifier",
ParserError::InvalidSubtag => "Invalid subtag",
ParserError::InvalidExtension => "Invalid extension",
ParserError::InvalidSubdivision => "Invalid subdivision",
ParserError::Unexpected => "Unexpected error",
};
f.write_str(value)
}
}
Loading

0 comments on commit 81b022f

Please sign in to comment.