Debian Codegraph @

net/sf/saxon/regex/REFlags.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.regex;
9
10 /**
11 * Class representing a set of regular expression flags (some combination of i, m, s, x, q).
12 * Also contains options affecting the regular expression dialect: whether or not XPath 2.0
13 * and XPath 3.0 extensions to XSD regex syntax are accepted.
14 */
15
16 public class REFlags {
17
18 private boolean caseIndependent;
19 private boolean multiLine;
20 private boolean singleLine;
21 private boolean allowWhitespace;
22 private boolean literal;
23 private boolean xpath20;
24 private boolean xpath30;
25 private boolean xsd11;
26 private boolean debug; // flags = ";g"
27 private boolean allowUnknownBlockNames = false; //flags = ";k"
28
29 /**
30 * Create the regular expression flags
31 *
32 * @param flags a string containing zero or more of 'i', 'x', 'm', 's'
33 * @param language one of "XSD10", "XSD11", "XP20", or "XP30" indicating the regular expression dialect.
34 * Also allow combinations, e.g. "XP20/XSD11".
35 */
36 public REFlags(String flags, String language) {
37
38 if (language.equals("XSD10")) {
39 // no action
40 } else if (language.contains("XSD11")) {
41 allowUnknownBlockNames = !language.contains("XP");
42 xsd11 = true;
43 }
44 if (language.contains("XP20")) {
45 xpath20 = true;
46 } else if (language.contains("XP30")) {
47 xpath20 = true;
48 xpath30 = true;
49 }
50
51 int semi = flags.indexOf(';');
52 int endStd = semi >= 0 ? semi : flags.length();
53 for (int i = 0; i < endStd; i++) {
54 char c = flags.charAt(i);
55 switch (c) {
56 case 'i':
57 caseIndependent = true;
58 break;
59 case 'm':
60 multiLine = true;
61 break;
62 case 's':
63 singleLine = true;
64 break;
65 case 'q':
66 literal = true;
67 if (!xpath30) {
68 throw new RESyntaxException("'q' flag requires XPath 3.0 to be enabled");
69 }
70 break;
71 case 'x':
72 allowWhitespace = true;
73 break;
74 default:
75 throw new RESyntaxException("Unrecognized flag '" + c + "'");
76 }
77 }
78 for (int i = semi + 1; i < flags.length(); i++) {
79 char c = flags.charAt(i);
80 switch (c) {
81 case 'g':
82 debug = true;
83 break;
84 case 'k':
85 allowUnknownBlockNames = true;
86 break;
87 case 'K':
88 allowUnknownBlockNames = false;
89 break;
90 }
91 }
92 }
93
94 public boolean isCaseIndependent() {
95 return caseIndependent;
96 }
97
98 public boolean isMultiLine() {
99 return multiLine;
100 }
101
102 public boolean isSingleLine() {
103 return singleLine;
104 }
105
106 public boolean isAllowWhitespace() {
107 return allowWhitespace;
108 }
109
110 public boolean isLiteral() {
111 return literal;
112 }
113
114 public boolean isAllowsXPath20Extensions() {
115 return xpath20;
116 }
117
118 public boolean isAllowsXPath30Extensions() {
119 return xpath30;
120 }
121
122 public boolean isAllowsXSD11Syntax() {
123 return xsd11;
124 }
125
126 public void setDebug(boolean debug) {
127 this.debug = debug;
128 }
129
130 public boolean isDebug() {
131 return debug;
132 }
133
134 public void setAllowUnknownBlockNames(boolean allow) {
135 this.allowUnknownBlockNames = allow;
136 }
137
138 public boolean isAllowUnknownBlockNames() {
139 return allowUnknownBlockNames;
140 }
141
142
143 }