From 43568e947f972725bd087552480d402511305f6a Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Mon, 11 Nov 2024 18:05:46 +0100 Subject: [PATCH 1/3] Ignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6142305 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.o +*.d From b72f78839c6aabd114afa307031889626e7f8175 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Mon, 11 Nov 2024 18:06:07 +0100 Subject: [PATCH 2/3] Hello and editor --- lab1/editor.cc | 30 ++++++++++++++++++++++++------ lab1/hello.cc | 5 +++++ 2 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 lab1/hello.cc diff --git a/lab1/editor.cc b/lab1/editor.cc index 82ec95b..fca27d4 100644 --- a/lab1/editor.cc +++ b/lab1/editor.cc @@ -6,11 +6,29 @@ using std::string; using size_type = Editor::size_type; -size_type Editor::get_size() const -{ - return text.size(); -} +size_type Editor::get_size() const { return text.size(); } -size_type Editor::find_left_par(size_type pos) const { - return string::npos; +Editor::size_type Editor::find_left_par(size_type pos) const { + char right_par = text[pos]; + char left_par; + + // Determine the matching left parenthesis for the given right parenthesis + switch (right_par) { + case ')': left_par = '('; break; + case ']': left_par = '['; break; + case '}': left_par = '{'; break; + default: return string::npos; // Not a valid right parenthesis + } + + int balance = 1; // Start with the right parenthesis at text[pos] + for (size_type i = pos; i-- > 0;) { + if (text[i] == left_par) { + balance--; + if (balance == 0) return i; // Found the matching left parenthesis + } else if (text[i] == right_par) { + balance++; + } + } + + return string::npos; // No matching left parenthesis found } diff --git a/lab1/hello.cc b/lab1/hello.cc new file mode 100644 index 0000000..b873300 --- /dev/null +++ b/lab1/hello.cc @@ -0,0 +1,5 @@ +#include + +int main(int argc, char *argv[]) { + std::cout << "Hello" << std::endl; +} From bdc3832fd12e888bef102559fb7294c8599b7de3 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Mon, 11 Nov 2024 18:06:14 +0100 Subject: [PATCH 3/3] Justfile for convenience --- lab1/Justfile | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 lab1/Justfile diff --git a/lab1/Justfile b/lab1/Justfile new file mode 100644 index 0000000..1ab8b38 --- /dev/null +++ b/lab1/Justfile @@ -0,0 +1,18 @@ +all: a1 a2 a3 a4 + +a1: + g++ -o hello hello.cc + ./hello +a2: + g++ -std=c++11 -o separate_main separate_main.cc separate_fn.cc + +a3: + g++ -std=c++11 -c separate_main.cc + g++ -std=c++11 -c separate_fn.cc + g++ -std=c++11 -o separate_main separate_main.o separate_fn.o + +a4: + g++ -std=c++11 -o separate_main separate_main.cc + +a5: + g++ -c -O2 -Wall -Wextra -pedantic-errors -Wold-style-cast -std=c++11 hello.cc