-
Notifications
You must be signed in to change notification settings - Fork 1
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
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 22e4e07
Use binary search when filtering POSIX locale extensions
x-hgg-x 8c44ece
Use binary search when matching specifiers
x-hgg-x 94c644f
Use flags to allow both case specifiers
x-hgg-x 96571d1
Fix test for ISO 8601 week
x-hgg-x fe340b9
Add error case for parsing width
x-hgg-x aa9cadf
Remove unnecessary mut bindings
x-hgg-x 264caa2
Describe usage of flags
x-hgg-x 0edcc1f
Remove magic constants for padding
x-hgg-x 6a7c5f2
Fix size limit
x-hgg-x f4b8737
Enforce ASCII for Upper and Lower structs
x-hgg-x 932e048
Add test for year width
x-hgg-x 98d208f
Make the crate no-std
x-hgg-x cf71127
Move assert module to its own file
x-hgg-x 3bb9a4b
Use pub(crate) instead of pub
x-hgg-x d493b71
Create a generic Time trait
x-hgg-x 3128110
Return a specific error if the formatted string is too large
x-hgg-x 380b19c
Return written slice for the buffered strftime
x-hgg-x b0cb994
Check if the width is a valid c_int value
x-hgg-x 8666e67
Move formatting tests to a specific module
x-hgg-x 4293c2e
Add items documentation
x-hgg-x 841159f
Move modules
x-hgg-x cf3f021
Add crate documentation
x-hgg-x c978820
Fix '%:::z' formatting
x-hgg-x b284ee8
Fix '%Z' formatting with padding
x-hgg-x d689066
Fix '%D' formatting
x-hgg-x 8997970
Add tests for all specifiers
x-hgg-x cb4befd
Fix doc build without std feature
x-hgg-x f927da3
Update authors section
x-hgg-x eeb2e1d
Format README.md
x-hgg-x 6b85f96
Remove duplicate test
x-hgg-x f3c384a
Simplify size limit computation
x-hgg-x 3421a46
Style fixes
x-hgg-x 86db031
Update LICENSE and README.md
x-hgg-x 999c3ff
Update documentation for the Time trait
x-hgg-x 95a7952
Remove Default implementation for Padding
x-hgg-x 2640f12
Use format args capture everywhere
x-hgg-x File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,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" | ||
|
@@ -24,6 +25,7 @@ std = ["alloc"] | |
alloc = [] | ||
x-hgg-x marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[dependencies] | ||
bitflags = "1.3" | ||
|
||
[dev-dependencies] | ||
# Property testing for interner getters and setters. | ||
|
This file contains hidden or 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,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 | ||
|
This file contains hidden or 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 hidden or 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,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; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.