/* * [VSlickRegexSearch.java] * * Summary: Funduc Search strings reserve chars for regex use. * * Copyright: (c) 2002-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 4.5 2009-02-26 add both Java string quoting and plain for Java search/regexes. */ package com.mindprod.quoter; /** * Funduc Search strings reserve chars for regex use. *
* These must be quoted with a leading \. - + * ? ( ) [ ] \ | $ ^ ! * * @author Roedy Green, Canadian Mind Products * @version 4.5 2009-02-26 add both Java string quoting and plain for Java search/regexes. * @since 2002-06-19 */ final class VSlickRegexSearch extends Translator { private static final String[] trt; static { // initialize the table array trt = new String[ 256 ]; for ( int i = 0; i < 32; i++ ) { // to hex \0xhh trt[ i ] = "\\0x" + Integer.toHexString( i + 0x100 ).substring( 1, 3 ); } for ( int i = 32; i < 127; i++ ) { // leave char unmolested. trt[ i ] = String.valueOf( ( char ) i ).intern(); } for ( int i = 127; i < 256; i++ ) { // to hex \0xhh trt[ i ] = "\\0x" + Integer.toHexString( i + 0x100 ).substring( 1, 3 ); } // override with chars that have special VSlick search representations // * + . ? \ { | } trt[ 10 ] = "\\n"; trt[ 13 ] = ""/* cr: ignore because \n means either \n or \r\n */; trt[ '*' ] = "\\*"/* * */; trt[ '+' ] = "\\+"/* + */; trt[ '.' ] = "\\."/* ! */; trt[ '?' ] = "\\?"/* ? */; trt[ '\\' ] = "\\\\"/* \ */; trt[ '{' ] = "\\{"/* ( */; trt[ '|' ] = "\\|"/* | */; trt[ '}' ] = "\\}"/* ) */; } // end static init // instance init. { table = trt; } } // end class