module BNFC.Backend.Common.StringUtils where import BNFC.Prelude ( String, isLower, isUpper, toLower, toUpper, panic ) -- | Helper function that escapes characters in strings -- >>> escapeChars "\\" -- "\\\\" -- >>> escapeChars "\"" -- "\\\"" -- >>> escapeChars "'" -- "\\'" escapeChars :: String -> String escapeChars [] = [] escapeChars ('\\':xs) = '\\' : '\\' : escapeChars xs escapeChars ('\"':xs) = '\\' : '\"' : escapeChars xs escapeChars ('\'':xs) = '\\' : '\'' : escapeChars xs escapeChars (x:xs) = x : escapeChars xs fstCharUpper :: String -> String fstCharUpper (x:xs) = if isUpper x then x : xs else toUpper x : xs fstCharUpper [] = panic "Name string is empty" fstCharLower :: String -> String fstCharLower (x:xs) = if isLower x then x : xs else toLower x : xs fstCharLower [] = panic "Name string is empty"