Skip to content

Implement strftime #12

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

Merged
merged 37 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
db1a35a
Initial implementation
x-hgg-x Aug 10, 2022
22e4e07
Use binary search when filtering POSIX locale extensions
x-hgg-x Aug 11, 2022
8c44ece
Use binary search when matching specifiers
x-hgg-x Aug 11, 2022
94c644f
Use flags to allow both case specifiers
x-hgg-x Aug 12, 2022
96571d1
Fix test for ISO 8601 week
x-hgg-x Aug 12, 2022
fe340b9
Add error case for parsing width
x-hgg-x Aug 12, 2022
aa9cadf
Remove unnecessary mut bindings
x-hgg-x Aug 12, 2022
264caa2
Describe usage of flags
x-hgg-x Aug 12, 2022
0edcc1f
Remove magic constants for padding
x-hgg-x Aug 12, 2022
6a7c5f2
Fix size limit
x-hgg-x Aug 12, 2022
f4b8737
Enforce ASCII for Upper and Lower structs
x-hgg-x Aug 12, 2022
932e048
Add test for year width
x-hgg-x Aug 12, 2022
98d208f
Make the crate no-std
x-hgg-x Aug 12, 2022
cf71127
Move assert module to its own file
x-hgg-x Aug 13, 2022
3bb9a4b
Use pub(crate) instead of pub
x-hgg-x Aug 13, 2022
d493b71
Create a generic Time trait
x-hgg-x Aug 13, 2022
3128110
Return a specific error if the formatted string is too large
x-hgg-x Aug 13, 2022
380b19c
Return written slice for the buffered strftime
x-hgg-x Aug 13, 2022
b0cb994
Check if the width is a valid c_int value
x-hgg-x Aug 13, 2022
8666e67
Move formatting tests to a specific module
x-hgg-x Aug 13, 2022
4293c2e
Add items documentation
x-hgg-x Aug 14, 2022
841159f
Move modules
x-hgg-x Aug 14, 2022
cf3f021
Add crate documentation
x-hgg-x Aug 14, 2022
c978820
Fix '%:::z' formatting
x-hgg-x Aug 14, 2022
b284ee8
Fix '%Z' formatting with padding
x-hgg-x Aug 14, 2022
d689066
Fix '%D' formatting
x-hgg-x Aug 14, 2022
8997970
Add tests for all specifiers
x-hgg-x Aug 14, 2022
cb4befd
Fix doc build without std feature
x-hgg-x Aug 14, 2022
f927da3
Update authors section
x-hgg-x Aug 14, 2022
eeb2e1d
Format README.md
x-hgg-x Aug 14, 2022
6b85f96
Remove duplicate test
x-hgg-x Aug 14, 2022
f3c384a
Simplify size limit computation
x-hgg-x Aug 15, 2022
3421a46
Style fixes
x-hgg-x Aug 15, 2022
86db031
Update LICENSE and README.md
x-hgg-x Aug 15, 2022
999c3ff
Update documentation for the Time trait
x-hgg-x Aug 15, 2022
95a7952
Remove Default implementation for Padding
x-hgg-x Aug 15, 2022
2640f12
Use format args capture everywhere
x-hgg-x Aug 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[package]
name = "strftime-ruby"
version = "0.1.0" # remember to set `html_root_url` in `src/lib.rs`.
authors = ["Ryan Lopopolo <[email protected]>"]
# remember to set `html_root_url` in `src/lib.rs`.
version = "0.1.0"
authors = ["Ryan Lopopolo <[email protected]>", "x-hgg-x"]
license = "MIT"
edition = "2021"
rust-version = "1.58.0"
Expand All @@ -24,6 +25,7 @@ std = ["alloc"]
alloc = []

[dependencies]
bitflags = "1.3"

[dev-dependencies]
# Property testing for interner getters and setters.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

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

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ All features are enabled by default.
- **std** - Enables a dependency on the Rust Standard Library. Activating this
feature also activates the **alloc** feature.
- **alloc** - Enables a dependency on the Rust [`alloc`] crate. Activating this
feature enables APIs that require [`alloc::string::String`].
feature enables APIs that require [`alloc::vec::Vec`] or
[`alloc::string::String`].

[`alloc`]: https://doc.rust-lang.org/alloc/
[`alloc::vec::vec`]: https://doc.rust-lang.org/alloc/vec/struct.Vec.html
[`alloc::string::string`]:
https://doc.rust-lang.org/alloc/string/struct.String.html

Expand All @@ -56,4 +58,5 @@ releases.

## License

`strftime-ruby` is licensed under the [MIT License](LICENSE) (c) Ryan Lopopolo.
`strftime-ruby` is licensed under the [MIT License](LICENSE) (c) Ryan Lopopolo
and x-hgg-x.
50 changes: 50 additions & 0 deletions src/format/assert.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//! Compile-time assert functions.

/// Helper macro for implementing asserts.
macro_rules! assert_sorted_by_key {
($s:expr, $f:expr) => {{
let mut i = 0;
while i + 1 < $s.len() {
assert!(*$f(&$s[i]) < *$f(&$s[i + 1]));
i += 1;
}
$s
}};
}

/// Returns the first element of a tuple.
const fn elem_0<T>(x: &(u8, T)) -> &u8 {
&x.0
}

/// Asserts that a slice is sorted and has no duplicates.
pub(crate) const fn assert_sorted(s: &[u8]) -> &[u8] {
assert_sorted_by_key!(s, core::convert::identity)
}

/// Asserts that a slice is sorted by its first element and has no duplicates.
pub(crate) const fn assert_sorted_elem_0<T>(s: &[(u8, T)]) -> &[(u8, T)] {
assert_sorted_by_key!(s, elem_0)
}

/// Asserts that converting the first input to uppercase yields the second input.
#[allow(dead_code)]
pub(crate) const fn assert_to_ascii_uppercase(table: &[&str], upper_table: &[&str]) {
assert!(table.len() == upper_table.len());

let mut index = 0;
while index < table.len() {
let (s, upper_s) = (table[index].as_bytes(), upper_table[index].as_bytes());
assert!(s.len() == upper_s.len());

let mut i = 0;
while i < s.len() {
assert!(s[i].is_ascii());
assert!(upper_s[i].is_ascii());
assert!(upper_s[i] == s[i].to_ascii_uppercase());
i += 1;
}

index += 1;
}
}
Loading