ymg2000
Silver Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору function StrChPos(const S: string; C : Char; var Pos : Cardinal) : Boolean; { Возвращает позицию C в строке S } asm push ebx { Save registers } push edi or eax, eax { Protect against null string } jz @@NotFound xor edi, edi { Zero counter } mov ebx, [eax-StrOffset].LStrRec.Length { Get input length } @@Loop: inc edi { Increment counter } cmp [eax], dl { Did we find it? } jz @@Found inc eax { Increment pointer } cmp edi, ebx { End of string? } jnz @@Loop { If not, loop } @@NotFound: xor eax, eax { Not found, zero EAX for False } mov [ecx], eax jmp @@Done @@Found: mov [ecx], edi { Set Pos } mov eax, 1 { Set EAX to True } @@Done: pop edi { Restore registers } pop ebx end; function CharExistsInStr(const S : string; C : Char) : Boolean; register; { Возвращает True, если символ C содержится в S } asm push ebx xor ecx, ecx or eax, eax jz @@Done mov ebx, [eax-StrOffset].LStrRec.Length or ebx, ebx jz @@Done jmp @@5 @@Loop: cmp dl, [eax+3] jne @@1 inc ecx jmp @@Done @@1: cmp dl, [eax+2] jne @@2 inc ecx jmp @@Done @@2: cmp dl, [eax+1] jne @@3 inc ecx jmp @@Done @@3: cmp dl, [eax+0] jne @@4 inc ecx jmp @@Done @@4: add eax, 4 sub ebx, 4 @@5: cmp ebx, 4 jge @@Loop cmp ebx, 3 je @@1 cmp ebx, 2 je @@2 cmp ebx, 1 je @@3 @@Done: mov eax, ecx pop ebx end; function WordPosInStr(N: Cardinal; const S, WordDelims: string; var Pos: Cardinal) : Boolean; { Устанавливается строка-разделитель слов и номер N искомого слова в строке. } { Если слово с таким номером есть в строке S, возвращается True и позиция начала этого слова } var Count: Cardinal; K : Cardinal; begin Count := 0; K := 1; Result := False; while (K <= Length(S)) and (Count <> N) do begin {skip over delimiters} while (I <= Length(S)) and CharExistsInStr(WordDelims, S[K]) do Inc(I); {if we're not beyond end of S, we're at the start of a word} if K <= Length(S) then Inc(Count); {if not finished, find the end of the current word} if Count <> N then while (K <= Length(S)) and not CharExistsInStr(WordDelims, S[K]) do Inc(K) else begin Pos := K; Result := True; end; end; end; function ExtractWordFromStr(N: Cardinal; const S, WordDelims: string): string; { Возвращает N-ое слово строки S. Слова отделены разделителем WordDelims. } var K, J : Cardinal; begin Result := ''; if WordPosInStr(N, S, WordDelims, K) then begin {find the end of the current word} J := K; while (K <= Length(S)) and not CharExistsInStr(WordDelims, S[K]) do Inc(K); SetLength(Result, K-J); Move(S[J], Result[1], K-J); end; end; function GetPreffix(const VildPattern: string; const VildCh: char): string; { Возвращает подстроку от начала строки VildPattern до первого вхождения } { в строку символа VildCh } var APos: cardinal; begin IF Not StrChPos(VildPattern, VildCh, APos) or (APos < 2) THEN Result := '' ELSE Result := ExtractWordFromStr(1, VildPattern, VildCh); end; |