Here you can find the source of normalize(String pathname, int len, int off)
public static String normalize(String pathname, int len, int off)
//package com.java2s; /*/*from www .ja v a 2 s .c o m*/ * Copyright 2010-2012 the original author or authors. * * 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 { public static String normalize(String pathname, int len, int off) { if (len == 0) return pathname; int n = len; while ((n > 0) && (pathname.charAt(n - 1) == '/')) n--; if (n == 0) return "/"; StringBuilder sb = new StringBuilder(pathname.length()); if (off > 0) sb.append(pathname.substring(0, off)); char prevChar = 0; for (int i = off; i < n; i++) { char c = pathname.charAt(i); if ((prevChar == '/') && (c == '/')) continue; sb.append(c); prevChar = c; } return sb.toString(); } public static String normalize(String pathname) { int n = pathname.length(); char prevChar = 0; for (int i = 0; i < n; i++) { char c = pathname.charAt(i); if ((prevChar == '/') && (c == '/')) return normalize(pathname, n, i - 1); prevChar = c; } if (prevChar == '/') return normalize(pathname, n, n - 1); return pathname; } }