Skip to content

Commit 9fb761d

Browse files
committed
Improved parsing
1 parent 6eb5f7e commit 9fb761d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/RegistryTools.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,12 @@ function change_symbol(u::U, s::Symbol) where U<:AbstractAffineUnits
286286
return constructorof(U)(scale=uscale(u), offset=uoffset(u), dims=dimension(u), symbol=s)
287287
end
288288

289-
_expr_preprocessing(str::String) = replace(str, " "=>"", "%"=>"percent")
289+
function _expr_preprocessing(str1::AbstractString)
290+
space2mult = r"([\%\w]) +([\%\w])" => s"\1*\2"
291+
str2 = replace(str1, space2mult) #Spaces between words are multiplications
292+
str3 = replace(str2, space2mult) #Spaces between words are multiplications
293+
return replace(str3, " "=>"", "%"=>"percent") #Eliminates extra spaces
294+
end
290295

291296
end
292297

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ end
445445
@test q"1.0" == 1.0u""
446446
@test qparse("1%") == 0.01u""
447447
@test qparse("1.0") == 1.0u""
448+
@test qparse("5 5kg") == 25u"kg"
448449

449450
#Test showerror
450451
testio = IOBuffer()

0 commit comments

Comments
 (0)