changeset 506:1b897a4536a4

Refactored code and fixed a few things in cmd.Statistics.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Wed, 12 Dec 2007 02:28:37 +0100
parents 3bb94ba21490
children 996041463028
files trunk/src/cmd/Statistics.d
diffstat 1 files changed, 7 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/cmd/Statistics.d	Wed Dec 12 02:25:42 2007 +0100
+++ b/trunk/src/cmd/Statistics.d	Wed Dec 12 02:28:37 2007 +0100
@@ -87,8 +87,8 @@
 {
   auto sourceText = loadFile(filePath);
   auto lx = new Lexer(sourceText, filePath);
-
-  auto token = lx.getTokens();
+  lx.scanAll();
+  auto token = lx.firstToken();
 
   Statistics stats;
 
@@ -100,7 +100,7 @@
 
     // Count whitespace characters
     if (token.ws !is null)
-      stats.whitespaceCount += countWhitespaceCharacters(token.ws, token.start);
+      stats.whitespaceCount += token.start - token.ws;
 
     switch (token.type)
     {
@@ -115,47 +115,14 @@
          TOK.Imaginary32, TOK.Imaginary64, TOK.Imaginary80:
       stats.numberCount++;
       break;
+    case TOK.Newline:
+      break;
     default:
       if (token.isKeyword)
         stats.keywordCount++;
+      else if (token.isWhitespace)
+        stats.wsTokenCount++;
     }
-
-    if (token.isWhitespace)
-      stats.wsTokenCount++;
   }
   return stats;
 }
-
-/// Counts newlines, \t, \v, \f and ' ' as whitespace characters.
-uint countWhitespaceCharacters(char* p, char* end)
-{
-  uint count;
-Loop:
-  while (1)
-  {
-    switch (*p)
-    {
-    case '\r':
-      if (p[1] == '\n')
-        ++p;
-    case '\n':
-      ++p;
-      ++count;
-      break;
-    case LS[0]:
-      if (p[1] == LS[1] && (p[2] == LS[2] || p[2] == PS[2]))
-      {
-        p += 3;
-        ++count;
-        break;
-      }
-    default:
-      if (!dil.Lexer.isspace(*p))
-        break Loop; // Exit loop.
-      ++p;
-      ++count;
-    }
-  }
-  assert(p is end);
-  return count;
-}