Java, JavaCC: How to check if a char (or char pair) is inside a given UTF32 range?

Posted by java.is.for.desktop on Stack Overflow See other posts from Stack Overflow or by java.is.for.desktop
Published on 2010-05-20T10:12:32Z Indexed on 2010/05/20 10:20 UTC
Read the original article Hit count: 240

Filed under:
|
|
|
|

Hello, everyone!

I am referring to the XML 1.1 spec.

Look at the definition of NameStartChar:

NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]

If I interpret this correctly, the last range (#x10000-#xEFFFF) goes beyond the UTF16 range of Java's char type. So it must be UTF32, right? So, I need to check pairs of char against this range, instead of single chars, right?

My questions are:

  • How do I check for such character ranges using standard Java methods?
  • How is it possible to define such ranges in JavaCC?
    • JavaCC complains about \u10000 and \uEFFFF

Thank you!

NOTE: Don't worry, I am not trying to write an own XML-parser. I need those character ranges for other reasons.

© Stack Overflow or respective owner

Related posts about java

Related posts about javacc