Advertisement
mixster

mixster

Sep 24th, 2008
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.07 KB | None | 0 0
  1. program Meow;
  2. function ReplaceMix(str, find, repl, punc: string): string;
  3. var
  4.   i, x: Integer;
  5.   mat: Boolean;
  6. begin
  7.   repeat
  8.     i := PosEx(find, str, i + 1);
  9.     if i <= 0 then
  10.       Break;
  11.     for x := 1 to Length(punc) do
  12.       if not mat then
  13.         if str[i - 1] = punc[x] then
  14.           mat := True;
  15.     if not mat then
  16.       Continue;
  17.     for x := 1 to Length(punc) do
  18.       if not mat then
  19.         if str[i + Length(find) + 1] = punc[x] then
  20.           mat := True;
  21.     if not mat then
  22.       Continue;
  23.     Delete(str, i, Length(find));
  24.     Insert(repl, str, i);
  25.     i := i + Length(repl);
  26.   until false;
  27.   Result := str;
  28. end;
  29.  
  30. function ExportAsHTML(input: string): string;
  31. var
  32.   KeyWords: TStringArray;
  33.   header, punct: string;
  34.   i, x, y: integer;
  35. begin
  36.   punct := ' [!"%&''()*+,-./:;<=>?@[\]_`{|}~]' + #13#10;
  37.   KeyWords := ['begin', 'end', 'else', 'try', ' except ', ' finally ', ' finally ', ' repeat ', ' until ', ' procedure ', ' function ', ' var ', ' const ', ' if ', ' string ', ' and ', ' array ', ' as ', ' case ', ' class ', ' const ', ' div ', ' do ', ' downto ', ' end ', ' for ', ' goto ', ' in ', ' is' , ' mod ', ' not ', ' object ', ' of ', ' on ', ' or ', ' procedure ', ' program ', ' record ', ' repeat ', ' set ', ' shl ', ' shr ', ' then ', ' to ', ' type ', ' while ', ' with ', ' xor ', ' forward '];
  38.   header := '<html>' + #13#10 + '  <head>' + #13#10 + '    <title>DanCardin</title>' + #13#10 + '    <script>' + #13#10 + '      .key { font-weight: bold;}' + #13#10 + '      .string { color: fuchsia;}' + #13#10 + '      .comment { color: green;}' + #13#10 + '    </script>' + #13#10 + '  </head>' + #13#10 + '  <body>' + #13#10;
  39.   Result := LowerCase(input);
  40.   if (Trim(Result) = '') then
  41.     Exit;
  42.   Result := ' ' + Replace(Result, Chr(13) + Chr(10), '  ') + ' ';
  43.   for i := 0 to high(keywords) do
  44.     Result := ReplaceMix(Result, KeyWords[i], '<div class="key">' + keywords[i] + '</div>', punct);
  45.   Result := header + Result + #13#10 + '  </body>' + #13#10 + '</html>';
  46. end;
  47.  
  48. begin
  49.   Writeln(ExportAsHTML('begin end; meow .try.'));
  50. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement