From 2ade4fcf14dc50ef2bc79c348dbb185011f1369d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20B=C3=B6hm?= <mboe@informatik.uni-kiel.de> Date: Thu, 24 Oct 2013 10:50:20 +0200 Subject: [PATCH] added extractOrigName function that extracts the original name of an identifier --- src/Curry/Base/Ident.hs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Curry/Base/Ident.hs b/src/Curry/Base/Ident.hs index 17c78c5..df8d23d 100644 --- a/src/Curry/Base/Ident.hs +++ b/src/Curry/Base/Ident.hs @@ -67,7 +67,7 @@ module Curry.Base.Ident , recordExtId, labelExtId, isRecordExtId, isLabelExtId, fromRecordExtId , fromLabelExtId, renameLabel, recordExt, labelExt, mkLabelIdent -- ** Constructed identifiers - , identPrefix, Curry.Base.Ident.sep + , identPrefix, Curry.Base.Ident.sep, extractOrigName ) where import Data.Char (isAlpha, isAlphaNum, isSpace) @@ -709,3 +709,19 @@ identPrefix = "#" -- elements sep :: String sep = ":_" + +-- |Extracts the original name of the given identifier. This is the string after +-- the last "sep". +extractOrigName :: Ident -> Ident +extractOrigName = updIdentName extractOrigName' + +extractOrigName' :: String -> String +extractOrigName' s = last (split' s "" []) + where + sep' = Curry.Base.Ident.sep + lenSep = length sep' + split' :: String -> String -> [String] -> [String] + split' str acc1 acc2 + | sep' `isPrefixOf` str = split' (drop lenSep str) "" (reverse acc1 : acc2) + | null str = reverse (reverse acc1 : acc2) + | otherwise = split' (tail str) (head str : acc1) acc2 -- GitLab