1 19 20 package org.netbeans.lib.lexer; 21 22 import org.netbeans.spi.lexer.CharPreprocessor; 23 import org.netbeans.spi.lexer.LexerInput; 24 25 36 37 public final class UnicodeEscapesPreprocessor extends CharPreprocessor { 38 39 42 protected void preprocessChar() { 43 int ch; 44 switch (ch = inputRead()) { 45 case '\\': switch (ch = inputRead()) { 50 case 'u': int i; 53 int c; 54 for (i = 4; i > 0; i--) { 55 switch (c = inputRead()) { 56 case '0': case '1': case '2': case '3': case '4': 57 case '5': case '6': case '7': case '8': case '9': 58 ch = (ch << 4) + (c - '0'); 59 break; 60 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 61 ch = (ch << 4) + (c - 'a' + 10); 62 break; 63 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 64 ch = (ch << 4) + (c - 'A' + 10); 65 break; 66 case LexerInput.EOF: i = -i; break; 70 default: inputBackup(1); i = -i; break; 74 } 75 } 76 if (i < 0) { outputPreprocessed((char)0xFFFF, 5 + i); 80 notifyError("Invalid unicode sequence"); 81 } else { 82 outputPreprocessed((char)ch, 5); 83 } 84 break; 85 86 default: 88 outputOriginal('\\'); 89 outputOriginal(ch); 90 break; 91 } 92 break; 93 94 default: 95 outputOriginal(ch); 96 break; 97 } 98 } 99 100 protected boolean isSensitiveChar(char ch) { 101 switch (ch) { 102 case '\\': 103 case '0': case '1': case '2': case '3': case '4': 104 case '5': case '6': case '7': case '8': case '9': 105 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 106 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 107 case 'u': 108 return true; 109 110 default: 111 return false; 112 } 113 } 114 115 protected int maxLookahead() { 116 return 1; 123 } 124 125 } 126 | Popular Tags |