Skip to content

Commit

Permalink
Fixed #17. Unicode PRIME and DOUBLE PRIME characters now allowed.
Browse files Browse the repository at this point in the history
E.g. readGroundPosition WGS84 "40°46′45.84″N 73°57′47.16″W"

Also the "Show" instance now uses the PRIME and DOUBLE PRIME characters
as this is less likely to cause confusion when pasting the output into
other kinds of string.
  • Loading branch information
PaulJohnson committed Feb 15, 2020
1 parent c80d06e commit 48551ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Geodetics/Geodetic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ showAngle a
| isNaN a1 = "NaN" -- Not a Nangle
| isInfinite a1 = sgn ++ "Infinity"
| otherwise = concat [sgn, show d, [chr 0xB0, ' '],
show m, "' ",
show s, ".", dstr, "\"" ]
show m, "\8242 ",
show s, ".", dstr, "\8243" ]
where
a1 = a /~ one
sgn = if a < _0 then "-" else ""
Expand Down
20 changes: 16 additions & 4 deletions src/Geodetics/LatLongParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,23 @@ import Data.Char
import Text.ParserCombinators.ReadP as P



-- | Parse an unsigned Integer value.
natural :: ReadP Integer -- Beware arithmetic overflow of Int
natural = read <$> munch1 isDigit


-- | Parse a tick sign for minutes. This accepts either the keyboard \"'\" or the unicode \"Prime\"
-- character U+2032
minuteTick :: ReadP ()
minuteTick = void $ choice [char '\'', char '\8242']


-- | Parse a double-tick sign for seconds. This accepts either the keyboard \" or the unicode
-- \"Double Prime\" character U+2033.
secondTick :: ReadP ()
secondTick = void $ choice [char '"', char '\8243']


-- | Parse an unsigned decimal value with optional decimal places but no exponent.
decimal :: ReadP Double
decimal = do
Expand Down Expand Up @@ -73,10 +85,10 @@ degreesMinutesSecondsUnits = do
d <- fromIntegral <$> option 0 (natural <* char '°')
guard $ d <= 360
skipSpaces
m <- fromIntegral <$> option 0 (natural <* char '\'')
m <- fromIntegral <$> option 0 (natural <* minuteTick)
guard $ m < 60
skipSpaces
s <- option 0 (decimal <* char '"')
s <- option 0 (decimal <* secondTick)
guard $ s < 60
return $ d + m / 60 + s / 3600
guard $ not $ null s -- Must specify at least one component.
Expand All @@ -100,7 +112,7 @@ degreesDecimalMinutesUnits = do
(s, a) <- gather $ do
d <- fromIntegral <$> option 0 (natural <* char '°')
guard $ d <= 360
m <- option 0 (decimal <* char '\'')
m <- option 0 (decimal <* minuteTick)
guard $ m < 60
return $ d + m / 60
guard $ not $ null s -- Must specify at least one component.
Expand Down

0 comments on commit 48551ec

Please sign in to comment.