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