-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstrlib.bas
More file actions
53 lines (44 loc) · 1.54 KB
/
Copy pathstrlib.bas
File metadata and controls
53 lines (44 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
' File: strlib.bas
' ------------
' In this demo we are using UNIT to add more useful String commands to
' SmallBASIC, by carefully creating our own String-Library: strlib.bas
'
' This demo includes only two useful functions, Lset() and Rset(); You
' can add more useful functions, subs, constants - but make sure that
' they are all String commands (not Array, File, Data, etc).
'
' Write your code carefully and efficiently, because you will use these
' commands frequently in other projects. And don't forget to debug the
' code and to add clear documentation, for you and for others.
'
' See also Home-->Article-->Welcome to SmallBASIC-->Units.
' ------------
'
' Here we declare that this file is a UNIT file.
' Note: Keep file-name and unit-name the same. That helps the SB to
' automatically recompile the required units when it is needed (i.e.
' to create strlib.sbu file).
' The actual file name must be in lower case for Linux OS.
Unit strlib ' (without .bas extension)
' Here we allow other SmallBASIC files to use some of our library keywords:
Export Lset, Rset
' Left justify string s in buffer of length b.
' example: x = Lset(" SmallBASIC ", 15) ' --> x is " SmallBASIC "
Func Lset(s, b)
Local l = Len(s)
If l >= b Then
Lset = Left(s, b)
Else
Lset = s + Space(b - l)
Fi
End
' Right justify string s in buffer of length b.
' example: x = Rset(" SmallBASIC ", 15) ' --> x is " SmallBASIC "
Func Rset(s, b)
Local l = Len(s)
If l >= b Then
Rset = Right(s, b)
Else
Rset = Space(b - l) + s
Fi
End