/** * Mad-Advertisement * Copyright (C) 2011 Thorsten Marx <thmarx@gmx.net> * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see <http://www.gnu.org/licenses/>. */ package net.mad.ads.common.util; import java.util.ArrayList; import java.util.List; public class Strings { /** * @param str * string to inspect * @return true if string is null or empty */ public static boolean isEmpty(String str) { return (str == null || str.length() == 0); } /** * @param str * string to inspect * @return true if string is null or empty or blank (i.e. whitespace only) */ public static boolean isBlank(String str) { return (str == null || str.trim().length() == 0); } /** * Removes to file extension * @param s * @return */ public static String removeExtension(String s) { String separator = System.getProperty("file.separator"); String filename; // Remove the path upto the filename. int lastSeparatorIndex = s.lastIndexOf(separator); if (lastSeparatorIndex == -1) { filename = s; } else { filename = s.substring(lastSeparatorIndex + 1); } // Remove the extension. int extensionIndex = filename.lastIndexOf("."); if (extensionIndex == -1) return filename; return filename.substring(0, extensionIndex); } public static String removeParamFromURL(String url, String param){ url = url.replaceAll("\\?" + param + "=[^&]*&?","?"); url = url.replaceAll("\\&" + param + "=[^&]*&?","&"); url = url.replace("/(\\?|&)$/",""); return url; } }