+ alire, testing, style checks
This commit is contained in:
parent
a5da252d29
commit
18be28f789
40 changed files with 154 additions and 81 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -5,4 +5,7 @@
|
|||
*.ali
|
||||
|
||||
# Build directory
|
||||
build
|
||||
build/
|
||||
|
||||
# Alire directory
|
||||
alire/
|
12
alire.toml
Normal file
12
alire.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
name = "encodings"
|
||||
description = "Text encoding handling library"
|
||||
version = "0.1.0-dev"
|
||||
|
||||
authors = ["Vovanium"]
|
||||
maintainers = ["Vovanium <vovanium@disroot.org>"]
|
||||
maintainers-logins = ["vovanium"]
|
||||
|
||||
project-files = ["gpr/encodings.gpr", "gpr/test.gpr", "gpr/examples.gpr"]
|
||||
|
||||
[[depends-on]]
|
||||
aunit = "^23.0.0"
|
|
@ -1,15 +0,0 @@
|
|||
project Encodings is
|
||||
for Source_Dirs use ("source");
|
||||
for Object_Dir use "build/objects";
|
||||
for Library_Dir use "build/library";
|
||||
for Library_Name use "encodings";
|
||||
for Library_Kind use "static";
|
||||
package Builder is
|
||||
for Default_Switches("Ada") use (
|
||||
"-gnato",
|
||||
"-O2",
|
||||
"-gnatW8",
|
||||
"-gnatyabfikltx"
|
||||
);
|
||||
end Builder;
|
||||
end Encodings;
|
|
@ -1,9 +0,0 @@
|
|||
with "../../encodings.gpr";
|
||||
project Default is
|
||||
for Object_Dir use "../../build/objects";
|
||||
for Exec_Dir use "../../build/executables";
|
||||
|
||||
package Builder is
|
||||
For Default_Switches("Ada") use ("-ggdb", "-gnatW8");
|
||||
end Builder;
|
||||
end Default;
|
|
@ -1,32 +0,0 @@
|
|||
-- An example of using low-level convertor API (fixed string procedures)
|
||||
-- Program reads standard input, adds cr before lf, then writes to standard output
|
||||
with Ada.Streams;
|
||||
use Ada.Streams;
|
||||
with Ada.Text_IO;
|
||||
use Ada.Text_IO;
|
||||
with Ada.Text_IO.Text_Streams;
|
||||
use Ada.Text_IO.Text_Streams;
|
||||
with Ada.Unchecked_Conversion;
|
||||
with Encodings.Line_Endings.Strip_CR;
|
||||
with Encodings.Utility;
|
||||
use Encodings.Utility;
|
||||
procedure Strip_CR is
|
||||
|
||||
Input_Stream: Stream_Access := Stream(Standard_Input);
|
||||
Output_Stream: Stream_Access := Stream(Standard_Output);
|
||||
Input_Buffer: String(1 .. 100);
|
||||
Output_Buffer: String(1 .. 100);
|
||||
Input_Last, Input_Read_Last: Natural;
|
||||
Output_Last: Natural;
|
||||
|
||||
Coder: Encodings.Line_Endings.Strip_CR.Converter;
|
||||
begin
|
||||
while not End_Of_File(Standard_Input) loop
|
||||
Read_String(Input_Stream.all, Input_Buffer, Input_Read_Last);
|
||||
Input_Last := Input_Buffer'First - 1;
|
||||
while Input_Last < Input_Read_Last loop
|
||||
Coder.Process(Input_Buffer(Input_Last + 1 .. Input_Read_Last), Input_Last, Output_Buffer, Output_Last);
|
||||
String'Write(Output_Stream, Output_Buffer(Output_Buffer'First .. Output_Last));
|
||||
end loop;
|
||||
end loop;
|
||||
end Strip_CR;
|
11
gpr/common.gpr
Normal file
11
gpr/common.gpr
Normal file
|
@ -0,0 +1,11 @@
|
|||
abstract project Common is
|
||||
Base_Path := project'Project_Dir & "/..";
|
||||
Source_Path := Base_Path & "/source";
|
||||
Build_Path := Base_Path & "/build";
|
||||
Default_Switches := (
|
||||
"-gnato",
|
||||
"-O2",
|
||||
"-gnatW8",
|
||||
"-gnatyAabefikltx"
|
||||
);
|
||||
end Common;
|
3
gpr/default.gpr
Normal file
3
gpr/default.gpr
Normal file
|
@ -0,0 +1,3 @@
|
|||
aggregate project Default is
|
||||
for Project_Files use ("encodings.gpr", "examples.gpr");
|
||||
end Default;
|
10
gpr/encodings.gpr
Normal file
10
gpr/encodings.gpr
Normal file
|
@ -0,0 +1,10 @@
|
|||
project Encodings extends "common" is
|
||||
for Source_Dirs use (Common.Source_Path & "/library");
|
||||
for Object_Dir use Common.Build_Path & "/objects";
|
||||
for Library_Dir use Common.Build_Path & "/library";
|
||||
for Library_Name use "encodings";
|
||||
for Library_Kind use "static";
|
||||
package Builder is
|
||||
for Default_Switches("Ada") use Common.Default_Switches;
|
||||
end Builder;
|
||||
end Encodings;
|
10
gpr/examples.gpr
Normal file
10
gpr/examples.gpr
Normal file
|
@ -0,0 +1,10 @@
|
|||
with "encodings";
|
||||
project Examples extends "common" is
|
||||
for Object_Dir use Common.Build_Path & "/objects";
|
||||
for Exec_Dir use Common.Build_Path & "/executables";
|
||||
for Source_Dirs use (Common.Source_Path & "/examples");
|
||||
|
||||
package Builder is
|
||||
For Default_Switches("Ada") use Common.Default_Switches;
|
||||
end Builder;
|
||||
end Examples;
|
16
gpr/test.gpr
Normal file
16
gpr/test.gpr
Normal file
|
@ -0,0 +1,16 @@
|
|||
with "aunit";
|
||||
with "encodings";
|
||||
|
||||
project Test extends "common" is
|
||||
for Source_Dirs use (Source_Path & "/test");
|
||||
for Object_Dir use Build_Path & "/objects";
|
||||
for Create_Missing_Dirs use "true";
|
||||
for Exec_Dir use Build_Path & "/executables";
|
||||
|
||||
package Compiler is
|
||||
for Default_Switches ("Ada") use Common.Default_Switches;
|
||||
end Compiler;
|
||||
|
||||
for Main use ("test.adb");
|
||||
|
||||
end Test;
|
|
@ -1,3 +0,0 @@
|
|||
package Encodings with Pure is
|
||||
Encoding_Error : exception;
|
||||
end Encodings;
|
|
@ -38,21 +38,23 @@ procedure Add_CR is
|
|||
-- end loop;
|
||||
--end;
|
||||
|
||||
Input_Stream: Stream_Access := Stream(Standard_Input);
|
||||
Output_Stream: Stream_Access := Stream(Standard_Output);
|
||||
Input_Buffer: String(1 .. 100);
|
||||
Output_Buffer: String(1 .. 100);
|
||||
Input_Last, Input_Read_Last: Natural;
|
||||
Output_Last: Natural;
|
||||
Input_Stream : Stream_Access := Stream (Standard_Input);
|
||||
Output_Stream : Stream_Access := Stream (Standard_Output);
|
||||
Input_Buffer : String (1 .. 100);
|
||||
Output_Buffer : String (1 .. 100);
|
||||
Input_Last,
|
||||
Input_Read_Last : Natural;
|
||||
Output_Last : Natural;
|
||||
|
||||
Coder: Encodings.Line_Endings.Add_CR.Converter;
|
||||
Coder : Encodings.Line_Endings.Add_CR.Converter;
|
||||
begin
|
||||
while not End_Of_File(Standard_Input) loop
|
||||
Read_String(Input_Stream.all, Input_Buffer, Input_Read_Last);
|
||||
while not End_Of_File (Standard_Input) loop
|
||||
Read_String (Input_Stream.all, Input_Buffer, Input_Read_Last);
|
||||
Input_Last := Input_Buffer'First - 1;
|
||||
while Input_Last < Input_Read_Last loop
|
||||
Coder.Process(Input_Buffer(Input_Last + 1 .. Input_Read_Last), Input_Last, Output_Buffer, Output_Last);
|
||||
String'Write(Output_Stream, Output_Buffer(Output_Buffer'First .. Output_Last));
|
||||
Coder.Process (Input_Buffer (Input_Last + 1 .. Input_Read_Last),
|
||||
Input_Last, Output_Buffer, Output_Last);
|
||||
String'Write (Output_Stream, Output_Buffer (Output_Buffer'First .. Output_Last));
|
||||
end loop;
|
||||
end loop;
|
||||
end Add_CR;
|
34
source/examples/strip_cr.adb
Normal file
34
source/examples/strip_cr.adb
Normal file
|
@ -0,0 +1,34 @@
|
|||
-- An example of using low-level convertor API (fixed string procedures)
|
||||
-- Program reads standard input, adds cr before lf, then writes to standard output
|
||||
with Ada.Streams;
|
||||
use Ada.Streams;
|
||||
with Ada.Text_IO;
|
||||
use Ada.Text_IO;
|
||||
with Ada.Text_IO.Text_Streams;
|
||||
use Ada.Text_IO.Text_Streams;
|
||||
with Ada.Unchecked_Conversion;
|
||||
with Encodings.Line_Endings.Strip_CR;
|
||||
with Encodings.Utility;
|
||||
use Encodings.Utility;
|
||||
procedure Strip_CR is
|
||||
|
||||
Input_Stream : Stream_Access := Stream (Standard_Input);
|
||||
Output_Stream : Stream_Access := Stream (Standard_Output);
|
||||
Input_Buffer : String (1 .. 100);
|
||||
Output_Buffer : String (1 .. 100);
|
||||
Input_Last,
|
||||
Input_Read_Last : Natural;
|
||||
Output_Last : Natural;
|
||||
|
||||
Coder : Encodings.Line_Endings.Strip_CR.Converter;
|
||||
begin
|
||||
while not End_Of_File (Standard_Input) loop
|
||||
Read_String (Input_Stream.all, Input_Buffer, Input_Read_Last);
|
||||
Input_Last := Input_Buffer'First - 1;
|
||||
while Input_Last < Input_Read_Last loop
|
||||
Coder.Process (Input_Buffer (Input_Last + 1 .. Input_Read_Last),
|
||||
Input_Last, Output_Buffer, Output_Last);
|
||||
String'Write (Output_Stream, Output_Buffer (Output_Buffer'First .. Output_Last));
|
||||
end loop;
|
||||
end loop;
|
||||
end Strip_CR;
|
|
@ -26,7 +26,7 @@ private
|
|||
Target_Cursor : out Natural)
|
||||
with
|
||||
Pre => Target'Length > 0,
|
||||
Post => Buffered_Length(State) = 0 or Target_Cursor = Target'Last;
|
||||
Post => Buffered_Length (State) = 0 or Target_Cursor = Target'Last;
|
||||
-- This should be called at the start of `Process` procedure
|
||||
-- to initialize variables and flush buffered data
|
||||
|
|
@ -5,7 +5,7 @@ generic
|
|||
type String_Type is array (Positive range <>) of Character_Type;
|
||||
Carriage_Return : in Character_Type; -- CR in the corresponding type
|
||||
Line_Feed : in Character_Type; -- LF in the corresponding type
|
||||
with package Converter_Base is new Encodings.Generic_Converters(
|
||||
with package Converter_Base is new Encodings.Generic_Converters (
|
||||
Source_Character => Character_Type,
|
||||
Target_Character => Character_Type,
|
||||
Source_String => String_Type,
|
|
@ -5,7 +5,7 @@ generic
|
|||
type String_Type is array (Positive range <>) of Character_Type;
|
||||
Carriage_Return : in Character_Type; -- CR in the corresponding type
|
||||
Line_Feed : in Character_Type; -- LF in the corresponding type
|
||||
with package Converter_Base is new Encodings.Generic_Converters(
|
||||
with package Converter_Base is new Encodings.Generic_Converters (
|
||||
Source_Character => Character_Type,
|
||||
Target_Character => Character_Type,
|
||||
Source_String => String_Type,
|
|
@ -6,7 +6,7 @@ package body Encodings.Utility.Generic_Sequence_Buffers is
|
|||
Target : in out String_Type;
|
||||
Target_Cursor : in out Natural)
|
||||
is
|
||||
Length : constant Natural := Natural'Min(
|
||||
Length : constant Natural := Natural'Min (
|
||||
Remaining_Length (Source, Source_Cursor),
|
||||
Remaining_Length (Target, Target_Cursor));
|
||||
New_Source_Cursor : constant Natural := Source_Cursor + Length;
|
||||
|
@ -18,7 +18,7 @@ package body Encodings.Utility.Generic_Sequence_Buffers is
|
|||
Target_Cursor := New_Target_Cursor;
|
||||
Source_Cursor := New_Source_Cursor;
|
||||
end if;
|
||||
end;
|
||||
end Copy;
|
||||
|
||||
--
|
||||
|
||||
|
@ -57,6 +57,6 @@ package body Encodings.Utility.Generic_Sequence_Buffers is
|
|||
begin
|
||||
Copy (Source, Source_Cursor, Target, Target_Cursor);
|
||||
Set_Buffer (Buffer, Source (Source_Cursor + 1 .. Source'Last));
|
||||
end;
|
||||
end Write;
|
||||
|
||||
end Encodings.Utility.Generic_Sequence_Buffers;
|
|
@ -16,7 +16,7 @@ package Encodings.Utility.Generic_Sequence_Buffers with Pure is
|
|||
-- First unprocessed position would have Last + 1 range thus may overflow
|
||||
-- if Last is Integer'Last.
|
||||
--
|
||||
--
|
||||
--
|
||||
-- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
-- | Already processed part | Unprocessed yet part |
|
||||
-- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
|
@ -88,7 +88,7 @@ package Encodings.Utility.Generic_Sequence_Buffers with Pure is
|
|||
) with
|
||||
Pre => Target_Cursor in Target'First - 1 .. Target'Last,
|
||||
Post => Target_Cursor in Target'First - 1 .. Target'Last
|
||||
and Length(Buffer'Old) - Length(Buffer) = Target_Cursor - Target_Cursor'Old
|
||||
and Length (Buffer'Old) - Length (Buffer) = Target_Cursor - Target_Cursor'Old
|
||||
and (Is_Empty (Buffer) or Target_Cursor = Target'Last);
|
||||
-- Write buffered data to a target string
|
||||
|
|
@ -34,7 +34,7 @@ package body Encodings.Utility is
|
|||
Buffer_I := Buffer_I + Element_Length;
|
||||
end loop;
|
||||
Last := Index_Type'Pred (Last);
|
||||
end;
|
||||
end Read_Array;
|
||||
|
||||
-- Strange, GNAT cannot use generic instance for package subprogram
|
||||
procedure Read_String (
|
||||
|
@ -48,6 +48,6 @@ package body Encodings.Utility is
|
|||
Array_Type => String);
|
||||
begin
|
||||
Inst (Stream, Item, Last);
|
||||
end;
|
||||
end Read_String;
|
||||
|
||||
end Encodings.Utility;
|
3
source/library/encodings.ads
Normal file
3
source/library/encodings.ads
Normal file
|
@ -0,0 +1,3 @@
|
|||
package Encodings with Pure is
|
||||
Encoding_Error : exception;
|
||||
end Encodings;
|
9
source/test/encodings-test.adb
Normal file
9
source/test/encodings-test.adb
Normal file
|
@ -0,0 +1,9 @@
|
|||
package body Encodings.Test is
|
||||
|
||||
function Suite return Access_Test_Suite is
|
||||
R : Access_Test_Suite := new Test_Suite;
|
||||
begin
|
||||
return R;
|
||||
end Suite;
|
||||
|
||||
end Encodings.Test;
|
8
source/test/encodings-test.ads
Normal file
8
source/test/encodings-test.ads
Normal file
|
@ -0,0 +1,8 @@
|
|||
with AUnit.Test_Suites;
|
||||
use AUnit.Test_Suites;
|
||||
|
||||
package Encodings.Test is
|
||||
|
||||
function Suite return Access_Test_Suite;
|
||||
|
||||
end Encodings.Test;
|
11
source/test/test.adb
Normal file
11
source/test/test.adb
Normal file
|
@ -0,0 +1,11 @@
|
|||
with AUnit.Reporter.Text;
|
||||
with AUnit.Run;
|
||||
|
||||
with Encodings.Test;
|
||||
|
||||
procedure Test is
|
||||
procedure Runner is new AUnit.Run.Test_Runner (Encodings.Test.Suite);
|
||||
Reporter : AUnit.Reporter.Text.Text_Reporter;
|
||||
begin
|
||||
Runner (Reporter);
|
||||
end Test;
|
Loading…
Reference in a new issue