Subversion Repositories Kolibri OS

Rev

Rev 5394 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5394 Rev 5907
1
proc string.length uses ebx, _str
1
proc string.length uses ebx, _str
2
    mov     eax, 0
2
    mov     eax, 0
3
    mov     ebx, [_str]
3
    mov     ebx, [_str]
4
  @@:
4
  @@:
5
    cmp     [ebx], byte 0
5
    cmp     [ebx], byte 0
6
    je	    @f
6
    je	    @f
7
    inc     eax
7
    inc     eax
8
    inc     ebx
8
    inc     ebx
9
    jmp     @b
9
    jmp     @b
10
  @@:
10
  @@:
11
    ret
11
    ret
12
 endp
12
 endp
13
 
13
 
14
 proc string.copy uses eax ebx ecx, _src, _dst
14
 proc string.copy uses eax ebx ecx, _src, _dst
15
    mov     eax, [_src]
15
    mov     eax, [_src]
16
    mov     ebx, [_dst]
16
    mov     ebx, [_dst]
17
  @@:
17
  @@:
18
    mov     cl, [eax]
18
    mov     cl, [eax]
19
    mov     [ebx], cl
19
    mov     [ebx], cl
20
    cmp     cl, 0
20
    cmp     cl, 0
21
    je	    @f
21
    je	    @f
22
    inc     eax
22
    inc     eax
23
    inc     ebx
23
    inc     ebx
24
    jmp     @b
24
    jmp     @b
25
  @@:
25
  @@:
26
    ret
26
    ret
27
 endp
27
 endp
28
 
28
 
29
 proc string.concatenate uses eax, _src, _dst
29
 proc string.concatenate uses eax, _src, _dst
30
    stdcall string.length, [_dst]
30
    stdcall string.length, [_dst]
31
    add     eax, [_dst]
31
    add     eax, [_dst]
32
    stdcall string.copy, [_src], eax
32
    stdcall string.copy, [_src], eax
33
    ret
33
    ret
34
 endp
34
 endp
35
 
35
 
36
 proc string.compare uses ebx ecx edx, _str1, _str2
36
 proc string.compare uses ebx ecx edx, _str1, _str2
37
    mov     eax, 0
37
    mov     eax, 0
38
    mov     ebx, [_str1]
38
    mov     ebx, [_str1]
39
    mov     ecx, [_str2]
39
    mov     ecx, [_str2]
40
  @@:
40
  @@:
41
    mov     dl, [ebx]
41
    mov     dl, [ebx]
42
    cmp     dl, [ecx]
42
    cmp     dl, [ecx]
43
    jne     .not_eq
43
    jne     .not_eq
44
    cmp     dl, 0
44
    cmp     dl, 0
45
    je	    @f
45
    je	    @f
46
    cmp     [ecx], byte 0
46
    cmp     [ecx], byte 0
47
    je	    @f
47
    je	    @f
48
    inc     ebx
48
    inc     ebx
49
    inc     ecx
49
    inc     ecx
50
    jmp     @b
50
    jmp     @b
51
 .not_eq:
51
 .not_eq:
52
    mov     eax, -1
52
    mov     eax, -1
53
  @@:
53
  @@:
54
    inc     eax
54
    inc     eax
55
    ret
55
    ret
56
 endp
56
 endp
-
 
57
 
-
 
58
 proc string.cmp uses ecx esi edi, _str1, _str2, _n
-
 
59
    mov     ecx, [_n]
-
 
60
    test    ecx, ecx	     ; Max length is zero?
-
 
61
    je	    .done
-
 
62
 
-
 
63
    mov     esi, [_str1]	; esi = string s1
-
 
64
    mov     edi, [_str2]	; edi = string s2
-
 
65
    cld
-
 
66
 .compare:
-
 
67
    cmpsb		     ; Compare two bytes
-
 
68
    jne     .done
-
 
69
    cmp     byte [esi-1], 0  ; End of string?
-
 
70
    je	    .done
-
 
71
    dec     ecx 	     ; Length limit reached?
-
 
72
    jne     .compare
-
 
73
 .done:
-
 
74
    seta    al		     ; al = (s1 > s2)
-
 
75
    setb    ah		     ; ah = (s1 < s2)
-
 
76
    sub     al, ah
