TextLogik sync and Text updated

This commit is contained in:
Andrin Fassbind 2021-11-11 15:28:41 +01:00
parent 117420c815
commit d51da11751
3 changed files with 14 additions and 9 deletions

View File

@ -39,7 +39,7 @@ public class Text {
* @return returns true if the paragraph is added successfully
*/
public boolean add(String text) {
this.text.add(text);
this.text.add(text.replaceAll("[^A-Za-z0-9 .,:?!\"'-]",""));
return true;
}
@ -168,7 +168,7 @@ public class Text {
String firstLetter;
String restLetters;
for (int i = 0; i < text.size(); i++) {
String[] words = text.get(i).trim().toLowerCase().split("[ :;.,!?><'/\n]+");
String[] words = text.get(i).trim().toLowerCase().split("[ :;.,!?><+*}{)('/\n]+");
for (String word : words) {
//Words get formatted consistently
counter = 1;

View File

@ -12,11 +12,16 @@ public class TextLogik {
textOutput = new TextOutput();
String[] command;
textOutput.UserInfoOutput("######################");
textOutput.UserInfoOutput("#WELCOME TO THE EDITOR#");
textOutput.UserInfoOutput("######################");
do {
textOutput.UserInfoOutput("Please enter a Command: ");
command = TextInput.checkForInput();
switch (command[0]) {
case "ADD":
textOutput.UserInfoOutput("Please enter your text: ");
if (command.length == 1) {
checkIfSuccess(text.add(TextInput.getTextInput()));
} else if (isNumeric(command[1])) {
@ -29,10 +34,10 @@ public class TextLogik {
break;
case "DEL":
if (command.length == 1) {
text.del();
checkIfSuccess(text.del());
} else if (isNumeric(command[1])) {
int line = Integer.parseInt(command[1]);
text.del(line);
checkIfSuccess(text.del(line));
} else {
textOutput.errorInvalidCommand();
}
@ -51,9 +56,9 @@ public class TextLogik {
break;
case "FORMAT":
if (command.length > 1 && "RAW".equals(command[1])) {
textOutput.formatRaw();
checkIfSuccess(textOutput.formatRaw());
} else if (command.length > 2 && "FIX".equals(command[1]) && isNumeric(command[2])) {
textOutput.formatFix(Integer.parseInt(command[2]));
checkIfSuccess(textOutput.formatFix(Integer.parseInt(command[2])));
} else {
textOutput.errorInvalidCommand();
}
@ -63,11 +68,10 @@ public class TextLogik {
textOutput.IndexOutput(text.index());
break;
case "PRINT":
textOutput.print(text.getText());
break;
case "REPLACE":
textOutput.UserInfoOutput("Please enter your text to replace: ");
if (command.length == 1){
checkIfSuccess(text.replace(TextInput.getTextInput(), TextInput.getTextInput()));
}else if(isNumeric(command[1])) {
@ -98,7 +102,7 @@ public class TextLogik {
private void checkIfSuccess(boolean method) {
if(method) {
textOutput.UserInfoOutput("Command was successfully");
textOutput.UserInfoOutput("Command was successfull");
}else {
textOutput.errorInvalidParagraph();
}

View File

@ -103,6 +103,7 @@ public class TextOutput {
}
}
}
System.out.println();
}
}