Option.java revision 1088:7e62d98d4625
1193323Sed/*
2193323Sed * Permission is hereby granted, free of charge, to any person obtaining a copy of
3193323Sed * this software and associated documentation files (the "Software"), to deal in
4193323Sed * the Software without restriction, including without limitation the rights to
5193323Sed * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
6193323Sed * of the Software, and to permit persons to whom the Software is furnished to do
7193323Sed * so, subject to the following conditions:
8193323Sed *
9193323Sed * The above copyright notice and this permission notice shall be included in all
10193323Sed * copies or substantial portions of the Software.
11193323Sed *
12193323Sed * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13193323Sed * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14202375Srdivacky * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15202375Srdivacky * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16193323Sed * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17193323Sed * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18193323Sed * SOFTWARE.
19202375Srdivacky */
20202375Srdivackypackage jdk.nashorn.internal.runtime.regexp.joni;
21202375Srdivacky
22202375Srdivacky@SuppressWarnings("javadoc")
23202375Srdivackypublic class Option {
24202375Srdivacky
25202375Srdivacky    /* options */
26202375Srdivacky    public static final int NONE                 = 0;
27202375Srdivacky    public static final int IGNORECASE           = (1<<0);
28202375Srdivacky    public static final int EXTEND               = (1<<1);
29202375Srdivacky    public static final int MULTILINE            = (1<<2);
30202375Srdivacky    public static final int SINGLELINE           = (1<<3);
31202375Srdivacky    public static final int FIND_LONGEST         = (1<<4);
32193323Sed    public static final int FIND_NOT_EMPTY       = (1<<5);
33193323Sed    public static final int NEGATE_SINGLELINE    = (1<<6);
34193323Sed    public static final int DONT_CAPTURE_GROUP   = (1<<7);
35193323Sed    public static final int CAPTURE_GROUP        = (1<<8);
36202375Srdivacky
37202375Srdivacky    /* options (search time) */
38202375Srdivacky    public static final int NOTBOL               = (1<<9);
39202375Srdivacky    public static final int NOTEOL               = (1<<10);
40193323Sed    public static final int POSIX_REGION         = (1<<11);
41202375Srdivacky    public static final int MAXBIT               = (1<<12); /* limit */
42193323Sed
43202375Srdivacky    public static final int DEFAULT              = NONE;
44202375Srdivacky
45193323Sed    public static String toString(final int option) {
46202878Srdivacky        String options = "";
47193323Sed        if (isIgnoreCase(option)) {
48193323Sed            options += "IGNORECASE ";
49193323Sed        }
50193323Sed        if (isExtend(option)) {
51202375Srdivacky            options += "EXTEND ";
52202375Srdivacky        }
53202375Srdivacky        if (isMultiline(option)) {
54226633Sdim            options += "MULTILINE ";
55226633Sdim        }
56226633Sdim        if (isSingleline(option)) {
57226633Sdim            options += "SINGLELINE ";
58193323Sed        }
59193323Sed        if (isFindLongest(option)) {
60            options += "FIND_LONGEST ";
61        }
62        if (isFindNotEmpty(option)) {
63            options += "FIND_NOT_EMPTY  ";
64        }
65        if (isNegateSingleline(option)) {
66            options += "NEGATE_SINGLELINE ";
67        }
68        if (isDontCaptureGroup(option)) {
69            options += "DONT_CAPTURE_GROUP ";
70        }
71        if (isCaptureGroup(option)) {
72            options += "CAPTURE_GROUP ";
73        }
74
75        if (isNotBol(option)) {
76            options += "NOTBOL ";
77        }
78        if (isNotEol(option)) {
79            options += "NOTEOL ";
80        }
81        if (isPosixRegion(option)) {
82            options += "POSIX_REGION ";
83        }
84
85        return options;
86    }
87
88    public static boolean isIgnoreCase(final int option) {
89        return (option & IGNORECASE) != 0;
90    }
91
92    public static boolean isExtend(final int option) {
93        return (option & EXTEND) != 0;
94    }
95
96    public static boolean isSingleline(final int option) {
97        return (option & SINGLELINE) != 0;
98    }
99
100    public static boolean isMultiline(final int option) {
101        return (option & MULTILINE) != 0;
102    }
103
104    public static boolean isFindLongest(final int option) {
105        return (option & FIND_LONGEST) != 0;
106    }
107
108    public static boolean isFindNotEmpty(final int option) {
109        return (option & FIND_NOT_EMPTY) != 0;
110    }
111
112    public static boolean isFindCondition(final int option) {
113        return (option & (FIND_LONGEST | FIND_NOT_EMPTY)) != 0;
114    }
115
116    public static boolean isNegateSingleline(final int option) {
117        return (option & NEGATE_SINGLELINE) != 0;
118    }
119
120    public static boolean isDontCaptureGroup(final int option) {
121        return (option & DONT_CAPTURE_GROUP) != 0;
122    }
123
124    public static boolean isCaptureGroup(final int option) {
125        return (option & CAPTURE_GROUP) != 0;
126    }
127
128    public static boolean isNotBol(final int option) {
129        return (option & NOTBOL) != 0;
130    }
131
132    public static boolean isNotEol(final int option) {
133        return (option & NOTEOL) != 0;
134    }
135
136    public static boolean isPosixRegion(final int option) {
137        return (option & POSIX_REGION) != 0;
138    }
139
140    /* OP_SET_OPTION is required for these options.  ??? */
141    //    public static boolean isDynamic(int option) {
142    //        return (option & (MULTILINE | IGNORECASE)) != 0;
143    //    }
144    public static boolean isDynamic(final int option) {
145        return false;
146    }
147}
148