Natools

Check-in [cd40fb63c6]
Login
Overview
Comment:string_slices: new callback-based constructor
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: cd40fb63c6ba2afb0defe48228dd0469d5146014
User & Date: nat on 2017-06-14 20:58:49
Other Links: manifest | tags
Context
2017-06-15
19:23
string_slice_tests: test the new callback-based constructor check-in: 4b6433de7a user: nat tags: trunk
2017-06-14
20:58
string_slices: new callback-based constructor check-in: cd40fb63c6 user: nat tags: trunk
2017-06-13
19:15
string_slices-slice_sets: drop uneeded mutability of string references check-in: 7521b2a2e6 user: nat tags: trunk
Changes

Modified src/natools-string_slices.adb from [55fc41b4d8] to [d363e97e60].

1
2

3
4
5
6
7
8
9
1

2
3
4
5
6
7
8
9

-
+







------------------------------------------------------------------------------
-- 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.        --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         --
112
113
114
115
116
117
118















119
120
121
122
123
124
125
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







   end Image;



   --------------------------
   -- 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
      begin
         return S;

Modified src/natools-string_slices.ads from [865a368eb3] to [57bd0c9847].

1
2

3
4
5
6
7
8
9
1

2
3
4
5
6
7
8
9

-
+







------------------------------------------------------------------------------
-- 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.        --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         --
72
73
74
75
76
77
78







79
80
81
82
83
84
85
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92







+
+
+
+
+
+
+







   Null_Slice : constant Slice;


   --------------------------
   -- 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