Java String Quote quoteRemarkSQL(String sql)

Here you can find the source of quoteRemarkSQL(String sql)

Description

In a string, replace block comment marks with /++ ..

License

Open Source License

Parameter

Parameter Description
sql the string

Return

the resulting string

Declaration

public static String quoteRemarkSQL(String sql) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from ww  w.j ava  2  s  .c  om*/
     * In a string, replace block comment marks with /++ .. ++/.
     *
     * @param sql the string
     * @return the resulting string
     */
    public static String quoteRemarkSQL(String sql) {
        sql = replaceAll(sql, "*/", "++/");
        return replaceAll(sql, "/*", "/++");
    }

    /**
     * Replace all occurrences of the before string with the after string.
     *
     * @param s the string
     * @param before the old text
     * @param after the new text
     * @return the string with the before string replaced
     */
    public static String replaceAll(String s, String before, String after) {
        int next = s.indexOf(before);
        if (next < 0) {
            return s;
        }
        StringBuilder buff = new StringBuilder(s.length() - before.length() + after.length());
        int index = 0;
        while (true) {
            buff.append(s.substring(index, next)).append(after);
            index = next + before.length();
            next = s.indexOf(before, index);
            if (next < 0) {
                buff.append(s.substring(index));
                break;
            }
        }
        return buff.toString();
    }
}

Related

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