aboutsummaryrefslogtreecommitdiff
path: root/src/jdk/nashorn/internal/runtime/regexp/joni/Option.java
blob: ead990074c7cf42aecd2b85997050381e9cbb72f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is furnished to do
 * so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package jdk.nashorn.internal.runtime.regexp.joni;

@SuppressWarnings("javadoc")
public class Option {

    /* options */
    public static final int NONE                 = 0;
    public static final int IGNORECASE           = (1<<0);
    public static final int EXTEND               = (1<<1);
    public static final int MULTILINE            = (1<<2);
    public static final int SINGLELINE           = (1<<3);
    public static final int FIND_LONGEST         = (1<<4);
    public static final int FIND_NOT_EMPTY       = (1<<5);
    public static final int NEGATE_SINGLELINE    = (1<<6);
    public static final int DONT_CAPTURE_GROUP   = (1<<7);
    public static final int CAPTURE_GROUP        = (1<<8);

    /* options (search time) */
    public static final int NOTBOL               = (1<<9);
    public static final int NOTEOL               = (1<<10);
    public static final int POSIX_REGION         = (1<<11);
    public static final int MAXBIT               = (1<<12); /* limit */

    public static final int DEFAULT              = NONE;

    public static String toString(final int option) {
        String options = "";
        if (isIgnoreCase(option)) {
            options += "IGNORECASE ";
        }
        if (isExtend(option)) {
            options += "EXTEND ";
        }
        if (isMultiline(option)) {
            options += "MULTILINE ";
        }
        if (isSingleline(option)) {
            options += "SINGLELINE ";
        }
        if (isFindLongest(option)) {
            options += "FIND_LONGEST ";
        }
        if (isFindNotEmpty(option)) {
            options += "FIND_NOT_EMPTY  ";
        }
        if (isNegateSingleline(option)) {
            options += "NEGATE_SINGLELINE ";
        }
        if (isDontCaptureGroup(option)) {
            options += "DONT_CAPTURE_GROUP ";
        }
        if (isCaptureGroup(option)) {
            options += "CAPTURE_GROUP ";
        }

        if (isNotBol(option)) {
            options += "NOTBOL ";
        }
        if (isNotEol(option)) {
            options += "NOTEOL ";
        }
        if (isPosixRegion(option)) {
            options += "POSIX_REGION ";
        }

        return options;
    }

    public static boolean isIgnoreCase(final int option) {
        return (option & IGNORECASE) != 0;
    }

    public static boolean isExtend(final int option) {
        return (option & EXTEND) != 0;
    }

    public static boolean isSingleline(final int option) {
        return (option & SINGLELINE) != 0;
    }

    public static boolean isMultiline(final int option) {
        return (option & MULTILINE) != 0;
    }

    public static boolean isFindLongest(final int option) {
        return (option & FIND_LONGEST) != 0;
    }

    public static boolean isFindNotEmpty(final int option) {
        return (option & FIND_NOT_EMPTY) != 0;
    }

    public static boolean isFindCondition(final int option) {
        return (option & (FIND_LONGEST | FIND_NOT_EMPTY)) != 0;
    }

    public static boolean isNegateSingleline(final int option) {
        return (option & NEGATE_SINGLELINE) != 0;
    }

    public static boolean isDontCaptureGroup(final int option) {
        return (option & DONT_CAPTURE_GROUP) != 0;
    }

    public static boolean isCaptureGroup(final int option) {
        return (option & CAPTURE_GROUP) != 0;
    }

    public static boolean isNotBol(final int option) {
        return (option & NOTBOL) != 0;
    }

    public static boolean isNotEol(final int option) {
        return (option & NOTEOL) != 0;
    }

    public static boolean isPosixRegion(final int option) {
        return (option & POSIX_REGION) != 0;
    }

    /* OP_SET_OPTION is required for these options.  ??? */
    //    public static boolean isDynamic(int option) {
    //        return (option & (MULTILINE | IGNORECASE)) != 0;
    //    }
    public static boolean isDynamic(final int option) {
        return false;
    }
}