Java String Sanitize sanitize(String path)

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

Description

Sanitizes path by ensuring that path starts with a slash and doesn't have one at the end

License

Apache License

Parameter

Parameter Description
path a parameter

Declaration

public static String sanitize(String path) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from  www .  ja v  a2  s  .c om*/
     * Sanitizes path by ensuring that path starts with a slash and doesn't have one at the end
     * @param path
     * @return
     */
    public static String sanitize(String path) {
        return withLeadingSlash(withoutSlashAtEnd(path));
    }

    private static String withLeadingSlash(String value) {
        return value.startsWith("/") ? value : "/" + value;
    }

    private static String withoutSlashAtEnd(String value) {
        return value.endsWith("/") ? value.substring(0, value.length() - 1) : value;
    }
}

Related

  1. sanitize(String input)
  2. sanitize(String input, String prohibitedStringsRegexp)
  3. sanitize(String methodHeader)
  4. sanitize(String mimeType)
  5. sanitize(String original)
  6. sanitize(String s)
  7. sanitize(String s)
  8. sanitize(String s)
  9. sanitize(String s, boolean allowColorCodes)