From 2cad552f6308b28cd7a99aa3584da98716019bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Sun, 2 Feb 2020 22:51:19 +1100 Subject: [PATCH] Quick fix for BioCore.RecordHelper: unsafe_parse_decimal --- src/sam/sam.jl | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/sam/sam.jl b/src/sam/sam.jl index d0f006b..f7b6c92 100644 --- a/src/sam/sam.jl +++ b/src/sam/sam.jl @@ -9,12 +9,43 @@ import Automa import Automa.RegExp: @re_str import BioAlignments import BioGenerics.Exceptions: missingerror -import BioGenerics.RecordHelper: unsafe_parse_decimal import BioGenerics: isfilled, header import BioSequences import BufferedStreams using Printf: @sprintf + +#TODO: update import BioCore.RecordHelper: unsafe_parse_decimal +# r"[0-9]+" must match `data[range]`. +function unsafe_parse_decimal(::Type{T}, data::Vector{UInt8}, range::UnitRange{Int}) where {T<:Unsigned} + x = zero(T) + @inbounds for i in range + x = Base.Checked.checked_mul(x, 10 % T) + x = Base.Checked.checked_add(x, (data[i] - UInt8('0')) % T) + end + return x +end + +# r"[-+]?[0-9]+" must match `data[range]`. +function unsafe_parse_decimal(::Type{T}, data::Vector{UInt8}, range::UnitRange{Int}) where {T<:Signed} + lo = first(range) + if data[lo] == UInt8('-') + sign = T(-1) + lo += 1 + elseif data[lo] == UInt8('+') + sign = T(+1) + lo += 1 + else + sign = T(+1) + end + x = zero(T) + @inbounds for i in lo:last(range) + x = Base.Checked.checked_mul(x, 10 % T) + x = Base.Checked.checked_add(x, (data[i] - UInt8('0')) % T) + end + return sign * x +end + include("flags.jl") include("metainfo.jl") include("record.jl")