Skip to content

Commit 322d288

Browse files
authored
Merge pull request #543 from boriel/feature/update_libraries
Feature/update libraries
2 parents 9de3c54 + 8fa8a6b commit 322d288

15 files changed

Lines changed: 172 additions & 534 deletions

File tree

src/arch/zx48k/library/lcase.bas

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/arch/zx48k/library/string.bas

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

240240

241241

242+
' ----------------------------------------------------------------
243+
' function ltrim(ByVal s$, rep$)
244+
'
245+
' Returns a copy of s$, 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+
266+
267+
268+
' ----------------------------------------------------------------
269+
' function rtrim(ByVal s$, rep$)
270+
'
271+
' Returns a copy of s$, removing all occurrences of rep$ on the
272+
' right side (ending) of s$. For example:
273+
' rtrim("Hello world. ", ". ") returns "Hello World"
274+
' ----------------------------------------------------------------
275+
function rtrim(ByVal s$, ByVal rep$) as String
276+
DIM i as Integer
277+
DIM d, l2 as Uinteger
278+
DIM l as Uinteger = len(rep$)
279+
280+
l2 = len(s$)
281+
if not l or l2 < l then return s$
282+
283+
d = l - 1
284+
i = l2 - 1
285+
286+
while i >= d and rep = s(i - d to i)
287+
i = i - l
288+
end while
289+
290+
if i < 0 then return ""
291+
292+
return s$(to i)
293+
end function
294+
295+
296+
297+
' ----------------------------------------------------------------
298+
' function trim(ByVal s$, rep$)
299+
'
300+
' Returns a copy of s$, removing all occurrences of rep$ on the
301+
' left and right side (ending) of s$. For example:
302+
' rtrim(";.;.Hello world;.;.", ";.") returns "Hello World"
303+
' ----------------------------------------------------------------
304+
function trim(ByVal s$, ByVal rep$) as String
305+
return ltrim(rtrim(s$, rep$), rep$)
306+
end function
242307

243308
#undef __MAX_LEN__
244309

src/arch/zx48k/library/ucase.bas

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/arch/zxnext/library/lcase.bas

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/arch/zxnext/library/string.bas

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

240240

241241

242+
' ----------------------------------------------------------------
243+
' function ltrim(ByVal s$, rep$)
244+
'
245+
' Returns a copy of s$, 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+
266+
267+
268+
' ----------------------------------------------------------------
269+
' function rtrim(ByVal s$, rep$)
270+
'
271+
' Returns a copy of s$, removing all occurrences of rep$ on the
272+
' right side (ending) of s$. For example:
273+
' rtrim("Hello world. ", ". ") returns "Hello World"
274+
' ----------------------------------------------------------------
275+
function rtrim(ByVal s$, ByVal rep$) as String
276+
DIM i as Integer
277+
DIM d, l2 as Uinteger
278+
DIM l as Uinteger = len(rep$)
279+
280+
l2 = len(s$)
281+
if not l or l2 < l then return s$
282+
283+
d = l - 1
284+
i = l2 - 1
285+
286+
while i >= d and rep = s(i - d to i)
287+
i = i - l
288+
end while
289+
290+
if i < 0 then return ""
291+
292+
return s$(to i)
293+
end function
294+
295+
296+
297+
' ----------------------------------------------------------------
298+
' function trim(ByVal s$, rep$)
299+
'
300+
' Returns a copy of s$, removing all occurrences of rep$ on the
301+
' left and right side (ending) of s$. For example:
302+
' rtrim(";.;.Hello world;.;.", ";.") returns "Hello World"
303+
' ----------------------------------------------------------------
304+
function trim(ByVal s$, ByVal rep$) as String
305+
return ltrim(rtrim(s$, rep$), rep$)
306+
end function
242307

243308
#undef __MAX_LEN__
244309

0 commit comments

Comments
 (0)