<commit_before>This module deals with printing C string literals 

\begin{code}
module CStrings(
	CLabelString, isCLabelString, pprCLabelString,

	cSEP, pp_cSEP,

	stringToC, charToC, pprFSInCStyle,
	charToEasyHaskell
  ) where

#include "HsVersions.h"

import Char	( ord, chr, isAlphaNum )
import Outputable
\end{code}


\begin{code}
type CLabelString = FAST_STRING		-- A C label, completely unencoded

pprCLabelString lbl = ptext lbl

isCLabelString :: CLabelString -> Bool	-- Checks to see if this is a valid C label
isCLabelString lbl 
  = all ok (_UNPK_ lbl)
  where
    ok c = isAlphaNum c || c == '_' || c == '.'
	-- The '.' appears in e.g. "foo.so" in the 
	-- module part of a ExtName.  Maybe it should be separate

cSEP    = SLIT("_")	-- official C separator
pp_cSEP = char '_'
\end{code}

\begin{code}
pprFSInCStyle :: FAST_STRING -> SDoc
pprFSInCStyle fs = doubleQuotes (text (stringToC (_UNPK_ fs)))

stringToC   :: String -> String
-- Convert a string to the form required by C in a C literal string
-- Tthe hassle is what to do w/ strings like "ESC 0"...
stringToC ""  = ""
stringToC [c] = charToC c
stringToC (c:cs)
    -- if we have something "octifiable" in "c", we'd better "octify"
    -- the rest of the string, too.
  = if (c < ' ' || c > '~')
    then (charToC c) ++ (concat (map char_to_C cs))
    else (charToC c) ++ (stringToC cs)<commit_msg>[project @ 2000-04-20 15:18:58 by simonmar] add	pprStringInCStyle :: String -> SDoc (we already have a FAST_STRING version but not one for plain Strings).<commit_after>This module deals with printing C string literals 

\begin{code}
module CStrings(
	CLabelString, isCLabelString, pprCLabelString,

	cSEP, pp_cSEP,

	stringToC, charToC, pprFSInCStyle, pprStringInCStyle,
	charToEasyHaskell
  ) where

#include "HsVersions.h"

import Char	( ord, chr, isAlphaNum )
import Outputable
\end{code}


\begin{code}
type CLabelString = FAST_STRING		-- A C label, completely unencoded

pprCLabelString lbl = ptext lbl

isCLabelString :: CLabelString -> Bool	-- Checks to see if this is a valid C label
isCLabelString lbl 
  = all ok (_UNPK_ lbl)
  where
    ok c = isAlphaNum c || c == '_' || c == '.'
	-- The '.' appears in e.g. "foo.so" in the 
	-- module part of a ExtName.  Maybe it should be separate

cSEP    = SLIT("_")	-- official C separator
pp_cSEP = char '_'
\end{code}

\begin{code}
pprFSInCStyle :: FAST_STRING -> SDoc
pprFSInCStyle fs = doubleQuotes (text (stringToC (_UNPK_ fs)))

pprStringInCStyle :: String -> SDoc
pprStringInCStyle s = doubleQuotes (text (stringToC s))

stringToC   :: String -> String
-- Convert a string to the form required by C in a C literal string
-- Tthe hassle is what to do w/ strings like "ESC 0"...
stringToC ""  = ""
stringToC [c] = charToC c
stringToC (c:cs)
    -- if we have something "octifiable" in "c", we'd better "octify"
    -- the rest of the string, too.
  = if (c < ' ' || c > '~')
    then (charToC c) ++ (concat (map char_to_C cs))
    else (charToC c) ++ (stringToC cs)
{'fraction_non_alphanumeric': 0.117096018735363, 'fraction_numerical': 0.005352960856473737, 'mean_word_length': 3.4827586206896552, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2626726', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1086, 'n_words': 373}