Rosetta Code/Rank languages by popularity: Difference between revisions

(Updated for changes in the MediaWiki API and the JDK)
 
Line 43:
 
with Ada.Containers.Ordered_Sets;
with Ada.Strings.Unbounded.Less_Case_Insensitive;
with Ada.Characters.Handling; use Ada.Characters.Handling;
 
Line 59:
type A_Language_Count is
record
Count : IntegerNatural := 0;
Language : Unbounded_String;
end record;
 
overriding
function "=" (L, R : A_Language_Count) return Boolean is
begin
Line 75 ⟶ 74:
or else (L.Count = R.Count
and then Less_Case_Insensitive
(Left => To_String (L.Language),
Right => To_String (R.Language)));
end "<";
 
Line 86 ⟶ 85:
procedure Find_Counts (S : String) is
 
function Strip_Character (S : String; C : StringCharacter) return String is
Comma_AtS_Copy_Str : constantString Natural(1 := Ada.Strings.Fixed.Index (S, C'Length);
S_Copy_Index : Natural := 0;
begin
iffor Comma_AtI =in 0S'Range thenloop
returnif S; (I) /= C then
S_Copy_Index := S_Copy_Index + 1;
else
return Strip_Character (S S_Copy_Str (S'FirstS_Copy_Index) ..:= Comma_AtS - 1(I);
else end if;
& S (Comma_At + 1 .. S'Last), C);
end ifloop;
 
return S_Copy_Str (S_Copy_Str'First .. S_Copy_Index);
end Strip_Character;
 
Line 101 ⟶ 103:
of Unbounded_String;
-- This list is quite comprehensive, but not complete
Categories_To_Ignore : Unbounded_String_Array := [
:= [ +"Pages with syntax highlighting errors",
+"Programming",
+"Examples needing attention",
Line 150 ⟶ 152:
];
begin
for ICategory inof Categories_To_Ignore'Range loop
declare
Category_At : constant Natural :=
Index (+To_Lower (L),
To_Lower (To_String (Category)));
To_String (Categories_To_Ignore (I))));
begin
if Category_At /= 0 then
Line 166 ⟶ 167:
end Ignore_Category;
 
Title_Str : constant String := "title=""Category:";
End_A_Tag_Str : constant String := "</a>";
Space_Paren_Str : constant String := " (";
 
Line 192 ⟶ 193:
 
Count : constant Natural :=
Natural'Value (Strip_Character (
S (Space_Paren_At + Space_Paren_Str'Length Strip_Character (
.. Space_At - 1), S (Space_Paren_At +
",")); Space_Paren_Str'Length
& S (Comma_At + 1 .. S'Last),Space_At C- 1);,
To_String (Categories_To_Ignore (I))','));
begin
if Closing_Bracket_At /= 0
Line 233 ⟶ 236:
Http_Source : constant AWS.Response.Data :=
AWS.Client.Get ("http://rosettacode.org/w/index.php?" &
"title=Special:Categories&limit=5000",
, Follow_Redirection => True);
Status : Status_Code;
begin
Line 255 ⟶ 258:
Put_Line ("Process complete.");
end Rank_Languages_By_Popularity;
 
</syntaxhighlight>
{{out|Sample output}}
9

edits