mirror of https://github.com/exaloop/codon
stdlib/internal/types/str.codon
parent
e9a841a471
commit
a306ce7c82
|
@ -1,6 +1,11 @@
|
||||||
|
# (c) 2022 Exaloop Inc. All rights reserved.
|
||||||
|
|
||||||
|
|
||||||
@pure
|
@pure
|
||||||
@C
|
@C
|
||||||
def strlen(a: cobj) -> int: pass
|
def strlen(a: cobj) -> int:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@extend
|
@extend
|
||||||
class str:
|
class str:
|
||||||
|
@ -68,7 +73,7 @@ class str:
|
||||||
str.memcpy(p + len1, other.ptr, len2)
|
str.memcpy(p + len1, other.ptr, len2)
|
||||||
return str(p, len3)
|
return str(p, len3)
|
||||||
|
|
||||||
def c_str(self):
|
def c_str(self) -> cobj:
|
||||||
n = self.__len__()
|
n = self.__len__()
|
||||||
p = cobj(n + 1)
|
p = cobj(n + 1)
|
||||||
str.memcpy(p, self.ptr, n)
|
str.memcpy(p, self.ptr, n)
|
||||||
|
@ -81,7 +86,7 @@ class str:
|
||||||
str.memcpy(p, t, n)
|
str.memcpy(p, t, n)
|
||||||
return str(p, n)
|
return str(p, n)
|
||||||
|
|
||||||
def __eq__(self, other: str):
|
def __eq__(self, other: str) -> bool:
|
||||||
if self.len != other.len:
|
if self.len != other.len:
|
||||||
return False
|
return False
|
||||||
i = 0
|
i = 0
|
||||||
|
@ -91,15 +96,19 @@ class str:
|
||||||
i += 1
|
i += 1
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def __match__(self, other: str):
|
def __match__(self, other: str) -> bool:
|
||||||
return self.__eq__(other)
|
return self.__eq__(other)
|
||||||
|
|
||||||
def __ne__(self, other: str):
|
def __ne__(self, other: str) -> bool:
|
||||||
return not self.__eq__(other)
|
return not self.__eq__(other)
|
||||||
|
|
||||||
def cat(*args):
|
def cat(*args) -> str:
|
||||||
total = 0
|
total = 0
|
||||||
if staticlen(args) == 1 and hasattr(args[0], "__iter__") and hasattr(args[0], "__len__"):
|
if (
|
||||||
|
staticlen(args) == 1
|
||||||
|
and hasattr(args[0], "__iter__")
|
||||||
|
and hasattr(args[0], "__len__")
|
||||||
|
):
|
||||||
for s in args[0]:
|
for s in args[0]:
|
||||||
if not isinstance(s, str):
|
if not isinstance(s, str):
|
||||||
compile_error("not a string")
|
compile_error("not a string")
|
||||||
|
|
Loading…
Reference in New Issue