Option.java revision 953:221a84ef44c0
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 22public class Option { 23 24 /* options */ 25 public static final int NONE = 0; 26 public static final int IGNORECASE = (1<<0); 27 public static final int EXTEND = (1<<1); 28 public static final int MULTILINE = (1<<2); 29 public static final int SINGLELINE = (1<<3); 30 public static final int FIND_LONGEST = (1<<4); 31 public static final int FIND_NOT_EMPTY = (1<<5); 32 public static final int NEGATE_SINGLELINE = (1<<6); 33 public static final int DONT_CAPTURE_GROUP = (1<<7); 34 public static final int CAPTURE_GROUP = (1<<8); 35 36 /* options (search time) */ 37 public static final int NOTBOL = (1<<9); 38 public static final int NOTEOL = (1<<10); 39 public static final int POSIX_REGION = (1<<11); 40 public static final int MAXBIT = (1<<12); /* limit */ 41 42 public static final int DEFAULT = NONE; 43 44 public static String toString(final int option) { 45 String options = ""; 46 if (isIgnoreCase(option)) options += "IGNORECASE "; 47 if (isExtend(option)) options += "EXTEND "; 48 if (isMultiline(option)) options += "MULTILINE "; 49 if (isSingleline(option)) options += "SINGLELINE "; 50 if (isFindLongest(option)) options += "FIND_LONGEST "; 51 if (isFindNotEmpty(option)) options += "FIND_NOT_EMPTY "; 52 if (isNegateSingleline(option)) options += "NEGATE_SINGLELINE "; 53 if (isDontCaptureGroup(option)) options += "DONT_CAPTURE_GROUP "; 54 if (isCaptureGroup(option)) options += "CAPTURE_GROUP "; 55 56 if (isNotBol(option)) options += "NOTBOL "; 57 if (isNotEol(option)) options += "NOTEOL "; 58 if (isPosixRegion(option)) options += "POSIX_REGION "; 59 60 return options; 61 } 62 63 public static boolean isIgnoreCase(final int option) { 64 return (option & IGNORECASE) != 0; 65 } 66 67 public static boolean isExtend(final int option) { 68 return (option & EXTEND) != 0; 69 } 70 71 public static boolean isSingleline(final int option) { 72 return (option & SINGLELINE) != 0; 73 } 74 75 public static boolean isMultiline(final int option) { 76 return (option & MULTILINE) != 0; 77 } 78 79 public static boolean isFindLongest(final int option) { 80 return (option & FIND_LONGEST) != 0; 81 } 82 83 public static boolean isFindNotEmpty(final int option) { 84 return (option & FIND_NOT_EMPTY) != 0; 85 } 86 87 public static boolean isFindCondition(final int option) { 88 return (option & (FIND_LONGEST | FIND_NOT_EMPTY)) != 0; 89 } 90 91 public static boolean isNegateSingleline(final int option) { 92 return (option & NEGATE_SINGLELINE) != 0; 93 } 94 95 public static boolean isDontCaptureGroup(final int option) { 96 return (option & DONT_CAPTURE_GROUP) != 0; 97 } 98 99 public static boolean isCaptureGroup(final int option) { 100 return (option & CAPTURE_GROUP) != 0; 101 } 102 103 public static boolean isNotBol(final int option) { 104 return (option & NOTBOL) != 0; 105 } 106 107 public static boolean isNotEol(final int option) { 108 return (option & NOTEOL) != 0; 109 } 110 111 public static boolean isPosixRegion(final int option) { 112 return (option & POSIX_REGION) != 0; 113 } 114 115 /* OP_SET_OPTION is required for these options. ??? */ 116 // public static boolean isDynamic(int option) { 117 // return (option & (MULTILINE | IGNORECASE)) != 0; 118 // } 119 public static boolean isDynamic(final int option) { 120 return false; 121 } 122} 123