Java tutorial
//package com.java2s; /* * Copyright (c) 2010 Inside Secure, All Rights Reserved. * * 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 { /** * Normalizes an absolute URI (lower scheme and host part) * * @param pString The absolute URI to be normalized */ /* package protected */static String normalizeAbsoluteURI(String pString) { int index = -1; /* lower the scheme part */ if ((index = pString.indexOf(':')) == -1) { return pString; } String scheme = pString.substring(0, index); pString = pString.replaceFirst(scheme, scheme.toLowerCase()); /* check the presence of "//" */ if ((index = pString.indexOf("//", index)) == -1) { /* no // found, return */ return pString; } /* lower the host part ( authority : [user@]host[:port] )*/ index += 2; int indexStart = pString.indexOf("@", index); indexStart = (indexStart == -1) ? index : indexStart + 1; int indexEnd = pString.indexOf(indexStart, ':'); if (indexEnd == -1) { if ((indexEnd = pString.indexOf("/", indexStart)) == -1) { indexEnd = pString.length(); } } String host = pString.substring(indexStart, indexEnd); return pString.replaceFirst(host, host.toLowerCase()); } }