Java String Sanitize sanitizeSingleQuotesInAlbumItemValues(String value)

Here you can find the source of sanitizeSingleQuotesInAlbumItemValues(String value)

Description

Transforms a value of an album Item and escapes single quotes.

License

Open Source License

Parameter

Parameter Description
value The value which must not be enclosed in single quotes.

Return

A string with the specified value which has the quotes escaped for further processing. Typically used in a raw SELECT statement.

Declaration

public static String sanitizeSingleQuotesInAlbumItemValues(String value) 

Method Source Code

//package com.java2s;
/** -----------------------------------------------------------------
 *    Sammelbox: Collection Manager - A free and open-source collection manager for Windows & Linux
 *    Copyright (C) 2011 Jerome Wagener & Paul Bicheler
 *
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ** ----------------------------------------------------------------- */

public class Main {
    /**//from ww w  .  j av  a2  s.  c  o  m
     * Transforms a value of an album Item and escapes single quotes.
     * @param value The value which must not be enclosed in single quotes.
     * @return A string with the specified value which has the quotes escaped for further processing. Typically used in a 
     * raw SELECT statement.
     */
    public static String sanitizeSingleQuotesInAlbumItemValues(String value) {
        int lastIndex = 0;
        int singleQuoteIndex = value.indexOf('\'', 0);
        StringBuilder sb = new StringBuilder();
        while (singleQuoteIndex != -1) {
            sb.append(value.substring(lastIndex, singleQuoteIndex));
            sb.append("''");
            lastIndex = singleQuoteIndex + 1;
            singleQuoteIndex = value.indexOf('\'', singleQuoteIndex + 1);
        }
        if (lastIndex > -1) {
            sb.append(value.substring(lastIndex));
        }
        return sb.toString();
    }
}

Related

  1. sanitizeProcOrFuncName(String src)
  2. sanitizeProjectName(final String projectName)
  3. sanitizeRefName(String refName)
  4. sanitizeResource(String resource)
  5. sanitizeSAMHeader(String samString)
  6. sanitizeString(final String s)
  7. sanitizeString(String dirtyString)
  8. sanitizeString(String input)
  9. sanitizeString(String s)