Skip to content

Commit

Permalink
sam/header/parser: Use header map version parser
Browse files Browse the repository at this point in the history
  • Loading branch information
zaeleus committed Feb 15, 2024
1 parent 76a20fd commit 6315e32
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions noodles-sam/src/header/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,16 @@ impl Parser {
}

fn extract_version(src: &[u8]) -> Option<Version> {
use self::record::value::map::header::parse_version;

const RECORD_PREFIX: &[u8] = b"@HD\t";
const DELIMITER: u8 = b'\t';
const FIELD_PREFIX: &[u8] = b"VN:";

if let Some(raw_value) = src.strip_prefix(RECORD_PREFIX) {
for raw_field in raw_value.split(|&b| b == DELIMITER) {
if let Some(raw_version) = raw_field.strip_prefix(FIELD_PREFIX) {
return str::from_utf8(raw_version)
.ok()
.and_then(|s| s.parse().ok());
if let Some(s) = raw_field.strip_prefix(FIELD_PREFIX) {
return parse_version(s).ok();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion noodles-sam/src/header/parser/record.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod kind;
mod value;
pub(crate) mod value;

use std::{error, fmt};

Expand Down
2 changes: 1 addition & 1 deletion noodles-sam/src/header/parser/record/value.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod comment;
mod map;
pub(crate) mod map;

use std::{error, fmt};

Expand Down
2 changes: 1 addition & 1 deletion noodles-sam/src/header/parser/record/value/map/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{error, fmt};

use bstr::{BStr, BString};

use self::version::parse_version;
pub(crate) use self::version::parse_version;
use super::field::{consume_delimiter, consume_separator, parse_tag, parse_value, value};
use crate::header::{
parser::Context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{error, fmt};

use crate::header::record::value::map::header::Version;

pub(super) fn parse_version(src: &[u8]) -> Result<Version, ParseError> {
pub(crate) fn parse_version(src: &[u8]) -> Result<Version, ParseError> {
const DELIMITER: u8 = b'.';

fn split_once(buf: &[u8], delimiter: u8) -> Option<(&[u8], &[u8])> {
Expand Down

0 comments on commit 6315e32

Please sign in to comment.