Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 5.30 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.io.*;
  2. import java.lang.*;
  3. import java.util.Scanner;
  4. public class FormatFile {
  5.         File newfile;
  6.         public FormatFile(File format){
  7.                 newfile = format;
  8.         }
  9.         public void check() throws FileNotFoundException{
  10.  
  11.  
  12.                 Scanner input = new Scanner(newfile);
  13.                
  14.                 while (input.hasNext()){
  15.                         String returnstring = input.next();
  16.                         int holder = returnstring.length();
  17.                         returnstring.replace("assert", "<FONT COLOR=RED>assert</FONT>");
  18.                         returnstring.replace("break", "<FONT COLOR=RED>break</FONT>");
  19.                         returnstring.replace("case", "<FONT COLOR=RED>case</FONT>");
  20.                         returnstring.replace("public", "<FONT COLOR=RED>public</FONT>");
  21.                         returnstring.replace("long", "<FONT COLOR=RED>long</FONT>");
  22.                         returnstring.replace("double", "<FONT COLOR=RED>double</FONT>");
  23.                         returnstring.replace("extends", "<FONT COLOR=RED>extends</FONT>");
  24.                         returnstring.replace("abstract", "<FONT COLOR=RED>abstract</FONT>");
  25.                         returnstring.replace("boolean", "<FONT COLOR=RED>boolean</FONT>");
  26.                         returnstring.replace("byte", "<FONT COLOR=RED>byte</FONT>");
  27.                         returnstring.replace("char", "<FONT COLOR=RED>char</FONT>");
  28.                         returnstring.replace("class", "<FONT COLOR=RED>class</FONT>");
  29.                         returnstring.replace("for", "<FONT COLOR=RED>for</FONT>");
  30.                         returnstring.replace("final", "<FONT COLOR=RED>final</FONT>");
  31.                         returnstring.replace("finally", "<FONT COLOR=RED>finally</FONT>");
  32.                         returnstring.replace("float", "<FONT COLOR=RED>float</FONT>");
  33.                         returnstring.replace("catch", "<FONT COLOR=RED>catch</FONT>");
  34.                         returnstring.replace("char", "<FONT COLOR=RED>char</FONT>");
  35.                         returnstring.replace("const", "<FONT COLOR=RED>const</FONT>");
  36.                         returnstring.replace("continue", "<FONT COLOR=RED>continue</FONT>");
  37.                         returnstring.replace("default", "<FONT COLOR=RED>default</FONT>");
  38.                         returnstring.replace("else", "<FONT COLOR=RED>else</FONT>");
  39.                         returnstring.replace("enum", "<FONT COLOR=RED>enum</FONT>");
  40.                         returnstring.replace("goto", "<FONT COLOR=RED>goto</FONT>");
  41.                         returnstring.replace("if", "<FONT COLOR=RED>if</FONT>");
  42.                         returnstring.replace("implements", "<FONT COLOR=RED>implements</FONT>");
  43.                         returnstring.replace("import", "<FONT COLOR=RED>import</FONT>");
  44.                         returnstring.replace("instanceof", "<FONT COLOR=RED>instanceof</FONT>");
  45.                         returnstring.replace("int", "<FONT COLOR=RED>int</FONT>");
  46.                         returnstring.replace("interface", "<FONT COLOR=RED>interface</FONT>");
  47.                         returnstring.replace("long", "<FONT COLOR=RED>long</FONT>");
  48.                         returnstring.replace("native", "<FONT COLOR=RED>native</FONT>");
  49.                         returnstring.replace("new", "<FONT COLOR=RED>new</FONT>");
  50.                         returnstring.replace("package", "<FONT COLOR=RED>package</FONT>");
  51.                         returnstring.replace("private", "<FONT COLOR=RED>private</FONT>");
  52.                         returnstring.replace("protected", "<FONT COLOR=RED>protected</FONT>");
  53.                         returnstring.replace("return", "<FONT COLOR=RED>return</FONT>");
  54.                         returnstring.replace("short", "<FONT COLOR=RED>short</FONT>");
  55.                         returnstring.replace("static", "<FONT COLOR=RED>static</FONT>");
  56.                         returnstring.replace("super", "<FONT COLOR=RED>super</FONT>");
  57.                         returnstring.replace("switch", "<FONT COLOR=RED>switch</FONT>");
  58.                         returnstring.replace("synchronized", "<FONT COLOR=RED>synchronized</FONT>");
  59.                         returnstring.replace("this", "<FONT COLOR=RED>this</FONT>");
  60.                         returnstring.replace("throws", "<FONT COLOR=RED>throws</FONT>");
  61.                         returnstring.replace("transient", "<FONT COLOR=RED>transient</FONT>");
  62.                         returnstring.replace("try", "<FONT COLOR=RED>try</FONT>");
  63.                         returnstring.replace("void", "<FONT COLOR=RED>void</FONT>");
  64.                         returnstring.replace("volatile", "<FONT COLOR=RED>volatile</FONT>");
  65.                         returnstring.replace("white", "<FONT COLOR=RED>white</FONT>");
  66.  
  67.                         if (returnstring.charAt(0) == '/'){
  68.                                 if (returnstring.charAt(1) == '/'){
  69.                                         returnstring = "<FONT COLOR=GREEN>" + returnstring + "</FONT>";
  70.                                 }
  71.                                 else if(returnstring.charAt(1) == '*'){
  72.                                         returnstring = "<FONT COLOR=GREEN>" + returnstring;
  73.                                         for (int i = 0; i < 10;){
  74.                                                 returnstring = input.next();
  75.                                                
  76.                                                 if (returnstring.charAt(holder) == '/'){
  77.                                                         if (returnstring.charAt(holder - 1) == '*'){
  78.                                                                 returnstring = returnstring + "</FONT>";
  79.                                                                 i = 10;
  80.                                                         }
  81.                                                 }
  82.                                         }
  83.                                 }
  84.                         }
  85.                         else if(returnstring.indexOf('"') != -1){
  86.                                 returnstring = returnstring.substring(0, returnstring.indexOf('"')) + "<FONT COLOR=BLUE>" + returnstring.substring(returnstring.lastIndexOf('"')) + "</FONT>";
  87.                         }
  88.                         else if (returnstring.indexOf("'") != -1){
  89.                                 returnstring = returnstring.substring(0, returnstring.indexOf("'")) + "<FONT COLOR=BLUE>" + returnstring.substring(returnstring.lastIndexOf("'")) + "</FONT>";
  90.                         }
  91.                         for (int i = 0; i < holder; i++){
  92.                                
  93.                                 if (isDigit(returnstring.charAt(i))){
  94.                                        
  95.                                 }
  96.                         }
  97.                 }
  98.         }
  99.         private boolean isDigit(char charAt) {
  100.                 boolean isdigit = false;
  101.                
  102.                 if (charAt == 0){
  103.                         isdigit = true;
  104.                 }
  105.                 else if(charAt == 1){
  106.                         isdigit = true;
  107.                 }
  108.                 else if(charAt == 2){
  109.                         isdigit = true;
  110.                 }
  111.                 else if(charAt == 3){
  112.                         isdigit = true;
  113.                 }
  114.                 else if(charAt == 4){
  115.                         isdigit = true;
  116.                 }
  117.                 else if(charAt == 5){
  118.                         isdigit = true;
  119.                 }
  120.                 else if(charAt == 6){
  121.                         isdigit = true;
  122.                 }
  123.                 else if(charAt == 7){
  124.                         isdigit = true;
  125.                 }
  126.                 else if(charAt == 8){
  127.                         isdigit = true;
  128.                 }
  129.                 else if(charAt == 9){
  130.                         isdigit = true;
  131.                 }
  132.                 return isdigit;
  133.         }
  134.        
  135. }