mirror of https://github.com/dirtbags/netarch.git
Initializers for GapStrings
This commit is contained in:
parent
9d487edfb3
commit
fc00e0941b
|
@ -10,10 +10,12 @@ import __init__
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
class GapString:
|
class GapString:
|
||||||
def __init__(self, drop='?'):
|
def __init__(self, init=None, drop='?'):
|
||||||
self.contents = []
|
self.contents = []
|
||||||
self.length = 0
|
self.length = 0
|
||||||
self.drop = drop
|
self.drop = drop
|
||||||
|
if init:
|
||||||
|
self.append(init)
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return self.length
|
return self.length
|
||||||
|
@ -58,7 +60,7 @@ class GapString:
|
||||||
end = min(self.length, end)
|
end = min(self.length, end)
|
||||||
start = min(self.length, start)
|
start = min(self.length, start)
|
||||||
|
|
||||||
new = self.__class__(self.drop)
|
new = self.__class__(drop=self.drop)
|
||||||
new.contents = self.contents[:]
|
new.contents = self.contents[:]
|
||||||
new.length = end - start
|
new.length = end - start
|
||||||
if new.length == 0:
|
if new.length == 0:
|
||||||
|
|
Loading…
Reference in New Issue