1   /*
2    * RDFpro - An extensible tool for building stream-oriented RDF processing libraries.
3    * 
4    * Written in 2014 by Francesco Corcoglioniti with support by Marco Amadori, Michele Mostarda,
5    * Alessio Palmero Aprosio and Marco Rospocher. Contact info on http://rdfpro.fbk.eu/
6    * 
7    * To the extent possible under law, the authors have dedicated all copyright and related and
8    * neighboring rights to this software to the public domain worldwide. This software is
9    * distributed without any warranty.
10   * 
11   * You should have received a copy of the CC0 Public Domain Dedication along with this software.
12   * If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
13   */
14  package eu.fbk.rdfpro.tql;
15  
16  import java.nio.charset.Charset;
17  
18  import org.openrdf.rio.RDFFormat;
19  
20  /**
21   * Constants for the Turtle Quads (TQL) format.
22   * <p>
23   * The Turtle Quads {@link RDFFormat} is defined by constant {@link #FORMAT}. As this constant is
24   * not part of the predefined set of formats in {@link RDFFormat}, it is necessary to register it.
25   * This can be done either via {@link RDFFormat#register(RDFFormat)}, or by simply calling method
26   * {@link #register()} on this class, which ensures that multiple calls will result in a single
27   * registration.
28   * </p>
29   */
30  public final class TQL {
31  
32      /** RDFFormat constant for the Turtle Quads (TQL) format). */
33      public static final RDFFormat FORMAT = new RDFFormat("Turtle Quads", "application/x-tql",
34              Charset.forName("UTF-8"), "tql", false, true);
35  
36      /**
37       * Registers the Turtle Quads format in the RIO registry. Calling this method multiple times
38       * results in a single registration. Note that registration is also done transparently the
39       * first time this class is accessed.
40       * 
41       * @deprecated as of Sesame 2.8, calling this method is not necessary - it is enough to avoid
42       *             using the deprecated RDFFormat.forFileName() (and other static methods) for
43       *             looking up an RDFFormat, and instead rely on methods in the Rio class
44       */
45      @Deprecated
46      public static void register() {
47          // Calling this method will cause the static initializer to run once
48      }
49  
50      // Package protected utility methods
51  
52      static boolean isPN_CHARS(final int c) { // ok
53          return isPN_CHARS_U(c) || isNumber(c) || c == '-' || c == 0x00B7 || c >= 0x0300
54                  && c <= 0x036F || c >= 0x203F && c <= 0x2040;
55      }
56  
57      static boolean isPN_CHARS_U(final int c) { // ok
58          return isPN_CHARS_BASE(c) || c == '_';
59      }
60  
61      static boolean isPN_CHARS_BASE(final int c) { // ok
62          return isLetter(c) || c >= 0x00C0 && c <= 0x00D6 || c >= 0x00D8 && c <= 0x00F6
63                  || c >= 0x00F8 && c <= 0x02FF || c >= 0x0370 && c <= 0x037D || c >= 0x037F
64                  && c <= 0x1FFF || c >= 0x200C && c <= 0x200D || c >= 0x2070 && c <= 0x218F
65                  || c >= 0x2C00 && c <= 0x2FEF || c >= 0x3001 && c <= 0xD7FF || c >= 0xF900
66                  && c <= 0xFDCF || c >= 0xFDF0 && c <= 0xFFFD || c >= 0x10000 && c <= 0xEFFFF;
67      }
68  
69      static boolean isLetter(final int c) {
70          return c >= 65 && c <= 90 || c >= 97 && c <= 122;
71      }
72  
73      static boolean isNumber(final int c) {
74          return c >= 48 && c <= 57;
75      }
76  
77  }