Files
@ 831e30606026
Branch filter:
Location: Jasinta/src/std.py - annotation
831e30606026
911 B
text/x-python
implemented the String object
18037ac0f6b4 18037ac0f6b4 18037ac0f6b4 18037ac0f6b4 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 831e30606026 18037ac0f6b4 c296b5584a9d 831e30606026 18037ac0f6b4 c296b5584a9d | class Number:
def __init__(self, x):
self.val = x
def __add__(self, other):
return Number(self.val+other.val)
class String:
def __init__(self, s):
self.val = s
@staticmethod
def fromCharCode(x):
return String(chr(x.val))
def __add__(self, other):
return String(self.val+other.val)
def charAt(self, i=None):
i = (i or Number(0)).val
if 0 <= i < len(self.val):
return String(self.val[i])
else:
return String("")
def substr(self, start=None, length=None):
start = (start or Number(0)).val
length = length.val if length is not None else len(self.val)
if length < 0:
return String("")
return String(self.val[start:start+length])
def slice(self, start=None, end=None):
start = (start or Number(0)).val
end = end.val if end is not None else None
return String(self.val[start:end])
lib = {
"String": String,
"document": {"write": lambda x: print(x.val)}
}
|