/* * [FunducRegexReplace.java] * * Summary: Funduc 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; /** * Funduc 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 FunducRegexReplace 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 ); } // override with chars that have special Funduc replace representations // % \ < > must be preceded by \ trt[ 7 ] = "\\a"; trt[ 8 ] = "\\b";/* Backspace character */ trt[ 9 ] = "\\t";/* TAB */ trt[ 10 ] = "\\r\\n";/* * Line Feed clipboard strips cr in crlf, * replace it */ trt[ 11 ] = "\\v";/* Vertical TAB */ trt[ 12 ] = "\\f";/* Form Feed */ trt[ 13 ] = "\\r";/* cr */ trt[ '%' ] = "\\%";/* % */ trt[ '<' ] = "\\<";/* < */ trt[ '>' ] = "\\>";/* > */ trt[ '\\' ] = "\\\\";/* \ */ } // end static init // instance init. { table = trt; } }