Java String Quote quote(final String value)

Here you can find the source of quote(final String value)

Description

quote

License

CDDL license

Declaration

public static String quote(final String value) 

Method Source Code

//package com.java2s;
/*/*from   www .  j  ava 2  s .c o  m*/
 * The contents of this file are subject to the terms of the Common Development and
 * Distribution License (the License). You may not use this file except in compliance with the
 * License.
 *
 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
 * specific language governing permission and limitations under the License.
 *
 * When distributing Covered Software, include this CDDL Header Notice in each file and include
 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2010?2011 ApexIdentity Inc.
 * Portions Copyright 2011-2014 ForgeRock AS.
 */

public class Main {

    public static String quote(final String value) {
        if (value == null) {
            return null;
        }
        final StringBuilder sb = new StringBuilder("\"");
        int length = value.length();
        for (int n = 0, cp; n < length; n += Character.charCount(cp)) {
            cp = value.codePointAt(n);
            if (cp == '\\' || cp == '"') {
                sb.append('\\');
            }
            sb.appendCodePoint(cp);
        }
        sb.append('"');
        return sb.toString();
    }
}

Related

  1. quote(final String str)
  2. quote(final String str)
  3. quote(final String sValue)
  4. quote(final String value)
  5. quote(final String value)
  6. quote(Object aObject)
  7. quote(Object s)
  8. quote(Object s)
  9. quote(Object value)