1
-------------------------------------------------------------------------------
3
-- This file is part of AdaBrowse.
5
-- <STRONG>Copyright (c) 2002 by Thomas Wolf.</STRONG>
7
-- AdaBrowse is free software; you can redistribute it and/or modify it
8
-- under the terms of the GNU General Public License as published by the
9
-- Free Software Foundation; either version 2, or (at your option) any
10
-- later version. AdaBrowse is distributed in the hope that it will be
11
-- useful, but <EM>without any warranty</EM>; without even the implied
12
-- warranty of <EM>merchantability or fitness for a particular purpose.</EM>
13
-- See the GNU General Public License for more details. You should have
14
-- received a copy of the GNU General Public License with this distribution,
15
-- see file "<A HREF="GPL.txt">GPL.txt</A>". If not, write to the Free
16
-- Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21
-- Author:</STRONG><DD>
23
-- <ADDRESS><A HREF="mailto:twolf@acm.org">twolf@acm.org</A></ADDRESS></DL>
26
-- Purpose:</STRONG><DD>
27
-- Miscellaneous text utilities.</DL>
32
-- 02-FEB-2002 TW First release.
33
-- 07-FEB-2002 TW Added 'Quote'.
34
-- 06-JUN-2003 TW Added 'To_Lower' and 'To_Upper'.
35
-- 11-JUN-2003 TW Added 'Canonical'.
37
-------------------------------------------------------------------------------
41
with Ada.Strings.Fixed;
42
with Ada.Strings.Maps;
46
pragma Elaborate_All (Util.Pathes);
48
package body AD.Text_Utilities is
50
package ASF renames Ada.Strings.Fixed;
51
package ASM renames Ada.Strings.Maps;
55
----------------------------------------------------------------------------
57
To_Dir_Sep : constant ASM.Character_Mapping :=
60
Util.Pathes.Directory_Separator & Util.Pathes.Directory_Separator);
61
-- Map both, so that this works on Unix and Windows!
64
(Suspicious_Name : in String)
68
return ASF.Translate (Suspicious_Name, To_Dir_Sep);
71
----------------------------------------------------------------------------
74
(Unit_Name : in String;
75
Suffix : in String := "ads")
78
Result : String (1 .. Unit_Name'Length + 1 + Suffix'Length);
81
for J in Unit_Name'Range loop
82
if Unit_Name (J) = '.' then
85
Result (I) := To_Lower (Unit_Name (J));
89
if Suffix'Last < Suffix'First then
90
return Result (1 .. I - 1);
93
Result (I + 1 .. Result'Last) := Suffix;
97
----------------------------------------------------------------------------
103
I : constant Natural := ASF.Index (S, Blanks);
105
if I = 0 then return S; end if; -- No white space
107
Result : String (1 .. I - S'First + 2 * (S'Last - I + 1) + 2);
108
-- Maximum needed length.
112
for J in S'Range loop
114
Result (K) := '\'; K := K + 1;
116
Result (K) := S (J); K := K + 1;
119
return Result (1 .. K);
123
end AD.Text_Utilities;