home *** CD-ROM | disk | FTP | other *** search
/ Prima Shareware 3 / DuCom_Prima-Shareware-3_cd1.bin / PROGRAMO / delphi / TPOP3 / MSGUTILS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-04-26  |  2.3 KB  |  109 lines

  1. unit Msgutils;
  2.  
  3. interface
  4.  
  5. uses Classes,SysUtils;
  6.  
  7. function TrimStr(s : string) : string;
  8. procedure TrimStringList(SL : TStrings);
  9. function GetHeaderValue(Hdr : TStrings; const ID : string) : string;
  10. function GetParameter(const p : string; s : string) : string;
  11. function AddBackSlash(const DirName : string) : string;
  12.  
  13. const
  14.   InvStr = '$$Unable to Get$$';
  15.  
  16. implementation
  17.  
  18. function TrimStr(s : string) : string;
  19. begin
  20.   while (Length(s)>0) and (s[1] in [' ',^I]) do
  21.     Delete(s,1,1);
  22.   while (Length(s)>0) and (s[Length(s)] in [' ',^I]) do
  23.     Delete(s,Length(s),1);
  24.   result:=s;
  25. end;
  26.  
  27. procedure TrimStringList(SL : TStrings);
  28. begin
  29.   with SL do
  30.   begin
  31.     while (Count>0) and (Strings[0]='') do
  32.       Delete(0);
  33.     while (Count>0) and (Strings[Count-1]='') do
  34.       Delete(Count-1);
  35.   end;
  36. end;
  37.  
  38. function GetHeaderValue(Hdr : TStrings; const ID : string) : string;
  39. var
  40.   Found : boolean;
  41.   i,j : Integer;
  42. begin
  43.   Found:=false; Result:='';
  44.   for i:=0 to Hdr.Count-1 do
  45.   if Pos(UpperCase(ID),UpperCase(Hdr[i]))=1 then
  46.   begin
  47.     Found:=true;
  48.     Break;
  49.   end;
  50.   if Found then
  51.   begin
  52.     Result:=Hdr[i];
  53.     j:=Pos(':',Result);
  54.     Delete(Result,1,j+1);
  55.     Result:=TrimStr(Result);
  56.     Inc(i);
  57.     while (i<=Hdr.Count-1) and (Pos(':',Hdr[i])=0) do
  58.     begin
  59.       Result:=Concat(Result,' ',TrimStr(Hdr[i]));
  60.       Inc(i);
  61.     end;
  62.   end;
  63. end;
  64.  
  65. function GetParameter(const p : string; s : string) : string;
  66. {Gets p="value" or p=value, returns 'value'}
  67. {April 07, 1996, removing trailing ;}
  68. var
  69.   i : Integer;
  70.   LastCh : Char;
  71. begin
  72.   Result:=InvStr;
  73.   i:=Pos(UpperCase(p),UpperCase(s));
  74.   if i<>0 then
  75.   begin
  76.     Result:='';
  77.     Delete(s,1,i+Length(p));
  78.     s:=TrimStr(s);
  79.     if s[1]='"' then
  80.     begin
  81.       LastCh:='"';
  82.       i:=2;
  83.     end
  84.     else
  85.     begin
  86.       LastCh:=' ';
  87.       i:=1;
  88.     end;
  89.     while (i<=Length(s)) and (s[i]<>LastCh) do
  90.     begin
  91.       Result:=Concat(Result,s[i]);
  92.       Inc(i);
  93.     end;
  94.     if Result[Length(Result)]=';' then
  95.       Delete(Result,Length(Result),1);
  96.     Result:=TrimStr(Result);
  97.   end;
  98. end;
  99.  
  100. function AddBackSlash(const DirName : string) : string;
  101. begin
  102.   if (Length(DirName)>0) and (DirName[Length(DirName)]<>'\')
  103.     then Result:=Concat(DirName,'\')
  104.   else
  105.     Result:=DirName;
  106. end;
  107.  
  108. end.
  109.