scng.adb (Check_End_Of_Line): Count characters, rather than bytes (makes a difference for wide characters)
2005-09-01 Robert Dewar <dewar@adacore.com> * scng.adb (Check_End_Of_Line): Count characters, rather than bytes (makes a difference for wide characters) * widechar.adb, widechar.ads: Add Wide_Char_Byte_Count feature to count chars vs bytes From-SVN: r103875
This commit is contained in:
parent
09245ac9a7
commit
d52f1094e5
|
@ -257,6 +257,7 @@ package body Scng is
|
||||||
First_Non_Blank_Location := Scan_Ptr;
|
First_Non_Blank_Location := Scan_Ptr;
|
||||||
|
|
||||||
Initialize_Checksum;
|
Initialize_Checksum;
|
||||||
|
Wide_Char_Byte_Count := 0;
|
||||||
|
|
||||||
-- Do not call Scan, otherwise the License stuff does not work in Scn
|
-- Do not call Scan, otherwise the License stuff does not work in Scn
|
||||||
|
|
||||||
|
@ -340,7 +341,10 @@ package body Scng is
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
procedure Check_End_Of_Line is
|
procedure Check_End_Of_Line is
|
||||||
Len : constant Int := Int (Scan_Ptr) - Int (Current_Line_Start);
|
Len : constant Int :=
|
||||||
|
Int (Scan_Ptr) -
|
||||||
|
Int (Current_Line_Start) -
|
||||||
|
Wide_Char_Byte_Count;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if Style_Check then
|
if Style_Check then
|
||||||
|
@ -362,6 +366,10 @@ package body Scng is
|
||||||
elsif Len > Opt.Max_Line_Length then
|
elsif Len > Opt.Max_Line_Length then
|
||||||
Error_Long_Line;
|
Error_Long_Line;
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
|
-- Reset wide character byte count for next line
|
||||||
|
|
||||||
|
Wide_Char_Byte_Count := 0;
|
||||||
end Check_End_Of_Line;
|
end Check_End_Of_Line;
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
|
@ -88,6 +88,8 @@ package body Widechar is
|
||||||
C : out Char_Code;
|
C : out Char_Code;
|
||||||
Err : out Boolean)
|
Err : out Boolean)
|
||||||
is
|
is
|
||||||
|
P_Init : constant Source_Ptr := P;
|
||||||
|
|
||||||
function In_Char return Character;
|
function In_Char return Character;
|
||||||
-- Function to obtain characters of wide character escape sequence
|
-- Function to obtain characters of wide character escape sequence
|
||||||
|
|
||||||
|
@ -108,6 +110,7 @@ package body Widechar is
|
||||||
begin
|
begin
|
||||||
C := Char_Code (WC_In (In_Char, Wide_Character_Encoding_Method));
|
C := Char_Code (WC_In (In_Char, Wide_Character_Encoding_Method));
|
||||||
Err := False;
|
Err := False;
|
||||||
|
Wide_Char_Byte_Count := Wide_Char_Byte_Count + Nat (P - P_Init - 1);
|
||||||
|
|
||||||
exception
|
exception
|
||||||
when Constraint_Error =>
|
when Constraint_Error =>
|
||||||
|
@ -151,6 +154,8 @@ package body Widechar is
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
procedure Skip_Wide (S : String; P : in out Natural) is
|
procedure Skip_Wide (S : String; P : in out Natural) is
|
||||||
|
P_Init : constant Natural := P;
|
||||||
|
|
||||||
function Skip_Char return Character;
|
function Skip_Char return Character;
|
||||||
-- Function to skip one character of wide character escape sequence
|
-- Function to skip one character of wide character escape sequence
|
||||||
|
|
||||||
|
@ -173,6 +178,7 @@ package body Widechar is
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Discard := WC_Skip (Skip_Char, Wide_Character_Encoding_Method);
|
Discard := WC_Skip (Skip_Char, Wide_Character_Encoding_Method);
|
||||||
|
Wide_Char_Byte_Count := Wide_Char_Byte_Count + Nat (P - P_Init - 1);
|
||||||
end Skip_Wide;
|
end Skip_Wide;
|
||||||
|
|
||||||
---------------
|
---------------
|
||||||
|
@ -180,6 +186,8 @@ package body Widechar is
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
procedure Skip_Wide (S : Source_Buffer_Ptr; P : in out Source_Ptr) is
|
procedure Skip_Wide (S : Source_Buffer_Ptr; P : in out Source_Ptr) is
|
||||||
|
P_Init : constant Source_Ptr := P;
|
||||||
|
|
||||||
function Skip_Char return Character;
|
function Skip_Char return Character;
|
||||||
-- Function to skip one character of wide character escape sequence
|
-- Function to skip one character of wide character escape sequence
|
||||||
|
|
||||||
|
@ -202,6 +210,7 @@ package body Widechar is
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Discard := WC_Skip (Skip_Char, Wide_Character_Encoding_Method);
|
Discard := WC_Skip (Skip_Char, Wide_Character_Encoding_Method);
|
||||||
|
Wide_Char_Byte_Count := Wide_Char_Byte_Count + Nat (P - P_Init - 1);
|
||||||
end Skip_Wide;
|
end Skip_Wide;
|
||||||
|
|
||||||
end Widechar;
|
end Widechar;
|
||||||
|
|
|
@ -40,6 +40,13 @@ with Types; use Types;
|
||||||
|
|
||||||
package Widechar is
|
package Widechar is
|
||||||
|
|
||||||
|
Wide_Char_Byte_Count : Nat := 0;
|
||||||
|
-- This value is incremented whenever Scan_Wide or Skip_Wide is called.
|
||||||
|
-- The amount added is the length of the wide character sequence minus
|
||||||
|
-- one. This means that the count that accululates here represents the
|
||||||
|
-- difference between the length in characters and the length in bytes.
|
||||||
|
-- This is used for checking the line length in characters.
|
||||||
|
|
||||||
function Length_Wide return Nat;
|
function Length_Wide return Nat;
|
||||||
-- Returns the maximum length in characters for the escape sequence that
|
-- Returns the maximum length in characters for the escape sequence that
|
||||||
-- is used to encode wide character literals outside the ASCII range. Used
|
-- is used to encode wide character literals outside the ASCII range. Used
|
||||||
|
|
Loading…
Reference in New Issue