diff trunk/src/cmd/Statistics.d @ 391:33b566df6af4

Migrated project to Tango. Decremented the numbers of the format placeholders in the localized messages by one. Replaced all instances of writef/ln with Stdout. Added module common.d with string aliases and a global Layout!(char) instance. Replaced %s format specifiers with index placeholders in html/xml_tags. Changed member Information.arguments to string message. Copied std.metastring, std.uni and std.utf from Phobos.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sat, 15 Sep 2007 17:12:26 +0200
parents 1059295c2727
children fcdf7ac5ad27
line wrap: on
line diff
--- a/trunk/src/cmd/Statistics.d	Wed Sep 12 21:03:41 2007 +0200
+++ b/trunk/src/cmd/Statistics.d	Sat Sep 15 17:12:26 2007 +0200
@@ -6,7 +6,7 @@
 import dil.Token;
 import dil.File;
 import dil.Lexer;
-import std.stdio;
+import common;
 
 struct Statistics
 {
@@ -24,7 +24,6 @@
   auto lx = new Lexer(sourceText, fileName);
 
   auto token = lx.getTokens();
-  char* end = lx.text.ptr;
 
   Statistics stats;
   // Traverse linked list.
@@ -33,9 +32,10 @@
     token = token.next;
 
     // Count whitespace characters
-    if (end != token.start)
+    if (token.ws)
     {
-      stats.whitespaceCount += token.start - end;
+      // TODO: naive method doesn't account for \r\n, LS and PS.
+      stats.whitespaceCount += token.start - token.ws;
     }
 
     switch (token.type)
@@ -58,21 +58,20 @@
 
     if (token.isWhitespace)
       stats.wsTokenCount++;
-
-    end = token.end;
   }
-  writefln("Whitespace character count: %s\n"
-           "Whitespace token count: %s\n"
-           "Keyword count: %s\n"
-           "Identifier count: %s\n"
-           "Number count: %s\n"
-           "Comment count: %s\n"
-           "Lines of code: %s",
-           stats.whitespaceCount,
-           stats.wsTokenCount,
-           stats.keywordCount,
-           stats.identCount,
-           stats.numberCount,
-           stats.commentCount,
-           lx.loc);
+  Stdout.formatln(
+    "Whitespace character count: {0}\n"
+    "Whitespace token count: {1}\n"
+    "Keyword count: {2}\n"
+    "Identifier count: {3}\n"
+    "Number count: {4}\n"
+    "Comment count: {5}\n"
+    "Lines of code: {6}",
+    stats.whitespaceCount,
+    stats.wsTokenCount,
+    stats.keywordCount,
+    stats.identCount,
+    stats.numberCount,
+    stats.commentCount,
+    lx.loc);
 }