Returns a valid token representation of the specified value. @param value object (can be null, will be converted to token otherwise) @param validate validate input @return token, or null if validation is enabled and if invalid characters are found
(final Object value, final boolean validate)
| 239 | * @return token, or {@code null} if validation is enabled and if invalid characters are found |
| 240 | */ |
| 241 | public static byte[] check(final Object value, final boolean validate) { |
| 242 | if(value == null) return Token.EMPTY; |
| 243 | |
| 244 | final TokenBuilder tb = new TokenBuilder(); |
| 245 | final TokenParser tp = new TokenParser(Token.token(value)); |
| 246 | while(tp.more()) { |
| 247 | final int cp = tp.next(); |
| 248 | if(valid(cp)) { |
| 249 | tb.add(cp); |
| 250 | } else { |
| 251 | if(validate) return null; |
| 252 | tb.add(Token.REPLACEMENT); |
| 253 | } |
| 254 | } |
| 255 | return tb.finish(); |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Checks the specified token as an NCName. |