Skip to content

Commit

Permalink
[REVIEW] Refactor read_sam_byte_vector
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Jan 5, 2023
1 parent 58a5155 commit 3cd2155
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions include/seqan3/io/sam_file/format_sam.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -850,13 +850,14 @@ inline void format_sam::read_sam_byte_vector(seqan3::detail::sam_tag_variant & v
if (str.size() % 2 != 0)
throw format_error{"[CORRUPTED SAM FILE] Hexadecimal tag must have even number of digits."};

for (size_t i = 0; i < str.size(); i += 2)
// H encodes bytes in a hexadecimal format. Two hex values are stored for each byte as characters.
// E.g., '1' and 'A' need one byte each and are read as `\x1A`, which is 27 in decimal.
for (auto hex_begin = str.begin(), hex_end = str.begin() + 2; hex_begin != str.end(); hex_begin += 2, hex_end += 2)
{
auto res = std::from_chars(str.begin() + i, str.begin() + i + 2, dummy_byte, 16);
auto res = std::from_chars(hex_begin, hex_end, dummy_byte, 16);

if (res.ec == std::errc::invalid_argument)
throw format_error{std::string("[CORRUPTED SAM FILE] The string '")
+ std::string(str.begin() + i, str.begin() + i + 2)
throw format_error{std::string("[CORRUPTED SAM FILE] The string '") + std::string(hex_begin, hex_end)
+ "' could not be cast into type uint8_t."};

if (res.ec == std::errc::result_out_of_range)
Expand Down

0 comments on commit 3cd2155

Please sign in to comment.