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

avatar

(send private message)

Posts: 923
Topics: 54

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: 923
Topics: 54

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: 923
Topics: 54

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 16 user(s) online. 0 member(s) and 16 guest(s)
Most users ever online was 533, May 5, 2016, 7:19 am.


Statistics:
Threads: 223 | Posts: 1835 | Members: 49 | Active Members: 49
Welcome to our newest member, pierrotstudio
const Copyright = '2011-2017 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd