Java String Quote quoteReplacement(String s)

Here you can find the source of quoteReplacement(String s)

Description

quote Replacement

License

Open Source License

Declaration

public static String quoteReplacement(String s) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004 Andrei Loskutov.//from ww  w.  ja va  2s  .  c  o  m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the BSD License
 * which accompanies this distribution, and is available at
 * http://www.opensource.org/licenses/bsd-license.php
 * Contributor:  Andrei Loskutov - initial API and implementation
 *******************************************************************************/

public class Main {
    public static String quoteReplacement(String s) {
        if (s.indexOf('\\') == -1 && s.indexOf('$') == -1) {
            return s;
        }
        int length = s.length();
        StringBuffer sb = new StringBuffer(length + 10);
        for (int i = 0; i < length; i++) {
            char c = s.charAt(i);
            if (c == '\\') {
                sb.append('\\').append('\\');
            } else if (c == '$') {
                sb.append('\\').append('$');
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }

    public static int indexOf(String line, char c, int startOffset, int stopOffset, boolean forward) {
        int i = startOffset;
        while (forward ? i < stopOffset : i > stopOffset) {
            if (line.charAt(i) == c) {
                return i;
            }
            if (forward) {
                i++;
            } else {
                i--;
            }
        }
        return -1;
    }
}

Related

  1. quoteReference(final String reference)
  2. quoteRegexMeta(final String input)
  3. quoteRegexMeta(String str)
  4. quoteRemarkSQL(String sql)
  5. quoteRemarkSQL(String sql)
  6. quoteReplacement(String s)
  7. quotes(CharSequence stringToQuote)
  8. quotes(CharSequence stringToQuote, boolean escapeQuote)
  9. quotes(String str)