1 20 21 package org.apache.directory.ldapstudio.ldifeditor.editor.text; 22 23 24 import org.eclipse.jface.text.rules.ICharacterScanner; 25 import org.eclipse.jface.text.rules.IRule; 26 import org.eclipse.jface.text.rules.IToken; 27 import org.eclipse.jface.text.rules.Token; 28 29 30 public class LdifValueRule implements IRule 31 { 32 33 private IToken token; 34 35 36 public LdifValueRule( IToken token ) 37 { 38 this.token = token; 39 } 40 41 42 public IToken evaluate( ICharacterScanner scanner ) 43 { 44 45 if ( matchContent( scanner ) ) 46 { 47 return this.token; 48 } 49 else 50 { 51 return Token.UNDEFINED; 52 } 53 54 } 55 56 57 protected boolean matchContent( ICharacterScanner scanner ) 58 { 59 60 int count = 0; 61 62 int c = scanner.read(); 63 while ( c != ICharacterScanner.EOF ) 64 { 65 66 if ( c == '\n' || c == '\r' ) 68 { 69 StringBuffer temp = new StringBuffer ( 3 ); 70 if ( c == '\r' ) 71 { 72 c = scanner.read(); 73 if ( c == '\n' ) 74 { 75 temp.append( c ); 76 } 77 else 78 { 79 scanner.unread(); 80 } 81 } 82 else if ( c == '\n' ) 83 { 84 c = scanner.read(); 85 if ( c == '\r' ) 86 { 87 temp.append( c ); 88 } 89 else 90 { 91 scanner.unread(); 92 } 93 } 94 95 c = scanner.read(); 96 if ( c == ' ' && c != ICharacterScanner.EOF ) 97 { 98 temp.append( c ); 100 count += temp.length(); 101 c = scanner.read(); 102 } 103 else 104 { 105 for ( int i = 0; i < temp.length(); i++ ) 106 scanner.unread(); 107 break; 108 } 109 } 110 else 111 { 112 count++; 113 c = scanner.read(); 114 } 115 } 116 scanner.unread(); 117 118 return count > 0; 119 } 120 121 } 122 | Popular Tags |