Code cleanup

Fixes some lines which were too long
Expands some variable names
Fixes some code repetition
This commit is contained in:
Kristian Knarvik 2020-04-06 20:46:11 +02:00
parent 57138ddd1a
commit 156676cf56
2 changed files with 31 additions and 15 deletions

View File

@ -27,7 +27,8 @@ public class Main {
//parser(tokenizer("AnimeConverter \"C:\\Users\\Kristian\\Downloads\\Anime\\[Kametsu] ERASED (BD 1080p Hi10 FLAC)\"")); //parser(tokenizer("AnimeConverter \"C:\\Users\\Kristian\\Downloads\\Anime\\[Kametsu] ERASED (BD 1080p Hi10 FLAC)\""));
//System.exit(1); //System.exit(1);
int choice = getChoice("Which converter do you want do use?\n1. Anime to web mp4\n2. Audio converter\n3. VideoStream converter", 1, 3); int choice = getChoice("Which converter do you want do use?\n1. Anime to web mp4\n2. Audio converter\n" +
"3. VideoStream converter", 1, 3);
printl("Input for this converter:"); printl("Input for this converter:");
switch (choice) { switch (choice) {
@ -144,7 +145,8 @@ public class Main {
* @throws IOException <p>If reading or writing fails.</p> * @throws IOException <p>If reading or writing fails.</p>
*/ */
private static void animeConverter() throws IOException { private static void animeConverter() throws IOException {
printl("[Audio languages jpn,eng,ger,fre] [Subtitle languages eng,ger,fre] [Convert to stereo if necessary true/false] [Prevent signs&songs subtitles true/false]\nYour input: "); printl("[Audio languages jpn,eng,ger,fre] [Subtitle languages eng,ger,fre] [Convert to stereo if " +
"necessary true/false] [Prevent signs&songs subtitles true/false]\nYour input: ");
List<String> input = readInput(4); List<String> input = readInput(4);
String[] audioLang = new String[]{"jpn", "*"}; String[] audioLang = new String[]{"jpn", "*"};
String[] subtitleLang = new String[]{"eng", "*"}; String[] subtitleLang = new String[]{"eng", "*"};

View File

@ -18,10 +18,12 @@ public class Parser {
}; };
Main.converterArgument[] audioArgs = { Main.converterArgument[] audioArgs = {
new Main.converterArgument("-outext", true, Main.converterArgumentValueType.SINGLE_VALUE) new Main.converterArgument("-outext", true,
Main.converterArgumentValueType.SINGLE_VALUE)
}; };
Main.converterArgument[] videoArgs = { Main.converterArgument[] videoArgs = {
new Main.converterArgument("-outext", true, Main.converterArgumentValueType.SINGLE_VALUE) new Main.converterArgument("-outext", true,
Main.converterArgumentValueType.SINGLE_VALUE)
}; };
String type = tokens.get(0).toLowerCase(); String type = tokens.get(0).toLowerCase();
if (!Main.listContains(types, s -> s.equals(type))) { if (!Main.listContains(types, s -> s.equals(type))) {
@ -46,39 +48,51 @@ public class Parser {
boolean startedQuote = false; boolean startedQuote = false;
StringBuilder currentToken = new StringBuilder(); StringBuilder currentToken = new StringBuilder();
for (int i = 0; i < input.length(); i++) { for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i); char character = input.charAt(i);
switch (c) { switch (character) {
case ' ': case ' ':
if (!startedQuote) { if (!startedQuote) {
//If not inside "", a space marks the end of a parameter //If not inside "", a space marks the end of a parameter
if (!currentToken.toString().trim().equals("")) { if (isNotEmpty(currentToken)) {
tokens.add(currentToken.toString()); tokens.add(currentToken.toString());
currentToken = new StringBuilder();
} else {
currentToken = new StringBuilder();
} }
currentToken = new StringBuilder();
} else { } else {
currentToken.append(c); currentToken.append(character);
} }
break; break;
case '"': case '"':
if (startedQuote) { if (startedQuote) {
if (!currentToken.toString().trim().equals("")) { //This quote signifies the end of the argument
if (isNotEmpty(currentToken)) {
tokens.add(currentToken.toString()); tokens.add(currentToken.toString());
currentToken = new StringBuilder(); currentToken = new StringBuilder();
} }
startedQuote = false; startedQuote = false;
} else { } else {
//This quote signifies the start of the argument
startedQuote = true; startedQuote = true;
currentToken = new StringBuilder(); currentToken = new StringBuilder();
} break; }
break;
default: default:
currentToken.append(c); //Adds a normal character to the token. Adds the current token to tokens if at the end of the input.
currentToken.append(character);
if (i == input.length() - 1) { if (i == input.length() - 1) {
tokens.add(currentToken.toString()); tokens.add(currentToken.toString());
} break; }
break;
} }
} }
return tokens; return tokens;
} }
/**
* Checks whether a string builder is empty
* @param builder <p>The string builder to check.</p>
* @return <p>True if the string builder is non empty.</p>
*/
private static boolean isNotEmpty(StringBuilder builder) {
return !builder.toString().trim().equals("");
}
} }