📄 cxa4026.a
字号:
-- CXA4026.A---- Grant of Unlimited Rights---- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained -- unlimited rights in the software and documentation contained herein.-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making -- this public release, the Government intends to confer upon all -- recipients unlimited rights equal to those held by the Government. -- These rights include rights to use, duplicate, release or disclose the -- released technical data and computer software in whole or in part, in -- any manner and for any purpose whatsoever, and to have or permit others -- to do so.---- DISCLAIMER---- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A-- PARTICULAR PURPOSE OF SAID MATERIAL.--*---- OBJECTIVE:-- Check that Ada.Strings.Fixed procedures Head, Tail, and Trim, as well -- as the versions of subprograms Translate (procedure and function), -- Index, and Count, available in the package which use a -- Maps.Character_Mapping_Function input parameter, produce correct -- results.---- TEST DESCRIPTION:-- This test examines the operation of several subprograms contained in-- the Ada.Strings.Fixed package. -- This includes procedure versions of Head, Tail, and Trim, as well as-- four subprograms that use a Character_Mapping_Function as a parameter -- to provide the mapping capability.-- -- Two functions are defined to provide the mapping. Access values -- are defined to refer to these functions. One of the functions will-- map upper case characters in the range 'A'..'Z' to their lower case-- counterparts, while the other function will map lower case characters-- ('a'..'z', or a character whose position is in one of the ranges -- 223..246 or 248..255, provided the character has an upper case form)-- to their upper case form.-- -- Function Index uses the mapping function access value to map the input-- string prior to searching for the appropriate index value to return.-- Function Count uses the mapping function access value to map the input-- string prior to counting the occurrences of the pattern string.-- Both the Procedure and Function version of Translate use the mapping-- function access value to perform the translation.---- Results of all subprograms are compared with expected results.-- -- -- CHANGE HISTORY:-- 10 Feb 95 SAIC Initial prerelease version-- 21 Apr 95 SAIC Modified definition of string variable Str_2.----!package CXA4026_0 is -- Function Map_To_Lower_Case will return the lower case form of -- Characters in the range 'A'..'Z' only, and return the input -- character otherwise. function Map_To_Lower_Case (From : Character) return Character; -- Function Map_To_Upper_Case will return the upper case form of -- Characters in the range 'a'..'z', or whose position is in one -- of the ranges 223..246 or 248..255, provided the character has -- an upper case form. function Map_To_Upper_Case (From : Character) return Character;end CXA4026_0;with Ada.Characters.Handling;package body CXA4026_0 is function Map_To_Lower_Case (From : Character) return Character is begin if From in 'A'..'Z' then return Character'Val(Character'Pos(From) - (Character'Pos('A') - Character'Pos('a'))); else return From; end if; end Map_To_Lower_Case; function Map_To_Upper_Case (From : Character) return Character is begin return Ada.Characters.Handling.To_Upper(From); end Map_To_Upper_Case;end CXA4026_0;with CXA4026_0;with Ada.Strings.Fixed;with Ada.Strings.Maps;with Ada.Characters.Handling;with Ada.Characters.Latin_1;with Report;procedure CXA4026 isbegin Report.Test ("CXA4026", "Check that procedures Trim, Head, and Tail, " & "as well as the versions of subprograms " & "Translate, Index, and Count, which use the " & "Character_Mapping_Function input parameter," & "produce correct results"); Test_Block: declare use Ada.Strings, CXA4026_0; -- The following strings are used in examination of the Translation -- subprograms. New_Character_String : String(1..10) := Ada.Characters.Latin_1.LC_A_Grave & Ada.Characters.Latin_1.LC_A_Ring & Ada.Characters.Latin_1.LC_AE_Diphthong & Ada.Characters.Latin_1.LC_C_Cedilla & Ada.Characters.Latin_1.LC_E_Acute & Ada.Characters.Latin_1.LC_I_Circumflex & Ada.Characters.Latin_1.LC_Icelandic_Eth & Ada.Characters.Latin_1.LC_N_Tilde & Ada.Characters.Latin_1.LC_O_Oblique_Stroke & Ada.Characters.Latin_1.LC_Icelandic_Thorn; TC_New_Character_String : String(1..10) := Ada.Characters.Latin_1.UC_A_Grave & Ada.Characters.Latin_1.UC_A_Ring & Ada.Characters.Latin_1.UC_AE_Diphthong & Ada.Characters.Latin_1.UC_C_Cedilla & Ada.Characters.Latin_1.UC_E_Acute & Ada.Characters.Latin_1.UC_I_Circumflex & Ada.Characters.Latin_1.UC_Icelandic_Eth & Ada.Characters.Latin_1.UC_N_Tilde & Ada.Characters.Latin_1.UC_O_Oblique_Stroke & Ada.Characters.Latin_1.UC_Icelandic_Thorn; -- Functions used to supply mapping capability. -- Access objects that will be provided as parameters to the -- subprograms. Map_To_Lower_Case_Ptr : Maps.Character_Mapping_Function := Map_To_Lower_Case'Access; Map_To_Upper_Case_Ptr : Maps.Character_Mapping_Function := Map_To_Upper_Case'Access; begin -- Function Index, Forward direction search. -- Note: Several of the following cases use the default value -- Forward for the Going parameter. if Fixed.Index(Source => "The library package Strings.Fixed", Pattern => "fix", Going => Ada.Strings.Forward, Mapping => Map_To_Lower_Case_Ptr) /= 29 or Fixed.Index("THE RAIN IN SPAIN FALLS MAINLY ON THE PLAIN", "ain", Mapping => Map_To_Lower_Case_Ptr) /= 6 or Fixed.Index("maximum number", "um", Ada.Strings.Forward, Map_To_Lower_Case_Ptr) /= 6 or Fixed.Index("CoMpLeTeLy MiXeD CaSe StRiNg", "MIXED CASE STRING", Ada.Strings.Forward, Map_To_Upper_Case_Ptr) /= 12 or Fixed.Index("STRING WITH NO MATCHING PATTERNS", "WITH", Ada.Strings.Forward, Map_To_Lower_Case_Ptr) /= 0 or Fixed.Index("THIS STRING IS IN UPPER CASE", "IS", Ada.Strings.Forward, Map_To_Upper_Case_Ptr) /= 3 or Fixed.Index("", -- Null string. "is", Mapping => Map_To_Lower_Case_Ptr) /= 0 or Fixed.Index("AAABBBaaabbb", "aabb", Mapping => Map_To_Lower_Case_Ptr) /= 2 then Report.Failed("Incorrect results from Function Index, going " & "in Forward direction, using a Character Mapping " & "Function parameter"); end if; -- Function Index, Backward direction search. if Fixed.Index("Case of a Mixed Case String", "case", Ada.Strings.Backward, Map_To_Lower_Case_Ptr) /= 17 or Fixed.Index("Case of a Mixed Case String", "CASE", Ada.Strings.Backward, Map_To_Upper_Case_Ptr) /= 17 or Fixed.Index("rain, Rain, and more RAIN", "rain", Ada.Strings.Backward, Map_To_Lower_Case_Ptr) /= 22 or Fixed.Index("RIGHT place, right time", "RIGHT", Ada.Strings.Backward, Map_To_Upper_Case_Ptr) /= 14 or Fixed.Index("WOULD MATCH BUT FOR THE CASE", "WOULD MATCH BUT FOR THE CASE", Ada.Strings.Backward, Map_To_Lower_Case_Ptr) /= 0 then Report.Failed("Incorrect results from Function Index, going " & "in Backward direction, using a Character Mapping " & "Function parameter"); end if; -- Function Index, Pattern_Error if Pattern = Null_String declare use Ada.Strings.Fixed; Null_Pattern_String : constant String := ""; TC_Natural : Natural := 1000; begin TC_Natural := Index("A Valid String", Null_Pattern_String, Ada.Strings.Forward, Map_To_Lower_Case_Ptr); Report.Failed("Pattern_Error not raised by Function Index when " & "given a null pattern string"); exception when Pattern_Error => null; -- OK, expected exception. when others => Report.Failed("Incorrect exception raised by Function Index " & "using a Character Mapping Function parameter " & "when given a null pattern string"); end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -