Skip to content

Commit

Permalink
Merge branch 'topic/vadim/lsp' into 'master'
Browse files Browse the repository at this point in the history
Few enhancements for use in LSP

Closes #214 and #215

See merge request eng/ide/VSS!283
  • Loading branch information
godunko committed Aug 25, 2023
2 parents 1b3d60f + 0c30573 commit 564e99b
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
--
-- Copyright (C) 2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
--

package body VSS.Strings.Formatters.Generic_Modulars is

------------
-- Format --
------------

overriding function Format
(Self : Formatter;
Format : VSS.Strings.Formatters.Format_Information)
return VSS.Strings.Virtual_String
is
Buffer : constant Wide_Wide_String :=
Modular_Type'Wide_Wide_Image (Self.Value);

begin
if Buffer (Buffer'First) = ' ' then
return
VSS.Strings.To_Virtual_String
(Buffer (Buffer'First + 1 .. Buffer'Last));

else
return VSS.Strings.To_Virtual_String (Buffer);
end if;
end Format;

-----------
-- Image --
-----------

function Image (Item : Modular_Type) return Formatter is
begin
return (Name => <>, Value => Item);
end Image;

-----------
-- Image --
-----------

function Image
(Name : VSS.Strings.Virtual_String;
Item : Modular_Type) return Formatter is
begin
return (Name => Name, Value => Item);
end Image;

----------
-- Name --
----------

overriding function Name
(Self : Formatter) return VSS.Strings.Virtual_String is
begin
return Self.Name;
end Name;

end VSS.Strings.Formatters.Generic_Modulars;
17 changes: 17 additions & 0 deletions source/text/implementation/vss-strings.adb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ package body VSS.Strings is
end return;
end "&";

---------
-- "*" --
---------

function "*"
(Left : Character_Count;
Right : VSS.Characters.Virtual_Character) return Virtual_String is
begin
return Result : Virtual_String do
-- Result.Set_Capacity (Left);

for J in 1 .. Left loop
Result.Append (Right);
end loop;
end return;
end "*";

---------
-- "<" --
---------
Expand Down
56 changes: 56 additions & 0 deletions source/text/vss-strings-formatters-generic_modulars.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
--
-- Copyright (C) 2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
--

-- This package provides formatter for integer types.
--
-- Integer_Formatter supports following formatting options:
-- [0][1-9[0-9]*][#[1-9][0-9]+]
--
-- 0 - fill leading zeros
--
-- By default, leading zeros is not filled.
--
-- 1-9[0-9]* - number of digits (not include sign)
--
-- By default, shortest number of digits is used.
--
-- #[1-9][0-9]* - base
--
-- By default, base is 10.

generic
type Modular_Type is mod <>;

package VSS.Strings.Formatters.Generic_Modulars is

pragma Preelaborate;

type Formatter is
new VSS.Strings.Formatters.Abstract_Formatter with private;

function Image (Item : Modular_Type) return Formatter;

function Image
(Name : VSS.Strings.Virtual_String;
Item : Modular_Type) return Formatter;

private

type Formatter is
new VSS.Strings.Formatters.Abstract_Formatter with record
Name : VSS.Strings.Virtual_String;
Value : Modular_Type;
end record;

overriding function Name
(Self : Formatter) return VSS.Strings.Virtual_String;

overriding function Format
(Self : Formatter;
Format : VSS.Strings.Formatters.Format_Information)
return VSS.Strings.Virtual_String;

end VSS.Strings.Formatters.Generic_Modulars;
5 changes: 5 additions & 0 deletions source/text/vss-strings.ads
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ package VSS.Strings is
-- Right : VSS.Characters.Virtual_Character) return Virtual_String;
-- -- Concatenation operator for virtual string and virtual characters.

function "*"
(Left : Character_Count;
Right : VSS.Characters.Virtual_Character) return Virtual_String;
-- Create string by repeating given number of given character.

procedure Clear (Self : in out Virtual_String'Class);
-- Remove all data.

Expand Down
29 changes: 29 additions & 0 deletions testsuite/text/test_string-test_asterisk_character.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--
-- Copyright (C) 2020-2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
--

separate (Test_String)
procedure Test_Asterisk_Character is

use type VSS.Strings.Virtual_String;

begin
declare
R : constant VSS.Strings.Virtual_String := 0 * 'A';

begin
Test_Support.Assert (R.Is_Empty);
-- Test_Support.Assert (not R.Is_Null);
-- XXX Should it be non-null string?
end;

declare
R : constant VSS.Strings.Virtual_String := 5 * 'B';

begin
Test_Support.Assert (not R.Is_Empty);
Test_Support.Assert (R = "BBBBB");
end;
end Test_Asterisk_Character;
4 changes: 4 additions & 0 deletions testsuite/text/test_string.adb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ with Test_Support;

procedure Test_String is

procedure Test_Asterisk_Character;
procedure Test_Ends_With;
procedure Test_Prepend;
procedure Test_Replace;
Expand All @@ -22,6 +23,8 @@ procedure Test_String is
--
-- This test requires valgrind.

procedure Test_Asterisk_Character is separate;

procedure Test_Ends_With is separate;

------------------
Expand Down Expand Up @@ -198,6 +201,7 @@ procedure Test_String is
end Test_V705_011;

begin
Test_Asterisk_Character;
Test_Ends_With;
Test_Prepend;
Test_Replace;
Expand Down

0 comments on commit 564e99b

Please sign in to comment.