home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / nastroje / RTF2HTML.ZIP / MDFUNCS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-06-25  |  5.6 KB  |  200 lines

  1. unit Mdfuncs;
  2.  
  3. interface
  4.  
  5. uses
  6.   Classes, StdCtrls;
  7.  
  8. function Uml_In(const Word: String): boolean;
  9. function ReplaceIn(SearchFor, ReplaceStr, Str : String) : String;
  10. function WcReplaceIn(SearchFor, ReplaceStr, Str : String; wcrange: integer) : String;
  11. function ReplaceAll(const SearchFor: array of String; const ReplaceStr: array of String; Str: String) : String;
  12. procedure ReplaceAllStringlist(const SearchFor: array of String; const ReplaceStr: array of String; Text: TStringlist);
  13. procedure StringToWords(const str: String; Words: TStringlist);
  14. procedure MemoToWords(const Memo: TMemo; Words: TStringlist);
  15.  
  16. implementation
  17.  
  18. function Uml_In(const Word: String): boolean;
  19. { untersucht einen String auf vorkommende Umlaute und retourniert das entsprechende Boolean }
  20. begin
  21.     if (Pos('─',Word) <> 0)
  22.     or (Pos('Σ',Word) <> 0)
  23.     or (Pos('╓',Word) <> 0)
  24.     or (Pos('÷',Word) <> 0)
  25.     or (Pos('▄',Word) <> 0)
  26.     or (Pos('ⁿ',Word) <> 0)
  27.     then
  28.         Result := true
  29.     else
  30.         Result := false;
  31. end;
  32.  
  33. function wcStr(wcSearchStr: string; str: string; wcrange: integer) : string;
  34. { sucht einen Suchstring mit wildcard in einem anderen String und liefert den tatsΣchlichen Suchstring       }
  35. { (ohne wildcard) zurⁿck, wenn der an Stelle der wildcard hinzugefⁿgte String nicht lΣnger als wcrange ist   }
  36. var
  37.     i, j, wcpos, wcstrlen : integer;
  38.     st, st2 : string;
  39.  
  40. begin
  41.     st := str;
  42.     wcpos := Pos('*',wcSearchStr);
  43.     if (wcpos > 1) and (wcpos < length(wcSearchStr)) then    { wildcards nur innerhalb des Wortes }
  44.     begin
  45.         i := Pos(Copy(wcSearchStr, 1, wcpos-1), st);
  46.         st2 := Copy(st, i+wcpos-1, length(st)-i-wcpos+2);
  47.         j := Pos(Copy(wcSearchStr, wcpos+1, length(wcSearchStr)-wcpos), st2);
  48.  
  49.         wcstrlen := length(wcSearchStr)+j-2;
  50.         if (j > 0) and (i > 0) and (wcstrlen <= length(wcSearchStr)+wcrange-1) then
  51.             Result := Copy(St, i, wcstrlen)
  52.         else
  53.             Result := '';
  54.     end
  55.     else
  56.         Result := '';
  57. end;
  58.  
  59. function ReplaceIn(SearchFor, ReplaceStr, Str : String) : String;
  60. { ersetzt alle Vorkommen EINES Teilstrings in einem String }
  61. var
  62.   Dummy : String;
  63.   i : integer;
  64.   st : String;
  65. begin
  66.   st := Str;
  67.   i := Pos(SearchFor, St);
  68.   Dummy := '';
  69.     while i <> 0 do
  70.     begin
  71.       Dummy := Dummy + Copy(St, 0, i - 1) + ReplaceStr;
  72.       st := copy(st, i + length(SearchFor), length(st)+1);
  73.       i := Pos(SearchFor, St);
  74.     end;
  75.   Result := Dummy + st;
  76. end;
  77.  
  78.  
  79. function WcReplaceIn(SearchFor, ReplaceStr, Str : String; wcrange: integer) : String;
  80. { ersetzt alle Vorkommen EINES Teilstrings in einem String }
  81. var
  82.   Dummy : String;
  83.   i : integer;
  84.   St, St2 : String;
  85.   wildcard : boolean;
  86.  
  87. begin
  88.   st := Str;
  89.   wildcard := false;
  90.  
  91.   if Pos('*',SearchFor) > 0 then
  92.   begin
  93.       wildcard := true;
  94.       St2 := wcstr(SearchFor, Str, wcrange);
  95.       if St2 <> '' then
  96.           i := Pos(St2, St)
  97.       else
  98.           i := 0;
  99.   end
  100.   else
  101.       i := Pos(SearchFor, St);
  102.  
  103.   Dummy := '';
  104.   while i <> 0 do
  105.   begin
  106.       Dummy := Dummy + Copy(St, 0, i - 1) + ReplaceStr;
  107.  
  108.       if wildcard then
  109.       begin
  110.           st := copy(St, i + length(St2), length(st)+1);
  111.           St2 := wcstr(SearchFor, Str, wcrange);
  112.           if St2 <> '' then
  113.               i := Pos(St2, St)
  114.           else
  115.               i := 0;
  116.       end
  117.       else
  118.       begin
  119.           St := copy(St, i + length(SearchFor), length(st)+1);
  120.           i := Pos(SearchFor, St);
  121.       end;
  122.   end;
  123.   Result := Dummy + st;
  124. end;
  125.  
  126.  
  127. function ReplaceAll(const SearchFor: array of String; const ReplaceStr: array of String; Str: String) : String;
  128. { ersetzt alle Vorkommen ALLER im array angegebenen Teilstrings in einem String }
  129. var
  130.     i, submax: integer;
  131.     st: String;
  132. begin
  133.     st := Str;
  134.     submax := High(SearchFor);
  135.     if (submax = High(ReplaceStr)) then
  136.         for i := 0 to submax do
  137.             st := ReplaceIn (SearchFor[i], ReplaceStr[i], st);
  138.     Result := st;
  139. end;
  140.  
  141.  
  142. procedure ReplaceAllStringlist(const SearchFor: array of String; const ReplaceStr: array of String; Text: TStringlist);
  143. { ersetzt alle Vorkommen ALLER im array angegebenen Teilstrings in einer TStringList }
  144. var
  145.     i, j, submax: integer;
  146. begin
  147.     submax := High(SearchFor);
  148.     if (Text.Count > 0) and (submax = High(ReplaceStr)) then
  149.     for i := 0 to (Text.Count-1) do
  150.         for j := 0 to submax do
  151.             Text[i] := ReplaceIn (SearchFor[j], ReplaceStr[j], Text[i]);
  152. end;
  153.  
  154. procedure StringToWords(const str: String; Words: TStringlist);
  155. { zerlegt ein TMemo in Strings(gespeichert in TStringList), die nur Buchstaben bzw. Zahlen enthalten }
  156. var
  157.     i: integer;
  158.     w: String;
  159. begin
  160.     i := 0;
  161.     w := '';
  162.     while i < length(str) do
  163.     begin
  164.         while (str[i] in ['0'..'9','a'..'z','A'..'Z','─','╓','▄','Σ','÷','ⁿ','▀']) do
  165.         begin
  166.             w := w + str[i];
  167.             Inc(i);
  168.         end;
  169.         if length(w) > 0 then Words.Add(w);
  170.         w := '';
  171.         Inc(i);
  172.     end;
  173. end;
  174.  
  175. procedure MemoToWords(const Memo: TMemo; Words: TStringlist);
  176. { zerlegt ein TMemo in Strings(gespeichert in TStringList), die nur Buchstaben bzw. Zahlen enthalten }
  177. var
  178.     i, meml: integer;
  179.     w: String;
  180. begin
  181.     Memo.SelectAll;
  182.     meml := Memo.SelLength;
  183.     i := 0;
  184.     w := '';
  185.     while i <= meml do
  186.     begin
  187.         while (Memo.Text[i] in ['0'..'9','a'..'z','A'..'Z','─','╓','▄','Σ','÷','ⁿ','▀']) do
  188.         begin
  189.             w := w + Memo.Text[i];
  190.             Inc(i);
  191.         end;
  192.         if length(w) > 0 then Words.Add(w);
  193.         w := '';
  194.         Inc(i);
  195.     end;
  196. end;
  197.  
  198.  
  199. end.
  200.