pragmarc_20240810.0.0_fc017aa4/src/pragmarc-mixed_case.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
-- PragmAda Reusable Component (PragmARC)
-- Copyright (C) 2021 by PragmAda Software Engineering.  All rights reserved.
-- Released under the terms of the BSD 3-Clause license; see https://opensource.org/licenses
-- **************************************************************************
--
-- History:
-- 2021 May 01     J. Carter          V2.1--Adhere to coding standard
-- 2020 Nov 01     J. Carter          V2.0--Initial Ada-12 version
----------------------------------------------------------------------------
-- 2000 Dec 01     J. Carter          V1.0--Initial release
--
with Ada.Characters.Handling;

function PragmARC.Mixed_Case (S : in String) return String is
   Result : String (S'range);
   Upper  : Boolean := True; -- True if next character should be upper case; True for 1st character
begin -- PragmARC.Mixed_Case
   All_Chars : for I in S'range loop
      if Upper then
         Result (I) := Ada.Characters.Handling.To_Upper (S (I) );
      else
         Result (I) := Ada.Characters.Handling.To_Lower (S (I) );
      end if;

      Upper := S (I) in '_' | '.'; -- Character following an underline or dot should be upper case
   end loop All_Chars;

   return Result;
end PragmARC.Mixed_Case;