Java String Quote quoteImpl(String s, char delim)

Here you can find the source of quoteImpl(String s, char delim)

Description

quote Impl

License

Open Source License

Declaration

private static String quoteImpl(String s, char delim) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012 Firestar Software, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from  w ww  .  jav a 2s.  co  m
 *     Firestar Software, Inc. - initial API and implementation
 *
 * Author:
 *     Gabriel Oancea
 *
 *******************************************************************************/

public class Main {
    private static String quoteImpl(String s, char delim) {
        if (s == null)
            return null;
        StringBuffer sb = new StringBuffer(s.length() + 3); // two delims one
        // magic
        sb.append(delim);
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == delim)
                sb.append(delim);
            sb.append(c);
        }
        sb.append(delim);
        return sb.toString();
    }
}

Related

  1. quoteIfNotNull(String text)
  2. quoteIfNotNull(StringBuilder sb, String val)
  3. quoteIfString(Object obj)
  4. quoteIfString(Object obj)
  5. quoteIfString(Object... arguments)
  6. quoteIt(String orig)
  7. quoteJava(String s)
  8. quoteJavascriptString(String s)
  9. quoteJavaString(String s)