MakeStringLiteral.pas

File name
MakeStringLiteral.pas
Date exported
Time exported
Formatting processor
TPascalFormattingProcessor
function MakeStringLiteral(const AString: string): string;
begin
  var InText := False;
  Result := '';
  for var c in AString do
    if C.IsControl then
    begin
      if InText then
      begin
        Result := Result + '''';
        InText := False;
      end;
      Result := Result + '#$' + IntToHex(Ord(C));
    end
    else
    begin
      if not InText then
        Result := Result + '''';
      Result := Result + C;
      if C = '''' then
        Result := Result + '''';
      InText := True;
    end;
  if InText then
    Result := Result + '''';
  if Result.IsEmpty then
    Result := '''''';
end;