[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36

John Goerzen jgoerzen at complete.org
Fri Apr 23 15:23:02 UTC 2010


The following commit has been merged in the master branch:
commit f46afd1db7d287f4f6a0bc2a25123909b7855af2
Author: John Goerzen <jgoerzen at complete.org>
Date:   Tue Apr 15 01:13:51 2008 -0500

    Implemented case-insentive parseNum

diff --git a/src/Data/Quantity.hs b/src/Data/Quantity.hs
index 451b992..86f00b0 100644
--- a/src/Data/Quantity.hs
+++ b/src/Data/Quantity.hs
@@ -44,6 +44,7 @@ module Data.Quantity (
 where
 import Data.List
 import Text.Printf
+import Data.Char
 
 {- | The options for 'quantifyNum' and 'renderNum' -}
 data SizeOpts = SizeOpts { base :: Int, -- ^ The base from which calculations are made
@@ -186,13 +187,16 @@ parseNum opts insensitive inp =
       [] -> Left "Couldn't parse numeric component of input"
       [(num, "")] -> Right num  -- No suffix; pass number unhindered
       [(num, [suffix])] ->
-          case lookup suffix suffixMap of
+          case lookup (caseTransformer suffix) suffixMap of
             Nothing -> Left $ "Unrecognized suffix " ++ show suffix
             Just power -> Right $ num * multiplier power
       [(_, suffix)] -> Left $ "Multi-character suffix " ++ show suffix
       _ -> Left "Multiple parses for input"
-    where suffixMap = zip (suffixes opts) 
+    where suffixMap = zip (map caseTransformer . suffixes $ opts) 
                           (iterate (+ (powerIncr opts)) (firstPower opts))
+          caseTransformer x
+              | insensitive = toLower x
+              | otherwise = x
           multiplier :: (Read a, Fractional a) => Int -> a
           multiplier power =
               fromRational . toRational $ 

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list