Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 6470 → Rev 6471

/kernel/trunk/fs/parse_fn.inc
237,77 → 237,54
ret
endp
 
 
char_todown:
; convert character in al to downcase, using cp866 encoding
cmp al, 'A'
cp866toUpper:
; convert cp866 character in al to uppercase
cmp al, 'a'
jb .ret
cmp al, 'Z'
jbe .az
cmp al, 0x80 ; 'А'
cmp al, 'z'
jbe @f
cmp al, 0xA0
jb .ret
cmp al, 0x90 ; 'Р'
cmp al, 0xB0
jb @f
cmp al, 0xE0
jb .ret
cmp al, 0xF0
jb .rus
cmp al, 0xF0 ; 'Ё'
jz .yo
cmp al, 0x9F ; 'Я'
cmp al, 0xF7
ja .ret
; 0x90-0x9F -> 0xE0-0xEF
add al, 0xE0-0x90
and eax, -2
.ret:
ret
 
.az:
.rus: ; 0x80-0x8F -> 0xA0-0xAF
add al, 0x20
@@:
sub eax, 32
ret
 
.yo:
inc al
.rus:
sub eax, 0xE0-0x90
ret
 
 
char_toupper:
; convert character in al to uppercase, using cp866 encoding
cmp al, 'a'
utf16toUpper:
; convert UTF-16 character in ax to uppercase
cmp ax, 'a'
jb .ret
cmp al, 'z'
jbe .az
cmp al, 0xA0 ; 'а'
cmp ax, 'z'
jbe @f
cmp ax, 430h
jb .ret
cmp al, 0xE0 ; 'р'
jb .rus
cmp al, 0xF1 ; 'ё'
jz .yo
cmp al, 0xEF ; 'я'
ja .ret
; 0xE0-0xEF -> 0x90-0x9F
sub al, 0xE0-0x90
cmp ax, 450h
jb @f
cmp ax, 460h
jnc .ret
sub eax, 80
.ret:
ret
 
.az:
.rus: ; 0xA0-0xAF -> 0x80-0x8F
and al, not 0x20
@@:
sub eax, 32
ret
 
.yo:
dec al
ret
 
 
uni2ansi_str:
; convert UNICODE zero-terminated string to ASCII-string (codepage 866)
; in: esi->source, edi->buffer (may be esi=edi)
; destroys: eax,esi,edi
lodsw
call uni2ansi_char
stosb
test al, al
jnz uni2ansi_str
ret
 
 
uni2ansi_char:
; convert UNICODE character in ax to ANSI character in al using cp866 encoding
cmp ax, 0x80
355,7 → 332,6
 
.table db 1, 51h, 4, 54h, 7, 57h, 0Eh, 5Eh
 
 
ansi2uni_char:
; convert ANSI character in al to UNICODE character in ax, using cp866 encoding
movzx eax, al
392,25 → 368,85
mov al, '_'
ret
 
utf8_to_cp866:
; in: esi, edi, ecx
; destroys esi, edi, ecx, eax
call utf8to16
js utf8to16.ret
call uni2ansi_char
stosb
jmp utf8_to_cp866
cp866toUTF8_string:
; in:
; esi -> cp866 string (could be zero terminated)
; edi -> buffer for UTF-8 string
; ecx = buffer size (signed)
lodsb
call ansi2uni_char
push eax
call UTF16to8
pop eax
js @f
test eax, eax
jnz cp866toUTF8_string
@@:
ret
 
utf8to16:
; SF=1 -> counter
; ZF=1 -> zero char
 
UTF16to8_string:
; in:
; esi -> string
; ecx = byte counter
; out:
; SF=1 -> end
; ax = UTF-16 char
; changes esi, ecx
; esi -> UTF-16 string (could be zero terminated)
; edi -> buffer for UTF-8 string
; ecx = buffer size (signed)
xor eax, eax
@@:
lodsw
push eax
call UTF16to8
pop eax
js @f
test eax, eax
jnz @b
@@:
ret
 
UTF16to8:
; in:
; eax = UTF-16 char
; edi -> buffer for UTF-8 char (increasing)
; ecx = byte counter (decreasing)
dec ecx
js .ret
cmp eax, 80h
jnc @f
stosb
test eax, eax ; SF=0
.ret:
ret
 
@@:
dec ecx
js .ret
cmp eax, 800h
jnc @f
shl eax, 2
shr al, 2
or eax, 1100000010000000b
xchg al, ah
stosw
ret
 
@@:
dec ecx
js .ret
shl eax, 4
shr ax, 2
shr al, 2
or eax, 111000001000000010000000b
bswap eax
shr eax, 8
stosb
shr eax, 8
stosw
ret
 
utf8to16:
; in: esi -> UTF-8 char (increasing)
; out: ax = UTF-16 char
lodsb
test al, al
jns .got
418,8 → 454,6
jnc utf8to16
@@:
shl ax, 8
dec ecx
js .ret
lodsb
test al, al
jns .got
429,8 → 463,6
shl ax, 3
jnc @f
shl eax, 3
dec ecx
js .ret
lodsb
test al, al
jns .got
445,7 → 477,6
 
.got:
xor ah, ah
.ret:
ret
 
strlen: