#define STRINGIFY(A) #A
const GLchar* source = STRINGIFY(
uniform sampler2D tex0;
uniform sampler2D tex1;
void main() {
vec4 s1 = texture2D(tex0, gl_TexCoord[0].st);
vec4 s2 = texture2D(tex1, gl_TexCoord[0].st + vec2(0.0625, 0.0625));
gl_FragColor = mix(vec4(1, s1.g, s1.b, 0.5), vec4(s2.r, s2.g, 1, 0.5), 0.5);
}
);
s := DoSomeStringMagics(
line1
line2
);
convert into:s := ' line1#13#10 line2';
with spaces and line changes included.edit: yay, 1000th post :D996 :)
When it's a one off I always use something like notepad++ to quote the lines by use of regular expressions.
program txt2const;
{$mode objfpc}{$H+}
uses
Classes, sysutils;
var
Src,Dst: TStringList;
I: Integer;
begin
if Paramcount<3 then
begin
WriteLn;
WriteLn(ExtractFileName(ParamStr(0))+' <source> <dest> <const name>');
Exit;
end;
try
Src:= TStringList.Create;
Dst:= TStringList.Create;
Src.LoadFromFile(ParamStr(1));
Dst.Add(ParamStr(3)+': String = ');
for I:=0 to Src.Count-2 do
Dst.Add(' ' + QuotedStr(Src[I]) + '#13#10+');
if Src.Count>1 then
Dst.Add(' ' + QuotedStr(Src[Src.Count-1]) + ';');
Dst.SaveToFile(ParamStr(2));
finally
Src.Free;
Dst.Free;
end;
end.
function PascalizeString(SourceString: string): string;
var
i: integer;
Target: TStringList;
begin
Target:=TStringList.Create;
try
Target.Text:=SourceString;
for i:=0 to Target.Count-1 do
begin
if i<Target.Count-1 then
Target[i]:=QuotedStr(Target[i])+' + LineEnding +'
else
Target[i]:=QuotedStr(Target[i])+';';
end;
result:=Target.Text;
finally
Target.Free;
end;
end;
Still would like to see this functionality [1] as an Edit/Paste special option inside the IDE (i.e. text on clipboard gets pasted as quoted string - multiline with line endings etc if needed)...Well, since you know the IDE quite well (I guess), why don't you add that functionality to the... refactoring menu perhaps?
Perhaps using an .lpk but I guess I can always try and write a Pascalscript macro ;)
Hi Leledumbo.... nah, I don't know the IDE that well at all TBH... I've just dabbled a bit with getting help files improved, really.QuoteStill would like to see this functionality [1] as an Edit/Paste special option inside the IDE (i.e. text on clipboard gets pasted as quoted string - multiline with line endings etc if needed)...Well, since you know the IDE quite well (I guess), why don't you add that functionality to the... refactoring menu perhaps?
Perhaps using an .lpk but I guess I can always try and write a Pascalscript macro ;)
You can extend the IDE to do this, by adding a macro. (trunk/upcoming 1.2)Hi Martin,
http://wiki.lazarus.freepascal.org/Editor_Macros_PascalScript
but I guess I can always try and write a Pascalscript macro ;)
procedure PascalizeString(Source: string; var Target: TStringList);
var
i: integer;
begin
Target.Text:=Source;
for i:=0 to Target.Count-1 do
begin
if i<Target.Count-1 then
Target[i]:=QuotedStr(Target[i])+' + LineEnding +'
else
Target[i]:=QuotedStr(Target[i])+';';
end;
end;
var
i: integer;
First,Last: TPoint;
SelectionText: string;
ResultList: TStringList;
begin
// Make sure text is selected:
if not Caller.SelAvail then exit;
First := Caller.BlockBegin;
Last := Caller.BlockEnd;
// Switch around if backward selection:
if (First.y > Last.y) or ((First.y = Last.y) and (First.x > Last.x)) then begin
First := Caller.BlockEnd;
Last := Caller.BlockBegin;
end;
// Copy over selected text
ResultList:=TStringList.Create;
try
for i:=First to Last do
begin
if i=First then
SelectionText:=Caller.Lines[i]
else
SelectionText:=SelectionText+LineEnding+Caller.Lines[i];
end;
PascalizeString(SelectionText,ResultList);
Caller.CutToClipBoard; //Cut out original text
ClipBoard.AsText:=ResultList.Text; //Assign our own variable
Caller.PasteFromClipBoard;
finally
ResultList.Free;
end;
end.
PascalScript doesn't seem to support tstringlist or I need to "register" support for it or something? How would I do that?