| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- W I D E C H A R -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 1992-2025, Free Software Foundation, Inc. -- |
| 10 |
-- -- |
| 11 |
-- GNAT is free software; you can redistribute it and/or modify it under -- |
| 12 |
-- terms of the GNU General Public License as published by the Free Soft- -- |
| 13 |
-- ware Foundation; either version 3, or (at your option) any later ver- -- |
| 14 |
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
| 15 |
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- |
| 16 |
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- |
| 17 |
-- for more details. You should have received a copy of the GNU General -- |
| 18 |
-- Public License distributed with GNAT; see file COPYING3. If not, go to -- |
| 19 |
-- http://www.gnu.org/licenses for a complete copy of the license. -- |
| 20 |
-- -- |
| 21 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 22 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 23 |
-- -- |
| 24 |
------------------------------------------------------------------------------ |
| 25 |
|
| 26 |
-- Subprograms for manipulation of wide character sequences. Note that in |
| 27 |
-- this package, wide character and wide wide character are not distinguished |
| 28 |
-- since this package is basically concerned with syntactic notions, and it |
| 29 |
-- deals with Char_Code values, rather than values of actual Ada types. |
| 30 |
|
| 31 |
with Types; use Types; |
| 32 |
|
| 33 |
package Widechar is |
| 34 |
|
| 35 |
Wide_Char_Byte_Count : Nat := 0; |
| 36 |
-- This value is incremented whenever Scan_Wide or Skip_Wide is called. |
| 37 |
-- The amount added is the length of the wide character sequence minus |
| 38 |
-- one. This means that the count that accumulates here represents the |
| 39 |
-- difference between the length in characters and the length in bytes. |
| 40 |
-- This is used for checking the line length in characters. |
| 41 |
|
| 42 |
function Length_Wide return Nat; |
| 43 |
-- Returns the maximum length in characters for the escape sequence that |
| 44 |
-- is used to encode wide character literals outside the ASCII range. Used |
| 45 |
-- only in the implementation of the attribute Width for Wide_Character |
| 46 |
-- and Wide_Wide_Character. |
| 47 |
|
| 48 |
procedure Scan_Wide |
| 49 |
(S : Source_Buffer_Ptr; |
| 50 |
P : in out Source_Ptr; |
| 51 |
C : out Char_Code; |
| 52 |
Err : out Boolean); |
| 53 |
-- On entry S (P) points to the first character in the source text for |
| 54 |
-- a wide character (i.e. to an ESC character, a left bracket, or an |
| 55 |
-- upper half character, depending on the representation method). A |
| 56 |
-- single wide character is scanned. If no error is found, the value |
| 57 |
-- stored in C is the code for this wide character, P is updated past |
| 58 |
-- the sequence and Err is set to False. If an error is found, then |
| 59 |
-- P points to the improper character, C is undefined, and Err is |
| 60 |
-- set to True. |
| 61 |
|
| 62 |
procedure Set_Wide |
| 63 |
(C : Char_Code; |
| 64 |
S : in out String; |
| 65 |
P : in out Natural); |
| 66 |
-- The escape sequence (including any leading ESC character) for the |
| 67 |
-- given character code is stored starting at S (P + 1), and on return |
| 68 |
-- P points to the last stored character (i.e. P is the count of stored |
| 69 |
-- characters on entry and exit, and the escape sequence is appended to |
| 70 |
-- the end of the stored string). The character code C represents a code |
| 71 |
-- originally constructed by Scan_Wide, so it is known to be in a range |
| 72 |
-- that is appropriate for the encoding method in use. |
| 73 |
|
| 74 |
procedure Skip_Wide (S : String; P : in out Natural); |
| 75 |
-- On entry, S (P) points to an ESC character for a wide character escape |
| 76 |
-- sequence or to an upper half character if the encoding method uses the |
| 77 |
-- upper bit, or to a left bracket if the brackets encoding method is in |
| 78 |
-- use. On exit, P is bumped past the wide character sequence. |
| 79 |
|
| 80 |
procedure Skip_Wide (S : Source_Buffer_Ptr; P : in out Source_Ptr); |
| 81 |
-- Similar to the above procedure, but operates on a source buffer |
| 82 |
-- instead of a string, with P being a Source_Ptr referencing the |
| 83 |
-- contents of the source buffer. |
| 84 |
|
| 85 |
function Is_Start_Of_Wide_Char |
| 86 |
(S : Source_Buffer_Ptr; |
| 87 |
P : Source_Ptr) return Boolean; |
| 88 |
-- Determines if S (P) is the start of a wide character sequence |
| 89 |
|
| 90 |
private |
| 91 |
pragma Inline (Is_Start_Of_Wide_Char); |
| 92 |
|
| 93 |
end Widechar; |