1 22 23 package org.gjt.sp.jedit.indent; 24 25 29 public abstract class BracketIndentRule implements IndentRule 30 { 31 public BracketIndentRule(char openBracket, char closeBracket) 33 { 34 this.openBracket = openBracket; 35 this.closeBracket = closeBracket; 36 } 38 public static class Brackets 40 { 41 int openCount; 42 int closeCount; 43 } 45 public Brackets getBrackets(String line) 47 { 48 Brackets brackets = new Brackets(); 49 50 for(int i = 0; i < line.length(); i++) 51 { 52 char ch = line.charAt(i); 53 if(ch == openBracket) 54 { 55 57 if(line.length() - i >= 3) 58 { 59 if(line.substring(i,i+3).equals("{{{")) 60 { 61 i += 2; 62 continue; 63 } 64 } 65 brackets.openCount++; 66 } 67 else if(ch == closeBracket) 68 { 69 if(brackets.openCount != 0) 70 brackets.openCount--; 71 else 72 brackets.closeCount++; 73 } 74 } 75 76 return brackets; 77 } 79 public String toString() 81 { 82 return getClass().getName() + "[" + openBracket + "," 83 + closeBracket + "]"; 84 } 86 protected char openBracket, closeBracket; 87 } 88 | Popular Tags |