Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Samples

LuNaRiZe

A community discussion post from the original code:zIRON forum.

Colin admin
Posts
928
Threads
49
Location
Bulgaria

LuNaRiZe

i've just put a function together strLunzarize, i will add it to the upcoming release, the function:

//
//Copyright (c) CodeZiron.com
//
function strLunarize(char* str) {
	push esi
	mov esi, str
	mov edx, str
@chkupper:
	lodsb
	al = or;
	je @exit;
	cmp al, 'A'
	jb @chklower;
	cmp al, 'Z'
	ja @chklower;
	add al, 0x20;
	mov [esi-1], al
@chklower:
	lodsb
	al = or;
	je @exit;
	cmp al, 'a'
	jb @chkupper;
	cmp al, 'z'
	ja @chkupper;
	sub al, 0x20;
	mov [esi-1], al
	jmp @chkupper;
@exit:
	xchg eax, edx
	pop esi
	ret
}

the usage is very simple

//declare our string storage; actually we only need 42, but i will keep it aligned on 4 bytes
char* mystr = new 48; 

//copy a string into our buffer
strlcpy(mystr, 'Ziron Is MY FAVorite programming LANGUAGE', 41);

//call the RTL function
mystr = strLunarize(mystr);

//output the string
WriteLn(mystr);

//deallocate the storage
delete mystr;

this of course will output the following:

zIrOn iS My fAvOrItE PrOgRaMmInG LaNgUaGe

enjoy.

Replies

Colin admin
Posts
928
Threads
49
Location
Bulgaria

a small update to the lunarize function, now s is replaced with z

//
//Copyright (c) CodeZiron.com
//
function strLunarize(char* str) {
	push esi
	mov esi, str
	mov edx, esi
@chkupper:
	lodsb
	al = or;
	je @exit;
	cmp al, 'A'
	jb @chklower;
	cmp al, 'Z'
	ja @chklower;
	if (al == 'S') {
		al = ord('z');
	} else {
		add al, 0x20;
	}
	mov [esi-1], al
@chklower:
	lodsb
	al = or;
	je @exit;
	cmp al, 'a'
	jb @chkupper;
	cmp al, 'z'
	ja @chkupper;
	if (al == 's') {
		al = ord('Z');
	} else {
		sub al, 0x20;
	}
	mov [esi-1], al
	jmp @chkupper;
@exit:
	xchg eax, edx
	pop esi
	ret
}
Colin admin
Posts
928
Threads
49
Location
Bulgaria

i have rewrote the function to use higher level syntax compatible from 1.1.17.5+

//
//Copyright (c) CodeZiron.com
//
procedure strLunarize(char* str) {
	uses esi;
	esi = str;
	edx = esi;
	
	repeat {
		lodsb
		if (al == 0) break;
		if ((al => 'A') and (al <= 'Z')) {
			if (al == 'S')
				al = ord('z');
			else
				add al, 0x20;
			[esi-1] = al;
		}
		
		lodsb
		if (al == 0) break;
		if ((al => 'a') and (al <= 'z')) {
			if (al == 's')
				al = ord('Z');
			else
				sub al, 0x20;
			[esi-1] = al;
		}
	};
}

a sample of using the procedure:

char myStr[32];
strlcpy(@myStr, 'This is a test string', 22);

strLunarize(@myStr);

WriteLn(@myStr);