Java String Chop chopScheme(String path)

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

Description

Chops the scheme/protocol from the given URL path and returns the path without the scheme.

License

Open Source License

Parameter

Parameter Description
path a URL path.

Return

the path without the scheme, or the given path, if it has no scheme.

Declaration

public static String chopScheme(String path) 

Method Source Code

//package com.java2s;
/**// ww w  .  j  a v  a  2s . com
 * This class holds various utility methods.
 * 
 * @author Yanick Duchesne
 *         <dl>
 *         <dt><b>Copyright: </b>
 *         <dd>Copyright &#169; 2002-2007 <a
 *         href="http://www.sapia-oss.org">Sapia Open Source Software </a>. All
 *         Rights Reserved.</dd>
 *         </dt>
 *         <dt><b>License: </b>
 *         <dd>Read the license.txt file of the jar or visit the <a
 *         href="http://www.sapia-oss.org/license.html">license page </a> at the
 *         Sapia OSS web site</dd>
 *         </dt>
 *         </dl>
 */

public class Main {
    /**
     * Chops the scheme/protocol from the given URL path and returns the path
     * without the scheme.
     * 
     * @param path
     *          a URL path.
     * @return the path without the scheme, or the given path, if it has no
     *         scheme.
     */
    public static String chopScheme(String path) {
        int idx = path.indexOf(":");

        if (idx >= 0) {
            if (path.length() >= 2) {
                if (path.charAt(1) == ':') {
                    if (Character.isLetter(path.charAt(0))) {
                        return path;
                    }
                }
            }
            String toReturn = path.substring(idx + 1);
            if (toReturn.startsWith("//")) {
                toReturn = toReturn.substring(1);
            }
            return toReturn;
        }

        return path;
    }

    private static boolean startsWith(String comparee, char comparant) {
        if (comparee.length() == 0)
            return false;
        return comparee.charAt(0) == comparant;
    }
}

Related

  1. chopLongLinesAtSpaces(int maxLineLenght, String text)
  2. chopNull(String str)
  3. chopPrefix(String x, String prefix)
  4. ChopRt(String this_string, String chomp_off)
  5. chopScheme(String path)
  6. chopString(String argString, int argLength)
  7. chopString(String str, int len)
  8. chopString(String title, int maxLen)
  9. chopToNSignificantDigits(final float original, int no_of_sig_digits)