rejetto forum

\n

Mars · 4 · 1343

0 Members and 1 Guest are viewing this topic.

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
Result of a laborious work

Quote
 end; // dir

 function dectochar(s:string):string;
  var
   j:integer;
   tab: TStringDynArray;
  begin

  try
    result:='';
    tab:=split('#',s);
    for j := 0 to length(tab) - 1 do
      if tab[j]>'' then
        result:=result+chr(lo(strtoint(tab[j])));
  except end;
  end;


  procedure handleSymbol();
........



    if pars.Count < 1 then exit; // from here, only macros with parameters

   if name = 'dec to char' then
      result:=dectochar(p);


    if name = 'dir' then
      dir();

........

 result:=xtpl(result, [
 //   '\n', CRLF,                         <<<------- don't forget to coment this line        
    '%build-time%', floatToStrF((now()-buildTime)*SECONDS, ffFixed, 7,3)
  ]);


{.dec to char|#65#66#13#10#67#68.}  return     'AB'+CRLF+'CD'

AB
CD

{.replace|\-|{.dec to char|#45#13#10.}|\n|{.dec to char|#13#10.}|\t|{.dec to char|#09.}|The result\nof a labo\-rious work\tis often\nrewarded.}

The result
of a labo-
rious work   is often
rewarded


the 'DEC TO CHAR'  macro works only with  a consequentive succession of chap #xxx  ( xxx : value from 0 to 255)
« Last Edit: February 04, 2010, 10:04:14 PM by Mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13308
    • View Profile
the 'DEC TO CHAR'  macro works only with  a consequentive succession of chap #xxx  ( xxx : value from 0 to 255)

thank you for suggesting mars.
i ended up with {.chr.} because it supports also hex.
strToInt() supports $xx format. Since this is a pascal syntax, i wanted something more "standard", and opted for a leading "x" instead of "$".
syntax is {.chr|13|10|x0D|x0A.}
do you agree?

    if name = 'chr' then
      begin
      result:='';
      for i:=0 to pars.count-1 do
        try result:=result+chr (strToInt(replaceStr(pars[ i],'x','$')))
        except end;
      end;
« Last Edit: February 08, 2010, 11:23:15 AM by rejetto »


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
Your proposition corresponds to my waits, an only small suggestion for a shorter code:

    if name = 'chr' then
       try
         for i:=0 to pars.count-1 do
            result:=result+chr (strToInt(replaceStr(pars[ i],'x','$')))
       except result:='' end;

one suggestion to users:
uses the section

[special:alias]
CRLF=chr|13|10
TAB=chr|09
convert to=replace|\n|{.CRLF.}|\t|{.TAB.}|$0

« Last Edit: February 08, 2010, 06:20:19 PM by Mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13308
    • View Profile
Your proposition corresponds to my waits, an only small suggestion for a shorter code:

that's not just shorter. it does something different. i don't see why discard everything for one bad code.