1 22 23 package org.armedbear.j; 24 25 public final class RubySyntaxIterator extends DefaultSyntaxIterator 26 { 27 private static final int STATE_NEUTRAL = 0; 28 private static final int STATE_QUOTE = 1; 29 30 public RubySyntaxIterator(Position pos) 31 { 32 super(pos); 33 } 34 35 public char[] hideSyntacticWhitespace(String s) 38 { 39 char[] chars = s.toCharArray(); 40 char quoteChar = 0; 41 int state = STATE_NEUTRAL; 42 final int length = chars.length; 43 for (int i = 0; i < length; i++) { 44 char c = chars[i]; 45 if (c == '\\' && i < length-1) { 46 chars[++i] = ' '; 48 } else if (state == STATE_QUOTE) { 49 chars[i] = ' '; 50 if (c == quoteChar) 51 state = STATE_NEUTRAL; 52 } else if (c == '"' || c == '\'') { 53 quoteChar = c; 54 state = STATE_QUOTE; 55 chars[i] = ' '; 56 } 57 } 58 int index = -1; 60 for (int i = 0; i < length; i++) { 61 if (chars[i] == '#') { 62 if (i > 0) { 63 char c = chars[i-1]; 65 if (c == '\\') 66 continue; 67 } 68 index = i; 70 break; 71 } 72 } 73 if (index >= 0) { 74 for (int i = index; i < length; i++) 75 chars[i] = ' '; 76 } 77 return chars; 78 } 79 } 80 | Popular Tags |