Fix build procedure.
[morzhol.git] / src / morzhol-strings.adb
blob3d0f1cafb8ea396e1159602f877cd647ecc556e9
1 ------------------------------------------------------------------------------
2 -- Morzhol --
3 -- --
4 -- Copyright (C) 2007-2008 --
5 -- Pascal Obry - Olivier Ramonat --
6 -- --
7 -- This library is free software; you can redistribute it and/or modify --
8 -- it under the terms of the GNU General Public License as published by --
9 -- the Free Software Foundation; either version 2 of the License, or (at --
10 -- your option) any later version. --
11 -- --
12 -- This library is distributed in the hope that it will be useful, but --
13 -- WITHOUT ANY WARRANTY; without even the implied warranty of --
14 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
15 -- General Public License for more details. --
16 -- --
17 -- You should have received a copy of the GNU General Public License --
18 -- along with this library; if not, write to the Free Software Foundation, --
19 -- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. --
20 ------------------------------------------------------------------------------
22 package body Morzhol.Strings is
24 ------------------
25 -- HTML_To_Text --
26 ------------------
28 function HTML_To_Text (HTML_Source : in String) return String is
30 subtype Source_Range is Positive range HTML_Source'Range;
32 Result : Unbounded_String;
33 Last : Integer := HTML_Source'First;
34 To_Skip : Natural := 0;
36 procedure Find_End_Tag (Position : in Source_Range);
37 -- Find end tag
39 ------------------
40 -- Find_End_Tag --
41 ------------------
43 procedure Find_End_Tag (Position : in Source_Range) is
44 begin
45 for L in Position + 1 .. HTML_Source'Last loop
46 if HTML_Source (L) = '>' then
47 To_Skip := L - Position;
48 Last := L + 1;
49 return;
50 end if;
51 end loop;
52 end Find_End_Tag;
54 begin
55 Skip_HTML_Tag :
56 for K in HTML_Source'Range loop
57 if To_Skip /= 0 then
58 To_Skip := To_Skip - 1;
60 else
61 if HTML_Source (K) = '<' then
62 Append (Result, HTML_Source (Last .. K - 1));
63 Find_End_Tag (K);
65 if To_Skip = 0 then
66 -- No last end tag
67 Last := HTML_Source'Last;
68 end if;
69 end if;
70 end if;
71 end loop Skip_HTML_Tag;
73 if Last < HTML_Source'Last then
74 Append (Result, HTML_Source (Last .. HTML_Source'Last));
75 end if;
77 return -Result;
78 end HTML_To_Text;
80 end Morzhol.Strings;