1/* 2 * Permission is hereby granted, free of charge, to any person obtaining a copy of 3 * this software and associated documentation files (the "Software"), to deal in 4 * the Software without restriction, including without limitation the rights to 5 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 6 * of the Software, and to permit persons to whom the Software is furnished to do 7 * so, subject to the following conditions: 8 * 9 * The above copyright notice and this permission notice shall be included in all 10 * copies or substantial portions of the Software. 11 * 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 * SOFTWARE. 19 */ 20package jdk.nashorn.internal.runtime.regexp.joni; 21 22@SuppressWarnings("javadoc") 23public class Option { 24 25 /* options */ 26 public static final int NONE = 0; 27 public static final int IGNORECASE = (1<<0); 28 public static final int EXTEND = (1<<1); 29 public static final int MULTILINE = (1<<2); 30 public static final int SINGLELINE = (1<<3); 31 public static final int FIND_LONGEST = (1<<4); 32 public static final int FIND_NOT_EMPTY = (1<<5); 33 public static final int NEGATE_SINGLELINE = (1<<6); 34 public static final int DONT_CAPTURE_GROUP = (1<<7); 35 public static final int CAPTURE_GROUP = (1<<8); 36 37 /* options (search time) */ 38 public static final int NOTBOL = (1<<9); 39 public static final int NOTEOL = (1<<10); 40 public static final int POSIX_REGION = (1<<11); 41 public static final int MAXBIT = (1<<12); /* limit */ 42 43 public static final int DEFAULT = NONE; 44 45 public static String toString(final int option) { 46 String options = ""; 47 if (isIgnoreCase(option)) { 48 options += "IGNORECASE "; 49 } 50 if (isExtend(option)) { 51 options += "EXTEND "; 52 } 53 if (isMultiline(option)) { 54 options += "MULTILINE "; 55 } 56 if (isSingleline(option)) { 57 options += "SINGLELINE "; 58 } 59 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