From 03ce423e9d74afc116f02f452e11bb82354b7f66 Mon Sep 17 00:00:00 2001 From: Jacob McDonnell Date: Fri, 14 Jan 2022 18:06:29 -0500 Subject: Added next, previous, last, and current line commands --- src/filebuffer.java | 37 +++++++++++++++++++++++++++++++++++++ src/jed.java | 11 ++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/filebuffer.java b/src/filebuffer.java index ff6b225..44515a1 100644 --- a/src/filebuffer.java +++ b/src/filebuffer.java @@ -19,6 +19,39 @@ public class filebuffer { readFile(); } } + + /* upperCase: makes the current line upper case */ + public void upperCase() { + String temp = buffer.get(currentLine).toUpperCase(); + buffer.add(currentLine, temp); + buffer.remove(currentLine + 1); + } + + /* lowerCase: makes the current line lower case */ + public void lowerCase() { + String temp = buffer.get(currentLine).toLowerCase(); + buffer.add(currentLine, temp); + buffer.remove(currentLine + 1); + } + + /* upperCase: makes the lines in the range upper case */ + public void upperCase(int start, int stop) { + for (int i = start; i < stop; i++) { + String temp = buffer.get(i).toUpperCase(); + buffer.add(i, temp); + buffer.remove(i + 1); + } + } + + /* lowerCase: makes the lines in the range lower case */ + public void lowerCase(int start, int stop) { + for (int i = start; i < stop; i++) { + String temp = buffer.get(i).toLowerCase(); + buffer.add(i, temp); + buffer.remove(i + 1); + } + } + /* getFileSize: gets the size of the buffer arraylist */ public int getFileSize() { return buffer.size(); @@ -121,6 +154,10 @@ public class filebuffer { replace(start, stop, temp[1], temp[2]); else if (temp[0].equals("d")) deleteLine(start, stop); + else if (temp[0].equals("l")) + lowerCase(start, stop); + else if (temp[0].equals("U")) + upperCase(start, stop); } /* deleteLine: deletes line in the range of start to stop */ diff --git a/src/jed.java b/src/jed.java index 3f2056c..012ead4 100644 --- a/src/jed.java +++ b/src/jed.java @@ -105,6 +105,15 @@ public class jed { case '$': // Last line command file.changeCurrentLine(file.getFileSize() - 1); break; + case '.': // Prints current line + System.out.println(file.getLine(file.getCurrentLine())); + break; + case 'U': // Uppercase entire line + file.upperCase(); + break; + case 'l': // Lowercase entire line + file.lowerCase(); + break; default: System.out.println("?"); break; @@ -116,7 +125,7 @@ public class jed { } private static void help() { - System.out.println("Jed commands:\nq: quits.\nw: writes the file.\nw: filename: writes with inputted name.\no: filename: opens the file.\na: appends user input to the end of the file.\nA: appends user input after the current line.\np: prints the file.\nn: prints the file with line numbers.\nc: deletes and changes the current line.\nd: deletes the current line.\nAny integer: changes to that line number.\ng/expression/: finds and prints the expression.\n%s/expression/newExpression/: replaces an expression with new user input through the whole file.\n: prefix works with d and s/ex/nex/ for a range of line.\ns/expression/newExpression/: replaces an expression with new user input in the current line.\nh: prints the commands and their description."); + System.out.println("Jed commands:\nq: quits.\nw: writes the file.\nw: filename: writes with inputted name.\no: filename: opens the file.\na: appends user input to the end of the file.\nA: appends user input after the current line.\np: prints the file.\nn: prints the file with line numbers.\nc: deletes and changes the current line.\nd: deletes the current line.\nl: makes line lower case.\nU: makes line upper case.\n-: goes to previous line.\n+: goes to next line.\n$: goes to last line.\n.: prints current line.\nAny integer: changes to that line number.\ng/expression/: finds and prints the expression.\n%s/expression/newExpression/: replaces an expression with new user input through the whole file.\n: prefix works with d, l, U, and s/ex/nex/ for a range of line.\ns/expression/newExpression/: replaces an expression with new user input in the current line.\nh: prints the commands and their description."); } /* isNum: checks if a string is a number, only to be used for changing lines */ -- cgit v1.2.3