Java String Quote quoteWhitespaces(String path)

Here you can find the source of quoteWhitespaces(String path)

Description

quote Whitespaces

License

Open Source License

Declaration

static public String quoteWhitespaces(String path) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013 Liviu Ionescu.//from  w w  w .j  a  va 2s.  co m
 * 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:
 *     Liviu Ionescu - initial version
 *******************************************************************************/

public class Main {
    static public String quoteWhitespaces(String path) {
        path = path.trim();
        // Escape the spaces in the path/filename if it has any
        String[] segments = path.split("\\s"); //$NON-NLS-1$
        if (segments.length > 1) {
            if (path.startsWith("\"") || path.startsWith("'"))
                return path;

            return "\"" + path + "\"";
        } else {
            return path;
        }
    }
}

Related

  1. quoteTokenize(String clientResponse)
  2. QuoteValue(String str)
  3. quoteValue(String value)
  4. QuoteValueIfNeeded(String str)
  5. quoteValues(String value)
  6. quoteWrap(String name)