List of usage examples for org.antlr.v4.runtime Lexer MIN_CHAR_VALUE
int MIN_CHAR_VALUE
To view the source code for org.antlr.v4.runtime Lexer MIN_CHAR_VALUE.
Click Source Link
From source file:loghub.configuration.CharSupport.java
License:BSD License
/** Return a string representing the escaped char for code c. E.g., If c * has value 0x100, you will get "\u0100". ASCII gets the usual * char (non-hex) representation. Control characters are spit out * as unicode. While this is specially set up for returning Java strings, * it can be used by any language target that has the same syntax. :) *//* w ww .j a va 2s . c om*/ public static String getANTLRCharLiteralForChar(int c) { if (c < Lexer.MIN_CHAR_VALUE) { return "'<INVALID>'"; } if (c < ANTLRLiteralCharValueEscape.length && ANTLRLiteralCharValueEscape[c] != null) { return '\'' + ANTLRLiteralCharValueEscape[c] + '\''; } if (Character.UnicodeBlock.of((char) c) == Character.UnicodeBlock.BASIC_LATIN && !Character.isISOControl((char) c)) { if (c == '\\') { return "'\\\\'"; } if (c == '\'') { return "'\\''"; } return '\'' + Character.toString((char) c) + '\''; } // turn on the bit above max "\uFFFF" value so that we pad with zeros // then only take last 4 digits String hex = Integer.toHexString(c | 0x10000).toUpperCase().substring(1, 5); String unicodeStr = "'\\u" + hex + "'"; return unicodeStr; }