forked from AdaDoom3/AdaDoom3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneo-library-dynamic_string.ads
More file actions
485 lines (471 loc) · 17.6 KB
/
Copy pathneo-library-dynamic_string.ads
File metadata and controls
485 lines (471 loc) · 17.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
with
Ada.Strings,
Ada.Finalization,
Neo.Foundation.Text_IO,
Neo.Foundation.Data_Types;
use
Ada.Strings,
Neo.Foundation.Text_IO,
Neo.Foundation.Data_Types;
package Neo.Library.Dynamic_String
is
-----------
-- Types --
-----------
type Record_Dynamic_String
is private;
------------------
-- Enumerations --
------------------
type Enuemrated_String_Measure
is(
Size_String_Measure,
Bandwidth_String_Measure);
-----------------
-- Subprograms --
-----------------
procedure Set_Length(
Source : in out Record_Dynamic_String
Length : in Integer_4_Natural);
function Get(
Source : in Record_Dynamic_String;
Index : in Integer_4_Positive)
return Character_1;
function Get(
Source : in Record_Dynamic_String;
Index : in Integer_4_Positive)
return Character_2;
function Get_Length(
Item : in Record_Dynamic_String)
return Integer_4_Natural;
function Get_Number_Of_Bits_Allocated
Item : in Record_Dynamic_String)
return Integer_4_Natural;
procedure To_Lower_Case(
Item : in out Record_Dynamic_String);
procedure To_Upper_Case(
Item : in out Record_Dynamic_String);
function To_Lower_Case(
Item : in Record_Dynamic_String)
return Record_Dynamic_String;
function To_Upper_Case(
Item : in Record_Dynamic_String)
return Record_Dynamic_String;
function To_Record_Dynamic_String(
Item : in Character_1)
return Record_Dynamic_String;
function To_Record_Dynamic_String(
Item : in Character_2)
return Record_Dynamic_String;
function To_Record_Dynamic_String(
Item : in String_1)
return Record_Dynamic_String;
function To_Record_Dynamic_String(
Item : in String_2)
return Record_Dynamic_String;
function "&"(
Left : in Record_Dynamic_String;
Right : in Record_Dynamic_String)
return Record_Dynamic_String;
function "&"(
Left : in Character_1;
Right : in Record_Dynamic_String)
return Record_Dynamic_String;
function "&"(
Left : in Record_Dynamic_String;
Right : in Character_1)
return Record_Dynamic_String;
function "&"(
Left : in Character_2;
Right : in Record_Dynamic_String)
return Record_Dynamic_String;
function "&"(
Left : in Record_Dynamic_String;
Right : in Character_2)
return Record_Dynamic_String;
function "&"(
Left : in String_1;
Right : in Record_Dynamic_String)
return Record_Dynamic_String;
function "&"(
Left : in Record_Dynamic_String;
Right : in String_1)
return Record_Dynamic_String;
function "&"(
Left : in String_2;
Right : in Record_Dynamic_String)
return Record_Dynamic_String;
function "&"(
Left : in Record_Dynamic_String;
Right : in String_2)
return Record_Dynamic_String;
function "="(
Left : in Record_Dynamic_String;
Right : in Record_Dynamic_String)
return Boolean;
function "="(
Left : in Character_1;
Right : in Record_Dynamic_String)
return Boolean;
function "="(
Left : in Record_Dynamic_String;
Right : in Character_1)
return Boolean;
function "="(
Left : in Character_2;
Right : in Record_Dynamic_String)
return Boolean;
function "="(
Left : in Record_Dynamic_String;
Right : in Character_2)
return Boolean;
function "="(
Left : in String_1;
Right : in Record_Dynamic_String)
return Boolean;
function "="(
Left : in Record_Dynamic_String;
Right : in String_1)
return Boolean;
function "="(
Left : in String_2;
Right : in Record_Dynamic_String)
return Boolean;
function "="(
Left : in Record_Dynamic_String;
Right : in String_2)
return Boolean;
function Are_Insensitive_Equal(
Item_A : in Record_Dynamic_String;
Item_B : in Record_Dynamic_String)
return Boolean;
function Are_Insensitive_Equal(
Item_A : in Character_1;
Item_B : in Record_Dynamic_String)
return Boolean;
function Are_Insensitive_Equal(
Item_A : in Record_Dynamic_String;
Item_B : in Character_1)
return Boolean;
function Are_Insensitive_Equal(
Item_A : in Character_2;
Item_B : in Record_Dynamic_String)
return Boolean;
function Are_Insensitive_Equal(
Item_A : in Record_Dynamic_String;
Item_B : in Character_2)
return Boolean;
function Are_Insensitive_Equal(
Item_A : in String_1;
Item_B : in Record_Dynamic_String)
return Boolean;
function Are_Insensitive_Equal(
Item_A : in Record_Dynamic_String;
Item_B : in String_1)
return Boolean;
function Are_Insensitive_Equal(
Item_A : in String_2;
Item_B : in Record_Dynamic_String)
return Boolean;
function Are_Insensitive_Equal(
Item_A : in Record_Dynamic_String;
Item_B : in String_2)
return Boolean;
function Are_Equal_Paths(
Source : in Record_Dynamic_String;
Path : in Record_Dynamic_String)
return Boolean;
function Are_Equal_Paths(
Source : in Record_Dynamic_String;
Path : in String_1)
return Boolean;
function Are_Equal_Paths(
Source : in Record_Dynamic_String;
Path : in String_2)
return Boolean;
function Are_Equal_Path_Prefixes(
Source : in Record_Dynamic_String;
Path : in Record_Dynamic_String)
return Boolean;
function Are_Equal_Path_Prefixes(
Source : in Record_Dynamic_String;
Path : in String_1)
return Boolean;
function Are_Equal_Path_Prefixes(
Source : in Record_Dynamic_String;
Path : in String_2)
return Boolean;
function Does_Contain_Lower_Case(
Item : in Record_Dynamic_String)
return Boolean;
function Does_Contain_Upper_Case(
Item : in Record_Dynamic_String)
return Boolean;
function Is_Numeric(
Item : in Record_Dynamic_String)
return Boolean;
function Is_Empty(
Item : in Record_Dynamic_String)
return Boolean;
procedure Empty(
Item : in out Record_Dynamic_String);
function Empty(
Item : in Record_Dynamic_String)
return Record_Dynamic_String;
procedure Clear(
Item : in out Record_Dynamic_String);
procedure Fill_With_Character(
Source : in out Record_Dynamic_String;
Item : in Character_1;
Up_To_Index : in Integer_4_Positive);
-- ???
procedure Insert_After(
Source : in out Record_Dynamic_String;
Addition : in Record_Dynamic_String;
Index : in Integer_4_Positive);
procedure Insert_After(
Source : in out Record_Dynamic_String;
Addition : in Character_1;
Index : in Integer_4_Positive);
procedure Insert_After(
Source : in out Record_Dynamic_String;
Addition : in Character_2;
Index : in Integer_4_Positive);
procedure Insert_After(
Source : in out Record_Dynamic_String;
Addition : in String_1;
Index : in Integer_4_Positive);
procedure Insert_After(
Source : in out Record_Dynamic_String;
Addition : in String_2;
Index : in Integer_4_Positive);
function Index(
Source : in Record_Dynamic_String;
Pattern : in String;
Going : in Direction := Forward;
Mapping : in Maps.Character_Mapping := Maps.Identity)
return Integer_4_Natural;
function Index(
Source : in Record_Dynamic_String;
Pattern : in String;
Going : in Direction := Forward;
Mapping : in Maps.Character_Mapping_Function)
return Integer_4_Natural;
function Index(
Source : in Record_Dynamic_String;
Set : in Maps.Character_Set;
Test : in Membership := Inside;
Going : in Direction := Forward)
return Integer_4_Natural;
function Index_Non_Blank(
Source : in Record_Dynamic_String;
Going : in Direction := Forward)
return Integer_4_Natural;
function Count(
Source : in Record_Dynamic_String;
Pattern : in String;
Mapping : in Maps.Character_Mapping := Maps.Identity)
return Integer_4_Natural;
function Count(
Source : in Record_Dynamic_String;
Pattern : in String;
Mapping : in Maps.Character_Mapping_Function)
return Integer_4_Natural;
function Count(
Source : in Record_Dynamic_String;
Set : in Maps.Character_Set)
return Integer_4_Natural;
procedure Find_Token(
Source : in Record_Dynamic_String;
Set : in Maps.Character_Set;
Test : in Membership;
First : in out Integer_4_Positive;
Last : in out Integer_4_Natural);
function Replace_Slice(
Source : in Record_Dynamic_String;
Low : in Integer_4_Positive;
High : in Integer_4_Natural;
By : in String)
return Record_Dynamic_String;
procedure Replace_Slice(
Source : in out Record_Dynamic_String;
Low : in Integer_4_Positive;
High : in Integer_4_Natural;
By : in String);
function Insert(
Source : in Record_Dynamic_String;
Before : in Integer_4_Positive;
New_Item : in String)
return Record_Dynamic_String;
procedure Insert(
Source : in out Record_Dynamic_String;
Before : in Integer_4_Positive;
New_Item : in String);
function Overwrite(
Source : in Record_Dynamic_String;
Position : in Integer_4_Positive;
New_Item : in String)
return Record_Dynamic_String;
procedure Overwrite(
Source : in out Record_Dynamic_String;
Position : in Integer_4_Positive;
New_Item : in String);
function Delete(
Source : in Record_Dynamic_String;
From : in Integer_4_Positive;
Through : in Integer_4_Natural)
return Record_Dynamic_String;
procedure Delete(
Source : in out Record_Dynamic_String;
From : in Integer_4_Positive;
Through : in Integer_4_Natural);
function Trim(
Source : in Record_Dynamic_String;
Side : in Trim_End)
return Record_Dynamic_String;
procedure Trim(
Source : in out Record_Dynamic_String;
Side : in Trim_End);
function Trim(
Source : in Record_Dynamic_String;
Left : in Maps.Character_Set;
Right : in Maps.Character_Set)
return Record_Dynamic_String;
procedure Trim(
Source : in out Record_Dynamic_String;
Left : in Maps.Character_Set;
Right : in Maps.Character_Set);
function Head(
Source : in Record_Dynamic_String;
Count : in Integer_4_Natural;
Pad : in Character := Space)
return Record_Dynamic_String;
procedure Head(
Source : in out Record_Dynamic_String;
Count : in Integer_4_Natural;
Pad : in Character := Space);
function Tail(
Source : in Record_Dynamic_String;
Count : in Integer_4_Natural;
Pad : in Character := Space)
return Record_Dynamic_String;
procedure Tail(
Source : in out Record_Dynamic_String;
Count : in Integer_4_Natural;
Pad : in Character := Space);
static bool IsValidUTF8( const uint8 * s, const int maxLen, utf8Encoding_t & encoding );
static ID_INLINE bool IsValidUTF8( const char * s, const int maxLen, utf8Encoding_t & encoding ) { return IsValidUTF8( ( const uint8* )s, maxLen, encoding ); }
static ID_INLINE bool IsValidUTF8( const uint8 * s, const int maxLen );
static ID_INLINE bool IsValidUTF8( const char * s, const int maxLen ) { return IsValidUTF8( ( const uint8* )s, maxLen ); }
int Find( const char c, int start = 0, int end = -1 ) const;
int Find( const char *text, bool casesensitive = true, int start = 0, int end = -1 ) const;
bool Filter( const char *filter, bool casesensitive ) const;
int Last( const char c ) const; -- return the index to the last occurance of 'c', returns -1 if not found
void Format( VERIFY_FORMAT_STRING const char *fmt, ... ); -- perform a threadsafe sprintf to the Source
static idStr FormatInt( const int num, bool isCash = false ); -- formats an integer as a value with commas
static idStr FormatCash( const int num ) { return FormatInt( num, true ); }
void StripTrailingWhitespace(); -- strip trailing white space characters
idStr & StripQuotes(); -- strip quotes around Source
bool Replace( const char *old, const char *nw );
bool ReplaceChar( const char old, const char nw );
ID_INLINE void CopyRange( const char * text, int start, int end );
-- file name methods
int FileNameHash() const; -- hash key for the filename (skips extension)
idStr & BackSlashesToSlashes(); -- convert slashes
idStr & SlashesToBackSlashes(); -- convert slashes
idStr & SetFileExtension( const char *extension ); -- set the given file extension
idStr & StripFileExtension(); -- remove any file extension
idStr & StripAbsoluteFileExtension(); -- remove any file extension looking from front (useful if there are multiple .'s)
idStr & DefaultFileExtension( const char *extension ); -- if there's no file extension use the default
idStr & DefaultPath( const char *basepath ); -- if there's no path use the default
void AppendPath( const char *text ); -- append a partial path
idStr & StripFilename(); -- remove the filename from a path
idStr & StripPath(); -- remove the path from the filename
void ExtractFilePath( idStr &dest ) const; -- copy the file path to another Source
void ExtractFileName( idStr &dest ) const; -- copy the filename to another Source
void ExtractFileBase( idStr &dest ) const; -- copy the filename minus the extension to another Source
void ExtractFileExtension( idStr &dest ) const; -- copy the file extension to another Source
bool CheckExtension( const char *ext );
-- hash keys
static int Hash( const char *Source );
static int Hash( const char *Source, int length );
static int IHash( const char *Source ); -- case insensitive
static int IHash( const char *Source, int length ); -- case insensitive
friend int sprintf( idStr &dest, const char *fmt, ... );
friend int vsprintf( idStr &dest, const char *fmt, va_list ap );
void ReAllocate( int amount, bool keepold ); -- reallocate Source data buffer
void FreeData(); -- free allocated Source memory
-- format value in the given measurement with the best unit, returns the best unit
int BestUnit( const char *format, float value, Measure_t measure );
-- format value in the requested unit and measurement
void SetUnit( const char *format, float value, int unit, Measure_t measure );
static void InitMemory();
static void ShutdownMemory();
static void PurgeMemory();
static void ShowMemoryUsage_f( const idCmdArgs &args );
int DynamicMemoryUsed() const;
static idStr FormatNumber( int number );
ASSERT_ENUM_STRING( Source, index ) ( 1 / (int)!( Source - index ) ) ? #Source : ""
-------
private
-------
---------------
-- Constants --
---------------
FILE_HASH_SIZE : constant Integer_4_Positive := 1024;
MINIMUM_STRING_ALLOCATION_IN_BYTES : constant Integer_4_Positive := 20;
MAXIMUM_STRING_ALLOCATION_IN_BYTES : constant Integer_4_Positive := 32;
static const uint32 STATIC_BIT = 31;
static const uint32 STATIC_MASK = 1u << STATIC_BIT;
static const uint32 ALLOCED_MASK = STATIC_MASK - 1;
------------
-- Arrays --
------------
type Array_Base_Buffer
is array 1..MINIMUM_STRING_ALLOCATION_IN_BYTES
of Integer_1_Unsigned;
-------------
-- Records --
-------------
type Record_Dynamic_String
is record
Length : Integer_4_Natural;
Data : Access_Array_Integer_1_Unsigned;
Is_Data_Static : Boolean;
Number_Of_Bytes_Allocated : Integer_4_Natural;
Buffer : Array_Base_Buffer;
end record;
-----------------
-- Subprograms --
-----------------
procedure Enusure_Buffer_Is_Large_Enough(
Amount : in Integer_4_Positive;
Do_Keep_Old : in Boolean := True);
procedure Set_Static_Buffer(
Buffer : in
void EnsureAlloced( int amount, bool keepold = true ); -- ensure Source data buffer is large anough
-- sets the data point to the specified buffer... note that this ignores makes the passed buffer empty and ignores
-- anything currently in the idStr's dynamic buffer. This method is intended to be called only from a derived class's constructor.
ID_INLINE void SetStaticBuffer( char * buffer, const int bufferLength );
ID_INLINE void Construct();
ID_INLINE int GetAlloced() const { return allocedAndFlag & ALLOCED_MASK; }
ID_INLINE void SetAlloced( const int a ) { allocedAndFlag = ( allocedAndFlag & STATIC_MASK ) | ( a & ALLOCED_MASK); }
ID_INLINE bool IsStatic() const { return ( allocedAndFlag & STATIC_MASK ) != 0; }
ID_INLINE void SetStatic( const bool isStatic ) { allocedAndFlag = ( allocedAndFlag & ALLOCED_MASK ) | ( isStatic << STATIC_BIT ); }
end Neo.Library.Dynamic_String;