Option.java revision 953:221a84ef44c0
1219019Sgabor/*
2219019Sgabor * Permission is hereby granted, free of charge, to any person obtaining a copy of
3219019Sgabor * this software and associated documentation files (the "Software"), to deal in
4219019Sgabor * the Software without restriction, including without limitation the rights to
5219019Sgabor * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
6219019Sgabor * of the Software, and to permit persons to whom the Software is furnished to do
7219019Sgabor * so, subject to the following conditions:
8219019Sgabor *
9219019Sgabor * The above copyright notice and this permission notice shall be included in all
10219019Sgabor * copies or substantial portions of the Software.
11219019Sgabor *
12219019Sgabor * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13219019Sgabor * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14219019Sgabor * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15219019Sgabor * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16219019Sgabor * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17219019Sgabor * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18219019Sgabor * SOFTWARE.
19219019Sgabor */
20219019Sgaborpackage jdk.nashorn.internal.runtime.regexp.joni;
21219019Sgabor
22219019Sgaborpublic class Option {
23219019Sgabor
24219019Sgabor    /* options */
25219019Sgabor    public static final int NONE                 = 0;
26219019Sgabor    public static final int IGNORECASE           = (1<<0);
27219019Sgabor    public static final int EXTEND               = (1<<1);
28219019Sgabor    public static final int MULTILINE            = (1<<2);
29219019Sgabor    public static final int SINGLELINE           = (1<<3);
30219019Sgabor    public static final int FIND_LONGEST         = (1<<4);
31219019Sgabor    public static final int FIND_NOT_EMPTY       = (1<<5);
32219019Sgabor    public static final int NEGATE_SINGLELINE    = (1<<6);
33219019Sgabor    public static final int DONT_CAPTURE_GROUP   = (1<<7);
34219019Sgabor    public static final int CAPTURE_GROUP        = (1<<8);
35219019Sgabor
36219019Sgabor    /* options (search time) */
37219019Sgabor    public static final int NOTBOL               = (1<<9);
38219019Sgabor    public static final int NOTEOL               = (1<<10);
39219019Sgabor    public static final int POSIX_REGION         = (1<<11);
40219019Sgabor    public static final int MAXBIT               = (1<<12); /* limit */
41219019Sgabor
42219019Sgabor    public static final int DEFAULT              = NONE;
43219019Sgabor
44219019Sgabor    public static String toString(final int option) {
45219019Sgabor        String options = "";
46219019Sgabor        if (isIgnoreCase(option)) options += "IGNORECASE ";
47219019Sgabor        if (isExtend(option)) options += "EXTEND ";
48219019Sgabor        if (isMultiline(option)) options += "MULTILINE ";
49219019Sgabor        if (isSingleline(option)) options += "SINGLELINE ";
50219019Sgabor        if (isFindLongest(option)) options += "FIND_LONGEST ";
51219019Sgabor        if (isFindNotEmpty(option)) options += "FIND_NOT_EMPTY  ";
52219019Sgabor        if (isNegateSingleline(option)) options += "NEGATE_SINGLELINE ";
53219019Sgabor        if (isDontCaptureGroup(option)) options += "DONT_CAPTURE_GROUP ";
54219019Sgabor        if (isCaptureGroup(option)) options += "CAPTURE_GROUP ";
55219019Sgabor
56219019Sgabor        if (isNotBol(option)) options += "NOTBOL ";
57219019Sgabor        if (isNotEol(option)) options += "NOTEOL ";
58219019Sgabor        if (isPosixRegion(option)) options += "POSIX_REGION ";
59219019Sgabor
60219019Sgabor        return options;
61219019Sgabor    }
62219019Sgabor
63219019Sgabor    public static boolean isIgnoreCase(final int option) {
64219019Sgabor        return (option & IGNORECASE) != 0;
65219019Sgabor    }
66219019Sgabor
67219019Sgabor    public static boolean isExtend(final int option) {
68219019Sgabor        return (option & EXTEND) != 0;
69219019Sgabor    }
70219019Sgabor
71219019Sgabor    public static boolean isSingleline(final int option) {
72219019Sgabor        return (option & SINGLELINE) != 0;
73219019Sgabor    }
74219019Sgabor
75219019Sgabor    public static boolean isMultiline(final int option) {
76219019Sgabor        return (option & MULTILINE) != 0;
77219019Sgabor    }
78219019Sgabor
79219019Sgabor    public static boolean isFindLongest(final int option) {
80219019Sgabor        return (option & FIND_LONGEST) != 0;
81219019Sgabor    }
82219019Sgabor
83219019Sgabor    public static boolean isFindNotEmpty(final int option) {
84219019Sgabor        return (option & FIND_NOT_EMPTY) != 0;
85219019Sgabor    }
86219019Sgabor
87219019Sgabor    public static boolean isFindCondition(final int option) {
88219019Sgabor        return (option & (FIND_LONGEST | FIND_NOT_EMPTY)) != 0;
89219019Sgabor    }
90219019Sgabor
91219019Sgabor    public static boolean isNegateSingleline(final int option) {
92219019Sgabor        return (option & NEGATE_SINGLELINE) != 0;
93219019Sgabor    }
94219019Sgabor
95219019Sgabor    public static boolean isDontCaptureGroup(final int option) {
96219019Sgabor        return (option & DONT_CAPTURE_GROUP) != 0;
97219019Sgabor    }
98219019Sgabor
99219019Sgabor    public static boolean isCaptureGroup(final int option) {
100219019Sgabor        return (option & CAPTURE_GROUP) != 0;
101219019Sgabor    }
102219019Sgabor
103219019Sgabor    public static boolean isNotBol(final int option) {
104219019Sgabor        return (option & NOTBOL) != 0;
105219019Sgabor    }
106219019Sgabor
107219019Sgabor    public static boolean isNotEol(final int option) {
108219019Sgabor        return (option & NOTEOL) != 0;
109219019Sgabor    }
110219019Sgabor
111219019Sgabor    public static boolean isPosixRegion(final int option) {
112219019Sgabor        return (option & POSIX_REGION) != 0;
113219019Sgabor    }
114219019Sgabor
115219019Sgabor    /* OP_SET_OPTION is required for these options.  ??? */
116219019Sgabor    //    public static boolean isDynamic(int option) {
117219019Sgabor    //        return (option & (MULTILINE | IGNORECASE)) != 0;
118219019Sgabor    //    }
119219019Sgabor    public static boolean isDynamic(final int option) {
120219019Sgabor        return false;
121219019Sgabor    }
122219019Sgabor}
123219019Sgabor