Skip to content

Commit 26b9aa2

Browse files
committed
Add LTRIM function
1 parent 00b794f commit 26b9aa2

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

src/arch/zx48k/library/string.bas

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,30 @@ end function
239239

240240

241241

242+
' ----------------------------------------------------------------
243+
' function ltrim(ByVal s$, rep$)
244+
'
245+
' Returns a copy of b$, removing all occurrences of rep$ on the
246+
' left side (beginning) of s$. For example:
247+
'
248+
' ----------------------------------------------------------------
249+
function ltrim(ByVal s$, ByVal rep$) as String
250+
DIM i as Uinteger = 0
251+
DIM d, l2 as Uinteger
252+
DIM l as Uinteger = len(rep$)
253+
254+
if not l then return s$
255+
256+
d = l - 1
257+
l2 = len(s$)
258+
259+
while i < l2 and rep = s(i to i + d)
260+
i = i + l
261+
end while
262+
263+
return s$(i to)
264+
end function
265+
242266

243267
#undef __MAX_LEN__
244268

src/arch/zxnext/library/string.bas

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,30 @@ end function
239239

240240

241241

242+
' ----------------------------------------------------------------
243+
' function ltrim(ByVal s$, rep$)
244+
'
245+
' Returns a copy of b$, removing all occurrences of rep$ on the
246+
' left side (beginning) of s$. For example:
247+
' ltrim(": Hello world", ": ") returns "Hello World"
248+
' ----------------------------------------------------------------
249+
function ltrim(ByVal s$, ByVal rep$) as String
250+
DIM i as Uinteger = 0
251+
DIM d, l2 as Uinteger
252+
DIM l as Uinteger = len(rep$)
253+
254+
if not l then return s$
255+
256+
d = l - 1
257+
l2 = len(s$)
258+
259+
while i < l2 and rep = s(i to i + d)
260+
i = i + l
261+
end while
262+
263+
return s$(i to)
264+
end function
265+
242266

243267
#undef __MAX_LEN__
244268

0 commit comments

Comments
 (0)