-
Notifications
You must be signed in to change notification settings - Fork 0
/
ka_strings.spin2
160 lines (115 loc) · 4.46 KB
/
ka_strings.spin2
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
'' =================================================================================================
''
'' File....... ka_strings.spin2
'' Purpose....
'' Author..... Kevin Ahr
'' Copyright (c) 2022 Kevin Ahr
'' -- see below for terms of use
'' Started.... 27 MAY 2022
''
'' {$P2}
''
'' =================================================================================================
con { fixed io pins }
RX1 = 63 { I } ' programming / debug
TX1 = 62 { O }
SF_CS = 61 { O } ' serial flash
SF_SCK = 60 { O }
SF_SDO = 59 { O }
SF_SDI = 58 { I }
pub null()
'' This is not a top-level object
pub containschar(char, str) : out | i, size
size := strsize(str)
repeat i from 0 to size
if byte[str][i] == char
out := true
return out
pub charcount(char, str) : out | i, size
size := strsize(str)
repeat i from 0 to size
if byte[str][i] == char
out += 1
return out
pub split_str(str, p_list, sep) : c | size, seps, i, j, k, prev_sep
bytefill(p_list, 0, strsize(p_list)) ' reset data
size := strsize(str)
prev_sep := 0
j := 0
k := 0
' get seps
repeat i from 0 to size
if byte[str][i] == sep
pint(56)
repeat j from prev_sep to i - 1
byte[p_list][j] := byte[str][j]
prev_sep := i
k++
return c
pub split_str2(str, sep, p_d0, p_d1) | len, i, c, vn
bytefill(p_d0, 0, strsize(p_d0)) ' reset data
bytefill(p_d1, 0, strsize(p_d1))
vn := 0
len := strsize(str)
repeat i from 0 to len ' loop through chars
c := byte[str][i]
if c
if c == sep ' seperator?
vn += 1
else
if vn == 0
byte[p_d0][strsize(p_d0)] := c ' add char to d0, d1, etc
elseif vn == 1
byte[p_d1][strsize(p_d1)] := c
pub split_str3(str, sep, p_d0, p_d1, p_d2) | len, i, c, vn
bytefill(p_d0, 0, strsize(p_d0)) ' reset data
bytefill(p_d1, 0, strsize(p_d1))
bytefill(p_d2, 0, strsize(p_d2))
vn := 0
len := strsize(str)
repeat i from 0 to len ' loop through chars
c := byte[str][i]
if c
if c == sep ' seperator?
vn += 1
else
case vn
0: byte[p_d0][strsize(p_d0)] := c ' add char to d0, d1, etc
1: byte[p_d1][strsize(p_d1)] := c
2: byte[p_d2][strsize(p_d2)] := c
pub split_str4(str, sep, p_d0, p_d1, p_d2, p_d3) | len, i, c, vn
bytefill(p_d0, 0, strsize(p_d0)) ' reset data
bytefill(p_d1, 0, strsize(p_d1))
bytefill(p_d2, 0, strsize(p_d2))
bytefill(p_d3, 0, strsize(p_d3))
vn := 0
len := strsize(str)
repeat i from 0 to len ' loop through chars
c := byte[str][i]
if c
if c == sep ' seperator?
vn += 1
else
case vn
0: byte[p_d0][strsize(p_d0)] := c ' add char to d0, d1, etc
1: byte[p_d1][strsize(p_d1)] := c
2: byte[p_d2][strsize(p_d2)] := c
3: byte[p_d3][strsize(p_d3)] := c
con { license }
{{
Terms of Use: MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
}}