module BNFC.Backend.Common.StrUtils where
import Data.Char (ord)
renderCharOrString :: String -> (Char, String)
renderCharOrString :: String -> (Char, String)
renderCharOrString [Char
c] | Char -> Int
ord Char
c Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
255 = (Char
'C', Char -> String
forall a. Show a => a -> String
show Char
c)
renderCharOrString String
s = (Char
'S', String
"\"" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
escapeChars String
s String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\"")
escapeChars :: String -> String
escapeChars :: String -> String
escapeChars [] = []
escapeChars (Char
'\\':String
xs) = Char
'\\' Char -> String -> String
forall a. a -> [a] -> [a]
: Char
'\\' Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
escapeChars String
xs
escapeChars (Char
'\"':String
xs) = Char
'\\' Char -> String -> String
forall a. a -> [a] -> [a]
: Char
'\"' Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
escapeChars String
xs
escapeChars (Char
'\'':String
xs) = Char
'\\' Char -> String -> String
forall a. a -> [a] -> [a]
: Char
'\'' Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
escapeChars String
xs
escapeChars (Char
x:String
xs) = Char
x Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
escapeChars String
xs