ApplyCaseFold.java revision 1088:7e62d98d4625
1262685Sdelphij/* 2174993Srafan * Permission is hereby granted, free of charge, to any person obtaining a copy of 3262685Sdelphij * this software and associated documentation files (the "Software"), to deal in 4174993Srafan * the Software without restriction, including without limitation the rights to 5174993Srafan * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 6174993Srafan * of the Software, and to permit persons to whom the Software is furnished to do 7174993Srafan * so, subject to the following conditions: 8174993Srafan * 9174993Srafan * The above copyright notice and this permission notice shall be included in all 10174993Srafan * copies or substantial portions of the Software. 11174993Srafan * 12174993Srafan * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13174993Srafan * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14174993Srafan * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15174993Srafan * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16174993Srafan * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17174993Srafan * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18174993Srafan * SOFTWARE. 19174993Srafan */ 20174993Srafanpackage jdk.nashorn.internal.runtime.regexp.joni; 21174993Srafan 22174993Srafanimport jdk.nashorn.internal.runtime.regexp.joni.ast.CClassNode; 23174993Srafan 24174993Srafanfinal class ApplyCaseFold { 25174993Srafan 26174993Srafan // i_apply_case_fold 27174993Srafan public static void apply(final int from, final int to, final Object o) { 28174993Srafan final ApplyCaseFoldArg arg = (ApplyCaseFoldArg)o; 29174993Srafan 30174993Srafan final ScanEnvironment env = arg.env; 31174993Srafan final CClassNode cc = arg.cc; 32174993Srafan final BitSet bs = cc.bs; 33174993Srafan 34174993Srafan final boolean inCC = cc.isCodeInCC(from); 35174993Srafan 36174993Srafan if (Config.CASE_FOLD_IS_APPLIED_INSIDE_NEGATIVE_CCLASS) { 37174993Srafan if ((inCC && !cc.isNot()) || (!inCC && cc.isNot())) { 38174993Srafan if (to >= BitSet.SINGLE_BYTE_SIZE) { 39174993Srafan cc.addCodeRange(env, to, to); 40174993Srafan } else { 41174993Srafan /* /(?i:[^A-C])/.match("a") ==> fail. */ 42174993Srafan bs.set(to); 43174993Srafan } 44174993Srafan } 45174993Srafan } else { 46174993Srafan if (inCC) { 47174993Srafan if (to >= BitSet.SINGLE_BYTE_SIZE) { 48174993Srafan if (cc.isNot()) { 49174993Srafan cc.clearNotFlag(); 50174993Srafan } 51174993Srafan cc.addCodeRange(env, to, to); 52174993Srafan } else { 53174993Srafan if (cc.isNot()) { 54174993Srafan bs.clear(to); 55174993Srafan } else { 56174993Srafan bs.set(to); 57174993Srafan } 58174993Srafan } 59174993Srafan } 60174993Srafan } // CASE_FOLD_IS_APPLIED_INSIDE_NEGATIVE_CCLASS 61174993Srafan 62174993Srafan } 63174993Srafan 64174993Srafan static final ApplyCaseFold INSTANCE = new ApplyCaseFold(); 65174993Srafan} 66174993Srafan