Register | Login
Forum Index > Samples > LuNaRiZe
Author Message
Pages: 1
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[33] LuNaRiZe - posted: 2011-05-12 17:19:37
i've just put a function together strLunzarize, i will add it to the upcoming release, the function:

Code:
//
//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

Code:
//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:

Code:
zIrOn iS My fAvOrItE PrOgRaMmInG LaNgUaGe


enjoy.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[34] - posted: 2011-05-12 18:19:45
a small update to the lunarize function, now s is replaced with z

Code:
//
//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
}


Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[62] - posted: 2011-09-05 19:36:47
i have rewrote the function to use higher level syntax compatible from 1.1.17.5+

Code:
//
//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:

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

strLunarize(@myStr);

WriteLn(@myStr);


Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Pages: 1
create new reply


Quick reply:

Message:



Currently Active Users:
There are currently 5 user(s) online. 0 member(s) and 5 guest(s)
Most users ever online was 1046, January 28, 2022, 2:08 pm.


Statistics:
Threads: 225 | Posts: 1848 | Members: 51 | Active Members: 51
Welcome to our newest member, yecate
const Copyright = '2011-2024 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd