module Distribution.Simple.Program.Internal (
    stripExtractVersion,
  ) where
import Prelude ()
import Distribution.Compat.Prelude
stripExtractVersion :: String -> String
stripExtractVersion str =
  let numeric ""    = False
      numeric (x:_) = isDigit x
      
      filterPar' :: Int -> [String] -> [String]
      filterPar' _ []                   = []
      filterPar' n (x:xs)
        | n >= 0 && "(" `isPrefixOf` x = filterPar' (n+1) ((tail x):xs)
        | n >  0 && ")" `isSuffixOf` x = filterPar' (n1) xs
        | n >  0                       = filterPar' n xs
        | otherwise                    = x:filterPar' n xs
      filterPar = filterPar' 0
  in case dropWhile (not . numeric) (filterPar . words $ str) of
    (ver:_) ->
      
      let isDot         = (== '.')
          (major, rest) = break isDot ver
          minor         = takeWhile isDigit (dropWhile isDot rest)
      in major ++ "." ++ minor
    _ -> ""