Rosetta Code/Rank languages by popularity: Difference between revisions
Rosetta Code/Rank languages by popularity (view source)
Revision as of 15:37, 3 June 2024
, 27 days ago→{{header|Ada}}
JoseAlexis (talk | contribs) |
JoseAlexis (talk | contribs) |
||
(One intermediate revision by one other user not shown) | |||
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 :
Language : Unbounded_String;
end record;
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 =>
Right =>
end "<";
Line 86 ⟶ 85:
procedure Find_Counts (S : String) is
function Strip_Character (S : String; C :
S_Copy_Index : Natural := 0;
begin
S_Copy_Index := S_Copy_Index + 1;
else▼
& S (Comma_At + 1 .. S'Last), C);▼
end
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 := [
+"Programming",
+"Examples needing attention",
Line 150 ⟶ 152:
];
begin
for
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
End_A_Tag_Str : constant String
Space_Paren_Str : constant String := " (";
Line 192 ⟶ 193:
Count : constant Natural :=
Natural'Value
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",
Status : Status_Code;
begin
Line 255 ⟶ 258:
Put_Line ("Process complete.");
end Rank_Languages_By_Popularity;
</syntaxhighlight>
{{out|Sample output}}
Line 2,577 ⟶ 2,579:
=={{header|Java}}==
Tested with Java 1.
<syntaxhighlight lang="java">
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.io.*;
Line 2,625 ⟶ 2,629:
{
URL url = new
URLConnection rc = url.openConnection();
BufferedReader bfr = new BufferedReader( new InputStreamReader( rc.getInputStream() ) );
Line 2,636 ⟶ 2,638:
while( line != null )
{
line = line.trim().replaceAll( "[\",]", "" );
if ( line.startsWith( "
{
// have a programming language - should look like "
languageName = after( after( line, ':' ), ':' ).trim();
}
else if( line.startsWith( "
{
// number of pages the language has (probably)
String pageCount = after( line, '
if( pageCount.compareTo( "
{
// haven't got "
languageList.add( ( (char) Integer.parseInt( pageCount ) ) + languageName );
languageName = "?";
} // if [pageCount.compareTo( "
}
else if( line.startsWith( "
{
// have an indication of wether there is more data or not
gcmcontinue[0] = after( line, '
} // if various line starts
line = bfr.readLine();
Line 2,676 ⟶ 2,678:
do
{
String path = ( "
+ "&generator=categorymembers"
+ "&gcmtitle=Category:Programming%20Languages"
Line 2,682 ⟶ 2,684:
+ ( gcmcontinue[0].compareTo( "" ) == 0 ? "" : ( "&gcmcontinue=" + gcmcontinue[0] ) )
+ "&prop=categoryinfo"
+ "&format=
);
parseContent( path, gcmcontinue, languageList );
Line 2,708 ⟶ 2,710:
} // for lPos
} // main
} // GetRCLanguages
</syntaxhighlight>
{{out}}
Top 10 languages as at
<pre>
1:
3:
4:
5:
6:
7:
8:
9:
10:
...
</pre>
|