-
 
77
    movsx   eax, al	     ; eax = (s1 > s2) - (s1 < s2), i.e. -1, 0, 1
-
 
78
    ret
-
 
79
 endp
57
 
80
 
58
 proc string.to_lower_case uses eax, _str
81
 proc string.to_lower_case uses eax, _str
59
    mov     eax, [_str]
82
    mov     eax, [_str]
60
  @@:
83
  @@:
61
    cmp     [eax], byte 0
84
    cmp     [eax], byte 0
62
    je	    @f
85
    je	    @f
63
    cmp     [eax], byte 65
86
    cmp     [eax], byte 65
64
    jl	    .next
87
    jl	    .next
65
    cmp     [eax], byte 90
88
    cmp     [eax], byte 90
66
    jg	    .next
89
    jg	    .next
67
    add     [eax], byte 97 - 65
90
    add     [eax], byte 97 - 65
68
 .next:
91
 .next:
69
    inc     eax
92
    inc     eax
70
    jmp     @b
93
    jmp     @b
71
  @@:
94
  @@:
72
    ret
95
    ret
73
 endp
96
 endp
74
 
97
 
75
 proc string.to_upper_case uses eax, _str
98
 proc string.to_upper_case uses eax, _str
76
    mov     eax, [_str]
99
    mov     eax, [_str]
77
  @@:
100
  @@:
78
    cmp     [eax], byte 0
101
    cmp     [eax], byte 0
79
    je	    @f
102
    je	    @f
80
    cmp     [eax], byte 97
103
    cmp     [eax], byte 97
81
    jl	    .next
104
    jl	    .next
82
    cmp     [eax], byte 122
105
    cmp     [eax], byte 122
83
    jg	    .next
106
    jg	    .next
84
    sub     [eax], byte 97 - 65
107
    sub     [eax], byte 97 - 65
85
 .next:
108
 .next:
86
    inc     eax
109
    inc     eax
87
    jmp     @b
110
    jmp     @b
88
  @@:
111
  @@:
89
    ret
112
    ret
90
 endp
113
 endp
91
 
114
 
92
 proc string.match uses ebx ecx edx, _str1, _str2
115
 proc string.match uses ebx ecx edx, _str1, _str2
93
    mov     ebx, [_str1]
116
    mov     ebx, [_str1]
94
    mov     ecx, [_str2]
117
    mov     ecx, [_str2]
95
  @@:
118
  @@:
96
    cmp     [ebx], byte 0
119
    cmp     [ebx], byte 0
97
    je	    @f
120
    je	    @f
98
    cmp     [ecx], byte 0
121
    cmp     [ecx], byte 0
99
    je	    @f
122
    je	    @f
100
 
123
 
101
    mov     dl, [ebx]
124
    mov     dl, [ebx]
102
    cmp     [ecx], byte '?'
125
    cmp     [ecx], byte '?'
103
    je	    .next
126
    je	    .next
104
    cmp     [ecx], byte '*'
127
    cmp     [ecx], byte '*'
105
    je	    .next_ebx
128
    je	    .next_ebx
106
    cmp     [ecx], dl
129
    cmp     [ecx], dl
107
    je	    .next
130
    je	    .next
108
 
131
 
109
    cmp     [ecx - 1], byte '*'
132
    cmp     [ecx - 1], byte '*'
110
    je	    .next_ecx
133
    je	    .next_ecx
111
 
134
 
112
    jmp     @f
135
    jmp     @f
113
 
136
 
114
 .next_ecx:
137
 .next_ecx:
115
    dec     ecx
138
    dec     ecx
116
    jmp     .next
139
    jmp     .next
117
 .next_ebx:
140
 .next_ebx:
118
    dec     ebx
141
    dec     ebx
119
 .next:
142
 .next:
120
    inc     ebx
143
    inc     ebx
121
    inc     ecx
144
    inc     ecx
122
    jmp     @b
145
    jmp     @b
123
  @@:
146
  @@:
124
 
147
 
125
  @@:
148
  @@:
126
    cmp     [ecx], byte 0
149
    cmp     [ecx], byte 0
127
    je	    @f
150
    je	    @f
128
    cmp     [ecx], byte '*'
151
    cmp     [ecx], byte '*'
129
    jne     @f
152
    jne     @f
