Skip to content

Commit

Permalink
Fix bl3 parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
adumbidiot committed Jun 2, 2023
1 parent d1fadd8 commit a9bef6e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ members = [
lto = "fat"
codegen-units = 1
opt-level = 3
strip = "symbols"
strip = "symbols"
panic = "abort"
7 changes: 5 additions & 2 deletions lib/shift-orcz/src/shift_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub const XBOX_CODE_INDEX: usize = 2;
static TD_SELECTOR: Lazy<Selector> =
Lazy::new(|| Selector::parse("td").expect("invalid TD_SELECTOR"));
static DATE_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"((?P<year_1>\d{4}).(?P<month_1>\d{2}).(?P<day_1>\d{2}))|((?P<month_2>[[:alpha:]]*?) *(?P<day_2>\d{1,2})(th|nd)? ?,? (?P<year_2>\d{4}))").unwrap()
Regex::new(r"((?P<year_1>\d{4}).(?P<month_1>\d{2}).(?P<day_1>\d{2}))|((?P<month_1_1>\d{1,2}).(?P<day_1_1>\d{2}).(?P<year_1_1>\d{4}))|((?P<month_2>[[:alpha:]]*?) *(?P<day_2>\d{1,2})(th|nd)? ?,? (?P<year_2>\d{4}))").unwrap()
});

/// Error that may occur while parsing a ShiftCode from an element
Expand Down Expand Up @@ -230,21 +230,23 @@ fn process_rewards_node(element: ElementRef) -> String {
}

fn parse_issue_date_str(issue_date_str: &str) -> Result<Option<time::Date>, FromElementError> {
if dbg!(issue_date_str) == "Unknown" {
if issue_date_str == "Unknown" {
Ok(None)
} else {
let captures = DATE_REGEX
.captures(issue_date_str)
.ok_or(FromElementError::MissingIssueDate)?;
let y = captures
.name("year_1")
.or_else(|| captures.name("year_1_1"))
.or_else(|| captures.name("year_2"))
.ok_or(FromElementError::IssueDateMissingYear)?
.as_str()
.parse::<i32>()
.map_err(FromElementError::IssueDateInvalidYear)?;
let m = captures
.name("month_1")
.or_else(|| captures.name("month_1_1"))
.map(|month| {
let month = month
.as_str()
Expand Down Expand Up @@ -275,6 +277,7 @@ fn parse_issue_date_str(issue_date_str: &str) -> Result<Option<time::Date>, From
.ok_or(FromElementError::IssueDateMissingMonth)??;
let d = captures
.name("day_1")
.or_else(|| captures.name("day_1_1"))
.or_else(|| captures.name("day_2"))
.ok_or(FromElementError::IssueDateMissingDay)?
.as_str()
Expand Down

0 comments on commit a9bef6e

Please sign in to comment.