Index: src/natools-string_slices.adb ================================================================== --- src/natools-string_slices.adb +++ src/natools-string_slices.adb @@ -1,7 +1,7 @@ ------------------------------------------------------------------------------ --- Copyright (c) 2013-2016, Natacha Porté -- +-- Copyright (c) 2013-2017, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- @@ -114,10 +114,25 @@ -------------------------- -- Conversion functions -- -------------------------- + + function New_Slice + (First : Positive; + Last : Natural; + Initialize : not null access procedure (S : out String)) + return Slice + is + Data : constant String_Refs.Data_Access := new String (First .. Last); + Ref : constant String_Refs.Immutable_Reference + := String_Refs.Create (Data); + begin + Initialize (Data.all); + return Slice'(Bounds => (First, Last + 1 - First), Ref => Ref); + end New_Slice; + function To_Slice (S : String) return Slice is function Create return String; function Create return String is Index: src/natools-string_slices.ads ================================================================== --- src/natools-string_slices.ads +++ src/natools-string_slices.ads @@ -1,7 +1,7 @@ ------------------------------------------------------------------------------ --- Copyright (c) 2013-2016, Natacha Porté -- +-- Copyright (c) 2013-2017, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- @@ -74,10 +74,17 @@ -------------------------- -- Conversion functions -- -------------------------- + function New_Slice + (First : Positive; + Last : Natural; + Initialize : not null access procedure (S : out String)) + return Slice; + -- Create a callback-initialized slice + function To_Slice (S : String) return Slice; -- Create a new slice containing the whole given string function To_String (S : Slice) return String; -- Return the string represented by the slice