130
    inc     ecx
153
    inc     ecx
131
    jmp     @b
154
    jmp     @b
132
  @@:
155
  @@:
133
 
156
 
134
    cmp     [ecx], byte 0
157
    cmp     [ecx], byte 0
135
    je	    @f
158
    je	    @f
136
    mov     eax, 0
159
    mov     eax, 0
137
    ret
160
    ret
138
  @@:
161
  @@:
139
    mov     eax, 1
162
    mov     eax, 1
140
    ret
163
    ret
141
 endp
164
 endp
142
 
165
 
143
 proc string.trim_last uses eax, _str
166
 proc string.trim_last uses eax, _str
144
    stdcall string.length, [_str]
167
    stdcall string.length, [_str]
145
    add     eax, [_str]
168
    add     eax, [_str]
146
    dec     eax
169
    dec     eax
147
  @@:
170
  @@:
148
    cmp     [eax], byte ' '
171
    cmp     [eax], byte ' '
149
    jne     @f
172
    jne     @f
150
    mov     [eax], byte 0
173
    mov     [eax], byte 0
151
    dec     eax
174
    dec     eax
152
    jmp     @b
175
    jmp     @b
153
  @@:
176
  @@:
154
    ret
177
    ret
155
 endp
178
 endp
156
 
179
 
157
 proc string.trim_first, _str
180
 proc string.trim_first, _str
158
    mov     eax, [_str]
181
    mov     eax, [_str]
159
  @@:
182
  @@:
160
    cmp     [eax], byte ' '
183
    cmp     [eax], byte ' '
161
    jne     @f
184
    jne     @f
162
    inc     eax
185
    inc     eax
163
    jmp     @b
186
    jmp     @b
164
  @@:
187
  @@:
165
    ret
188
    ret
166
 endp
189
 endp
167
 
190
 
168
 proc string.index_of uses ebx ecx, _str, _char, _num
191
 proc string.index_of uses ebx ecx, _str, _char, _num
169
    mov     ebx, [_char]
192
    mov     ebx, [_char]
170
    mov     ecx, [_str]
193
    mov     ecx, [_str]
171
    mov     eax, 0
194
    mov     eax, 0
172
  @@:
195
  @@:
173
    cmp     [ecx], byte 0
196
    cmp     [ecx], byte 0
174
    je	    @f
197
    je	    @f
175
    cmp     [ecx], bl
198
    cmp     [ecx], bl
176
    jne     .after_check
199
    jne     .after_check
177
    dec     [_num]
200
    dec     [_num]
178
    jz	    .finded
201
    jz	    .finded
179
 .after_check:
202
 .after_check:
180
    inc     ecx
203
    inc     ecx
181
    inc     eax
204
    inc     eax
182
    jmp     @b
205
    jmp     @b
183
  @@:
206
  @@:
184
    mov     eax, -1
207
    mov     eax, -1
185
 .finded:
208
 .finded:
186
    ret
209
    ret
187
 endp
210
 endp
188
 
211
 
189
 proc string.last_index_of uses ebx ecx, _str, _char, _num
212
 proc string.last_index_of uses ebx ecx, _str, _char, _num
190
    stdcall string.length, [_str]
213
    stdcall string.length, [_str]
191
    mov     ecx, [_str]
214
    mov     ecx, [_str]
192
    add     ecx, eax
215
    add     ecx, eax
193
    mov     ebx, [_char]
216
    mov     ebx, [_char]
194
  @@:
217
  @@:
195
    cmp     eax, 0
218
    cmp     eax, 0
196
    je	    @f
219
    je	    @f
197
    cmp     [ecx], bl
220
    cmp     [ecx], bl
198
    jne     .after_check
221
    jne     .after_check
199
    dec     [_num]
222
    dec     [_num]
200
    jz	    .finded
223
    jz	    .finded
201
 .after_check:
224
 .after_check:
202
    dec     ecx
225
    dec     ecx
203
    dec     eax
226
    dec     eax
204
    jmp     @b
227
    jmp     @b
205
  @@:
228
  @@:
206
    mov     eax, -2
229
    mov     eax, -2
207
 .finded:
230
 .finded:
208
    inc     eax
231
    inc     eax
209
    ret
232
    ret
210
 endp
233
 endp