391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
if Word_Maps.Has_Element (Cursor) then
Word_Maps.Update_Element (Counter.Map, Cursor, Update'Access);
else
Word_Maps.Insert (Counter.Map, Word, Count);
end if;
end Add_Word;
function Simple_Dictionary
(Counter : in Word_Counter;
Word_Count : in Natural)
return String_Lists.List
is
use type Ada.Containers.Count_Type;
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
if Word_Maps.Has_Element (Cursor) then
Word_Maps.Update_Element (Counter.Map, Cursor, Update'Access);
else
Word_Maps.Insert (Counter.Map, Word, Count);
end if;
end Add_Word;
procedure Add_Words
(Counter : in out Word_Counter;
Phrase : in String;
Min_Size : in Positive;
Max_Size : in Positive)
is
subtype Word_Part is Character with Static_Predicate
=> Word_Part in '0' .. '9' | 'A' .. 'Z' | 'a' .. 'z'
| Character'Val (128) .. Character'Val (255);
I, First, Next : Positive;
begin
if Max_Size < Min_Size then
return;
end if;
I := Phrase'First;
Main_Loop :
while I in Phrase'Range loop
Skip_Non_Word :
while I in Phrase'Range and then Phrase (I) not in Word_Part loop
I := I + 1;
end loop Skip_Non_Word;
exit Main_Loop when I not in Phrase'Range;
First := I;
Skip_Word :
while I in Phrase'Range and then Phrase (I) in Word_Part loop
I := I + 1;
end loop Skip_Word;
Next := I;
if Next - First in Min_Size .. Max_Size then
Add_Word (Counter, Phrase (First .. Next - 1));
end if;
end loop Main_Loop;
end Add_Words;
function Simple_Dictionary
(Counter : in Word_Counter;
Word_Count : in Natural)
return String_Lists.List
is
use type Ada.Containers.Count_Type;
|