-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext_buffer.py
More file actions
36 lines (28 loc) · 951 Bytes
/
Copy pathtext_buffer.py
File metadata and controls
36 lines (28 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from doubly_linked_list import DoublyLinkedList
class TextBuffer:
def __init__(self, init=None):
self.content = DoublyLinkedList()
if init !=None:
for char in init:
self.contents.add_to_tail(char)
def __len__(self):
return len(self.content)
def __str__(self):
s = ""
current = self.contents.head
while current:
s += current.value
current = current.next
return s
def append(self, char):
self.contnets.add_to_tail(char)
def prepend(self, char):
self.contents.add_to_head(char)
def delete_front(self):
self.contents.remove_from_head()
def delete_back(self):
self.contents.remove_from_tail()
def join(self, buffer):
buffer.contents.head.prev = self.contents.tail
self.contents.tail.next = buffer.contents.head
self.contents.tail = buffer.contents.tail