Added getSuggestedFilename.

This commit is contained in:
Robert Greene 2003-01-26 02:38:30 +00:00
parent fc02bbc6e8
commit 0ce42f9f7e
3 changed files with 37 additions and 0 deletions

View File

@ -627,4 +627,13 @@ public class DosFormatDisk extends FormattedDisk {
public int getLogicalDiskNumber() {
return 0;
}
/**
* Returns a valid filename for the given filename. DOS 3.3
* pretty much allows anything - so it is cut to 30 characters
* and trimmed (trailing whitespace may cause confusion).
*/
public String getSuggestedFilename(String filename) {
return filename.toUpperCase().substring(0, 30).trim();
}
}

View File

@ -335,4 +335,11 @@ public abstract class FormattedDisk extends Disk {
* volumes to distinguish.
*/
public abstract int getLogicalDiskNumber();
/**
* Returns a valid filename for the given filename. This does not
* necessarily guarantee a unique filename - just validity of
* the filename.
*/
public abstract String getSuggestedFilename(String filename);
}

View File

@ -687,4 +687,25 @@ public class ProdosFormatDisk extends FormattedDisk {
public int getLogicalDiskNumber() {
return 0;
}
/**
* Returns a valid filename for the given filename. ProDOS filenames
* have a maximum length of 15 characters, must start with a character
* and may contain characters (A-Z), digits (0-9), or the period (.).
*/
public String getSuggestedFilename(String filename) {
StringBuffer newName = new StringBuffer();
if (!Character.isLetter(filename.charAt(0))) {
newName.append('A');
}
int i=0;
while (newName.length() < 15 && i<filename.length()) {
char ch = filename.charAt(i);
if (Character.isLetterOrDigit(ch) || ch == '.') {
newName.append(ch);
}
i++;
}
return newName.toString().toUpperCase().trim();
}
}