Skip to content

Commit

Permalink
Wrap code in SubfieldCode
Browse files Browse the repository at this point in the history
Signed-off-by: Nico Wagner <[email protected]>
  • Loading branch information
nwagner84 committed Sep 2, 2024
1 parent b8eea77 commit 4a395e7
Show file tree
Hide file tree
Showing 9 changed files with 320 additions and 77 deletions.
4 changes: 2 additions & 2 deletions crates/pica-format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ops::RangeTo;
use std::str::FromStr;

use pica_matcher::{OccurrenceMatcher, SubfieldMatcher, TagMatcher};
use pica_record::{FieldRef, RecordRef, SubfieldRef};
use pica_record::{FieldRef, RecordRef, SubfieldCode, SubfieldRef};
use thiserror::Error;
use winnow::prelude::*;

Expand Down Expand Up @@ -123,7 +123,7 @@ impl Formatter for Fragments {

#[derive(Debug, Clone, PartialEq)]
struct Value {
codes: Vec<char>,
codes: Vec<SubfieldCode>,
prefix: Option<String>,
suffix: Option<String>,
bounds: RangeTo<usize>,
Expand Down
7 changes: 4 additions & 3 deletions crates/pica-format/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use bstr::ByteSlice;
use pica_matcher::parser::{
parse_occurrence_matcher, parse_subfield_matcher, parse_tag_matcher,
};
use pica_record::SubfieldCode;
use winnow::ascii::{digit1, multispace0, multispace1};
use winnow::combinator::{
alt, delimited, empty, opt, preceded, repeat, separated, terminated,
Expand Down Expand Up @@ -180,14 +181,14 @@ fn parse_list_and_then(i: &mut &[u8]) -> PResult<List> {
}

/// Parses a subfield code (a single alpha-numeric character)
fn parse_code(i: &mut &[u8]) -> PResult<char> {
fn parse_code(i: &mut &[u8]) -> PResult<SubfieldCode> {
one_of(('0'..='9', 'a'..='z', 'A'..='Z'))
.map(char::from)
.map(SubfieldCode::from_unchecked)
.parse_next(i)
}

/// Parses a sequence of subfield codes.
fn parse_codes(i: &mut &[u8]) -> PResult<Vec<char>> {
fn parse_codes(i: &mut &[u8]) -> PResult<Vec<SubfieldCode>> {
alt((
parse_code.map(|code| vec![code]),
delimited(ws('['), repeat(2.., parse_code), ws(']')),
Expand Down
Loading

0 comments on commit 4a395e7

Please sign in to comment.