rejetto forum

Software => HFS ~ HTTP File Server => Programmers corner => Topic started by: Mars on February 04, 2010, 10:01:44 PM

Title: \n
Post by: Mars on February 04, 2010, 10:01:44 PM
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)
Title: \n
Post by: rejetto on February 08, 2010, 11:16:47 AM
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;
Title: \n
Post by: Mars on February 08, 2010, 05:59:01 PM
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

Title: \n
Post by: rejetto on February 09, 2010, 05:30:59 PM
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.