-- | Encode a GHC name to an identifier.
encodeName :: Name -> Text
encodeName name = T.pack encoded where
  encoded = case nameModule_maybe name of
    Nothing -> zEncodeString (occNameString (nameOccName name))
    Just mod ->
      zEncodeString (packageIdString (modulePackageId mod)) ++ "$" ++
      intercalate "$" (map zEncodeString (words (dotsToSpace (moduleNameString (moduleName mod))))) ++ "$" ++
      zEncodeString (occNameString (nameOccName name))

-- | Convert dots to spaces.
encodeName :: Name -> Text
encodeName name = T.pack encoded where
  encoded = case nameModule_maybe name of
    Nothing -> zEncodeString (occNameString (nameOccName name))
    Just mod ->
      zEncodeString (packageIdString (modulePackageId mod)) ++ "$" ++
      intercalate "$" (map zEncodeString (words (dotsToSpace (moduleNameString (moduleName mod))))) ++ "$" ++
      zEncodeString (occNameString (nameOccName name))

-- | Convert dots to spaces.
encodeName name = T.pack encoded where
  encoded = case nameModule_maybe name of
    Nothing -> zEncodeString (occNameString (nameOccName name))
    Just mod ->
      zEncodeString (packageIdString (modulePackageId mod)) ++ "$" ++
      intercalate "$" (map zEncodeString (words (dotsToSpace (moduleNameString (moduleName mod))))) ++ "$" ++
      zEncodeString (occNameString (nameOccName name))

-- | Convert dots to spaces.