Skip to content

Commit 8f7ecbf

Browse files
authored
Merge pull request #12 from x-hgg-x/format
2 parents 7991a71 + 2640f12 commit 8f7ecbf

File tree

11 files changed

+2484
-11
lines changed

11 files changed

+2484
-11
lines changed

Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[package]
22
name = "strftime-ruby"
3-
version = "0.1.0" # remember to set `html_root_url` in `src/lib.rs`.
4-
authors = ["Ryan Lopopolo <[email protected]>"]
3+
# remember to set `html_root_url` in `src/lib.rs`.
4+
version = "0.1.0"
5+
authors = ["Ryan Lopopolo <[email protected]>", "x-hgg-x"]
56
license = "MIT"
67
edition = "2021"
78
rust-version = "1.58.0"
@@ -24,6 +25,7 @@ std = ["alloc"]
2425
alloc = []
2526

2627
[dependencies]
28+
bitflags = "1.3"
2729

2830
[dev-dependencies]
2931
# Property testing for interner getters and setters.

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2022 Ryan Lopopolo <[email protected]>
3+
Copyright (c) 2022 Ryan Lopopolo <[email protected]> and x-hgg-x.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ All features are enabled by default.
4343
- **std** - Enables a dependency on the Rust Standard Library. Activating this
4444
feature also activates the **alloc** feature.
4545
- **alloc** - Enables a dependency on the Rust [`alloc`] crate. Activating this
46-
feature enables APIs that require [`alloc::string::String`].
46+
feature enables APIs that require [`alloc::vec::Vec`] or
47+
[`alloc::string::String`].
4748

4849
[`alloc`]: https://doc.rust-lang.org/alloc/
50+
[`alloc::vec::vec`]: https://doc.rust-lang.org/alloc/vec/struct.Vec.html
4951
[`alloc::string::string`]:
5052
https://doc.rust-lang.org/alloc/string/struct.String.html
5153

@@ -56,4 +58,5 @@ releases.
5658

5759
## License
5860

59-
`strftime-ruby` is licensed under the [MIT License](LICENSE) (c) Ryan Lopopolo.
61+
`strftime-ruby` is licensed under the [MIT License](LICENSE) (c) Ryan Lopopolo
62+
and x-hgg-x.

src/format/assert.rs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//! Compile-time assert functions.
2+
3+
/// Helper macro for implementing asserts.
4+
macro_rules! assert_sorted_by_key {
5+
($s:expr, $f:expr) => {{
6+
let mut i = 0;
7+
while i + 1 < $s.len() {
8+
assert!(*$f(&$s[i]) < *$f(&$s[i + 1]));
9+
i += 1;
10+
}
11+
$s
12+
}};
13+
}
14+
15+
/// Returns the first element of a tuple.
16+
const fn elem_0<T>(x: &(u8, T)) -> &u8 {
17+
&x.0
18+
}
19+
20+
/// Asserts that a slice is sorted and has no duplicates.
21+
pub(crate) const fn assert_sorted(s: &[u8]) -> &[u8] {
22+
assert_sorted_by_key!(s, core::convert::identity)
23+
}
24+
25+
/// Asserts that a slice is sorted by its first element and has no duplicates.
26+
pub(crate) const fn assert_sorted_elem_0<T>(s: &[(u8, T)]) -> &[(u8, T)] {
27+
assert_sorted_by_key!(s, elem_0)
28+
}
29+
30+
/// Asserts that converting the first input to uppercase yields the second input.
31+
#[allow(dead_code)]
32+
pub(crate) const fn assert_to_ascii_uppercase(table: &[&str], upper_table: &[&str]) {
33+
assert!(table.len() == upper_table.len());
34+
35+
let mut index = 0;
36+
while index < table.len() {
37+
let (s, upper_s) = (table[index].as_bytes(), upper_table[index].as_bytes());
38+
assert!(s.len() == upper_s.len());
39+
40+
let mut i = 0;
41+
while i < s.len() {
42+
assert!(s[i].is_ascii());
43+
assert!(upper_s[i].is_ascii());
44+
assert!(upper_s[i] == s[i].to_ascii_uppercase());
45+
i += 1;
46+
}
47+
48+
index += 1;
49+
}
50+
}

0 commit comments

Comments
 (0)