Java String Sanitize sanitize(char orig)

Here you can find the source of sanitize(char orig)

Description

sanitize

License

Apache License

Declaration

static String sanitize(char orig) 

Method Source Code

//package com.java2s;
/*/*from   w  w w.j  av  a 2  s .  c o m*/
 * Copyright 2011 vvakame <vvakame@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    static String sanitize(char orig) {
        return sanitize(String.valueOf(orig));
    }

    static String sanitize(String orig) {
        if (orig == null) {
            return null;
        }
        // TODO Increase Process Speed
        return orig.replace("\\", "\\\\").replace("\"", "\\\"").replace("/", "\\/").replace("\b", "\\b")
                .replace("\f", "\\f").replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t");
    }
}

Related

  1. sanitize(CharSequence string)
  2. sanitize(double[] outdata)
  3. sanitize(final String main)
  4. sanitize(final String name)