annotate gcc/ada/libgnat/s-wchcnv.ads @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S Y S T E M . W C H _ C N V --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- This package contains generic subprograms used for converting between
kono
parents:
diff changeset
33 -- sequences of Character and Wide_Character. Wide_Wide_Character values
kono
parents:
diff changeset
34 -- are also handled, but represented using integer range types defined in
kono
parents:
diff changeset
35 -- this package, so that this package can be used from applications that
kono
parents:
diff changeset
36 -- are restricted to Ada 95 compatibility (such as the compiler itself).
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 -- All the algorithms for encoding and decoding are isolated in this package
kono
parents:
diff changeset
39 -- and in System.WCh_JIS and should not be duplicated elsewhere. The only
kono
parents:
diff changeset
40 -- exception to this is that GNAT.Decode_String and GNAT.Encode_String have
kono
parents:
diff changeset
41 -- their own circuits for UTF-8 conversions, for improved efficiency.
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 -- This unit may be used directly from an application program by providing
kono
parents:
diff changeset
44 -- an appropriate WITH, and the interface can be expected to remain stable.
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 pragma Compiler_Unit_Warning;
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 with System.WCh_Con;
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 package System.WCh_Cnv is
kono
parents:
diff changeset
51 pragma Pure;
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 type UTF_32_Code is range 0 .. 16#7FFF_FFFF#;
kono
parents:
diff changeset
54 for UTF_32_Code'Size use 32;
kono
parents:
diff changeset
55 -- Range of allowed UTF-32 encoding values
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 type UTF_32_String is array (Positive range <>) of UTF_32_Code;
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 generic
kono
parents:
diff changeset
60 with function In_Char return Character;
kono
parents:
diff changeset
61 function Char_Sequence_To_Wide_Char
kono
parents:
diff changeset
62 (C : Character;
kono
parents:
diff changeset
63 EM : System.WCh_Con.WC_Encoding_Method) return Wide_Character;
kono
parents:
diff changeset
64 -- C is the first character of a sequence of one or more characters which
kono
parents:
diff changeset
65 -- represent a wide character sequence. Calling the function In_Char for
kono
parents:
diff changeset
66 -- additional characters as required, Char_To_Wide_Char returns the
kono
parents:
diff changeset
67 -- corresponding wide character value. Constraint_Error is raised if the
kono
parents:
diff changeset
68 -- sequence of characters encountered is not a valid wide character
kono
parents:
diff changeset
69 -- sequence for the given encoding method.
kono
parents:
diff changeset
70 --
kono
parents:
diff changeset
71 -- Note on the use of brackets encoding (WCEM_Brackets). The brackets
kono
parents:
diff changeset
72 -- encoding method is ambiguous in the context of this function, since
kono
parents:
diff changeset
73 -- there is no way to tell if ["1234"] is eight unencoded characters or
kono
parents:
diff changeset
74 -- one encoded character. In the context of Ada sources, any sequence
kono
parents:
diff changeset
75 -- starting [" must be the start of an encoding (since that sequence is
kono
parents:
diff changeset
76 -- not valid in Ada source otherwise). The routines in this package use
kono
parents:
diff changeset
77 -- the same approach. If the input string contains the sequence [" then
kono
parents:
diff changeset
78 -- this is assumed to be the start of a brackets encoding sequence, and
kono
parents:
diff changeset
79 -- if it does not match the syntax, an error is raised.
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 generic
kono
parents:
diff changeset
82 with function In_Char return Character;
kono
parents:
diff changeset
83 function Char_Sequence_To_UTF_32
kono
parents:
diff changeset
84 (C : Character;
kono
parents:
diff changeset
85 EM : System.WCh_Con.WC_Encoding_Method) return UTF_32_Code;
kono
parents:
diff changeset
86 -- This is similar to the above, but the function returns a code from
kono
parents:
diff changeset
87 -- the full UTF_32 code set, which covers the full range of possible
kono
parents:
diff changeset
88 -- values in Wide_Wide_Character. The result can be converted to
kono
parents:
diff changeset
89 -- Wide_Wide_Character form using Wide_Wide_Character'Val.
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 generic
kono
parents:
diff changeset
92 with procedure Out_Char (C : Character);
kono
parents:
diff changeset
93 procedure Wide_Char_To_Char_Sequence
kono
parents:
diff changeset
94 (WC : Wide_Character;
kono
parents:
diff changeset
95 EM : System.WCh_Con.WC_Encoding_Method);
kono
parents:
diff changeset
96 -- Given a wide character, converts it into a sequence of one or
kono
parents:
diff changeset
97 -- more characters, calling the given Out_Char procedure for each.
kono
parents:
diff changeset
98 -- Constraint_Error is raised if the given wide character value is
kono
parents:
diff changeset
99 -- not a valid value for the given encoding method.
kono
parents:
diff changeset
100 --
kono
parents:
diff changeset
101 -- Note on brackets encoding (WCEM_Brackets). For the input routines above,
kono
parents:
diff changeset
102 -- upper half characters can be represented as ["hh"] but this procedure
kono
parents:
diff changeset
103 -- will only use brackets encodings for codes higher than 16#FF#, so upper
kono
parents:
diff changeset
104 -- half characters will be output as single Character values.
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 generic
kono
parents:
diff changeset
107 with procedure Out_Char (C : Character);
kono
parents:
diff changeset
108 procedure UTF_32_To_Char_Sequence
kono
parents:
diff changeset
109 (Val : UTF_32_Code;
kono
parents:
diff changeset
110 EM : System.WCh_Con.WC_Encoding_Method);
kono
parents:
diff changeset
111 -- This is similar to the above, but the input value is a code from the
kono
parents:
diff changeset
112 -- full UTF_32 code set, which covers the full range of possible values
kono
parents:
diff changeset
113 -- in Wide_Wide_Character. To convert a Wide_Wide_Character value, the
kono
parents:
diff changeset
114 -- caller can use Wide_Wide_Character'Pos in the call.
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 end System.WCh_Cnv;