----------------------------------------------------------------------------- -- -- libwww-ada95 : A World Wide Web client library for Ada95 -- -- W W W . F I E L D _ N A M E S -- -- B o d y -- -- Copyright (C) 1997-1998 Regents of the University of California -- -- libwww-ada95 is free software; you can redistribute it and/or modify it -- under the terms of the GNU General Public License as published by the Free -- Software Foundation, with or without the single exception listed below; -- either version 2, or (at your option) any later version. libwww-ada95 is -- distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; -- without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -- PARTICULAR PURPOSE. See the GNU General Public License for more details. -- You should have received a copy of the GNU General Public License -- distributed with libwww-ada95; see the file COPYING. If not, write to the -- Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- 02111-1307, USA. -- -- As a special exception, if other files instantiate generics from this -- library, or you link this library with other files to produce an -- executable, this library does not by itself cause the resulting -- executable to be covered by the GNU General Public License. This -- exception does not however invalidate any other reasons why the -- executable file might be covered by the GNU General Public License. -- -- Created in 1997 by Kari Nies ----------------------------------------------------------------------------- package body WWW.Field_Names is -- for Nazi style checker function Lower_Case (UBS : UB_String) return STRING; function Replace_Hypens (UBS : UB_String) return String; function Check_Special_Cases (Field_Name : UB_String) return Field_Name; -- convert a unbounded string to a lower case constrained string function Lower_Case (UBS : UB_String) return STRING is S : STRING (1 .. UB_Strings.Length (UBS)) := UB_Strings.To_String (UBS); C : CHARACTER; begin for i in 1 .. S'Length loop C := S (i); if C in 'A' .. 'Z' then S (i) := Character'Val (Character'Pos (C) + Character'Pos ('a') - Character'Pos ('A')); end if; end loop; return S; end Lower_Case; -- convert a unbounded string to a constrained string with all hyphens -- converted to underscores function Replace_Hypens (UBS : UB_String) return String is S : STRING (1 .. UB_Strings.Length (UBS)) := UB_Strings.To_String (UBS); C : CHARACTER; begin for i in 1 .. S'Length loop C := S (i); if C = '-' then S (i) := '_'; end if; end loop; return S; end Replace_Hypens; use UB_Strings; function Check_Special_Cases (Field_Name : UB_String) return Field_Name is Lower_Field_Name : UB_String := UB_Strings.To_Unbounded_String (Lower_Case (Field_Name)); begin if Lower_Field_Name = "pragma" then return XPragma; elsif Lower_Field_Name = "accept" then return XAccept; elsif Lower_Field_Name = "range" then return XRange; else return Unknown; end if; end Check_Special_Cases; function Parse_Field_Name (FN_Str : UB_String) return Field_Name is begin -- try straign coversion return Field_Name'Value (Replace_Hypens (FN_Str)); exception when CONSTRAINT_ERROR => -- guaranteed to return special case or unknown return Check_Special_Cases (FN_Str); end Parse_Field_Name; function Field_Name_2_Id (FN : Field_Name) return NATURAL is begin return Field_Name'Pos (FN); end Field_Name_2_Id; end WWW.Field_Names;