package de.danoeh.antennapod.util;

import java.util.Arrays;

/** Generates valid filenames for a given string. */
public class FileNameGenerator {
	
	private static final char[] ILLEGAL_CHARACTERS = { '/', '\\', '?', '%',
			'*', ':', '|', '"', '<', '>' };
	static {
		Arrays.sort(ILLEGAL_CHARACTERS);
	}
	
	private FileNameGenerator() {

	}

	/**
	 * This method will return a new string that doesn't contain any illegal
	 * characters of the given string.
	 */
	public static String generateFileName(String string) {
		StringBuilder builder = new StringBuilder();
		for (int i = 0; i < string.length(); i++) {
			char c = string.charAt(i);
			if (Arrays.binarySearch(ILLEGAL_CHARACTERS, c) < 0) {
				builder.append(c);
			}
		}
		return builder.toString();
	}

	public static long generateLong(final String str) {
		return str.hashCode();
	}
}

@@ -714,16 +714,40 @@
 ppend(c)
+.replaceFirst(%22  *$%22,%22%22)
 ;%0A%09%09%09%7D%0A%09

Remove trailing spaces in filenames