/* * [VSlickRegexReplace.java] * * Summary: Slick Edit Replace 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; /** * Slick Edit Replace 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 VSlickRegexReplace extends Translator { private static final String[] trt; static { // translation table for char to Replace literal string form. trt = new String[ 256 ]; // initialize the table array 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 ); } trt[ 10 ] = "\\n"; trt[ 13 ] = ""/* cr: ignore because \n means either \n or \r\n */; trt[ '\\' ] = "\\\\"/* \ */; } // end static init // instance init. { table = trt; } } // end class