% This file is only intended to be input by Tcode_Ccode.tex

%%%   String and Char prefixes   %%%

%Chek the combination of prefix (L, u, u8 or U) + ' or ".
%We take advantage and define them to the format we want for each case.

%For the \edef's that follow
\let\FormatToApply\relax
\let\FormatNextCharLit\relax
\let\FormatNextString\relax
\catcode`'=11
\catcode`"=11
\catcode`8=11

{%local-global in oder to avoid \csFormat defining anything
\xdef\FormatCharLitCDefault{\csFormat{CharLit}} %The default, for char literals without prefix
%
\xdef\CPrefix@L@'{
  \let\FormatToApply\csFormat{CharWPrefix}
  \let\FormatNextCharLit\csFormat{CharLitW}
}
\global\let\CPrefix@u@'\CPrefix@L@'
\global\let\CPrefix@U@'\CPrefix@L@'

\xdef\CPrefix@u8@'{
  \let\FormatToApply\csFormat{CharPrefix}
  \let\FormatNextCharLit\csFormat{CharLit}
}

\xdef\FormatStrCDefault{\csFormat{String}} %The default, for strings without prefix
%
\xdef\CPrefix@L@"{
  \let\FormatToApply\csFormat{StrWPrefix}
  \let\FormatNextString\csFormat{StringWide}
}
\global\let\CPrefix@u@"\CPrefix@L@"
\global\let\CPrefix@U@"\CPrefix@L@"
\global\edef\CPrefix@u8@"{
  \let\FormatToApply\csFormat{StrPrefix}
  \let\FormatNextString\csFormat{String}
}
}

\catcode`'=12
\catcode`"=12
\catcode`8=12

\TcodeCcode@Reload@A{
  \let\FormatNextCharLit\FormatCharLitCDefault
  \let\FormatNextString\FormatStrCDefault
}
\the\TcodeCcode@Reload@A

\def\PrePrintCPrefixHook{\PrePrintHook}

%We must use the indirect \Format...Default in case the formatting of the plain string changes midway between strings; likewise for CharLit
\def\NcodeParseCCharLiteral#1'{{\SetEscapeChars\FormatNextCharLit '#1'}\let\FormatNextCharLit\FormatCharLitCDefault\@parsecode}
\def\NcodeParseCString#1"{{\SetEscapeChars\FormatNextString "#1"}\let\FormatNextString\FormatStrCDefault\@parsecode}
%Inisde the enironment Code. No need of \SetEscapeChars here
\def\CodeParseCString#1"{\global\let\CContinueInTheMiddle\FormatNextString{\FormatNextString "#1"}\global\let\FormatNextString\FormatStrCDefault\@parsecode}
