Hello and editor
This commit is contained in:
parent
43568e947f
commit
b72f78839c
2 changed files with 29 additions and 6 deletions
|
@ -6,11 +6,29 @@ using std::string;
|
||||||
|
|
||||||
using size_type = Editor::size_type;
|
using size_type = Editor::size_type;
|
||||||
|
|
||||||
size_type Editor::get_size() const
|
size_type Editor::get_size() const { return text.size(); }
|
||||||
{
|
|
||||||
return text.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
size_type Editor::find_left_par(size_type pos) const {
|
Editor::size_type Editor::find_left_par(size_type pos) const {
|
||||||
return string::npos;
|
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
|
||||||
}
|
}
|
||||||
|
|
5
lab1/hello.cc
Normal file
5
lab1/hello.cc
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
std::cout << "Hello" << std::endl;
|
||||||
|
}
|
Loading…
Reference in a new issue