Register | Login
Forum Index > News > Ziron Library Files
Author Message
Pages: 1
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[337] Ziron Library Files - posted: 2011-11-04 23:33:13
right now there is no real documentation on what functions are available inside the library files and their usage... so when i get time i will post in this thread, different functions and their usage, if you want to ask about a specific function then please start a new thread in Source Help section, you will not be able to reply to this thread.

-----------------------------------

ok to start off with we will look at the most recent procedure addition "strFold" which is inside the "strings.zir" library file.

strFold

strFold will collapse a string by x amount of characters, it takes 2 parameters, the first is the string buffer, and the second is the length you want to collapse by. Lets take a look:

Code:
program WIN32CUI 'test';

#include 'strings.zir'; 
#include 'console.zir'; //strings is included in console.zir anyway but i've added it above for reference.

char buf[32];

strAppend(@buf, 'Command 1$Command 2$', 32);

//Here you could process the buf string to the deliminator in this sample.

print('My String: "', @buf, '"\r\n');

strFold(@buf, 10); // <<<<<<<<<<<<<<<<<<<<

//and so on for command 2

print('My String: "', @buf, '"\r\n');

wait_key(nil);
ExitProcess(0);


the output would be as so:

Command 1$Command 2$
Command 2$


notice the first 10 characters are folded and the rest of the buffer has now moved to the start - making way for more appends (which we will take a look at next thread)

more functions will be documented in this thread at later times/dates smile

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
[345] - posted: 2011-11-05 15:19:08
Let us take a closer look at strAppend.

strAppend

Code:
program WIN32CUI 'test';

#include 'strings.zir'; 
#include 'console.zir'; //strings is included in console.zir anyway but i've added it above for reference.

char buf[32];

strAppend(@buf, 'Test ', 32);
strAppend(@buf, 'Test ', 32);
strAppend(@buf, 'Test ', 32);
strAppend(@buf, 'Test ', 32);
strAppend(@buf, 'Test ', 32);
strAppend(@buf, 'Test ', 32);
strAppend(@buf, 'Test ', 32);

print('My String: "', @buf, '"\r\n');

//notice there is one Test missing, there is 6 not 7... this is because it does not all fit into the buffer.

//we can perform checks when using strAppend.

eax = strAppend(@buf, 'Test', 32);
if (eax == false) {
  print('strAppend failed - not enough buffer storage to append the string\r\n');
}


//still 6 Test 's
print('My String: "', @buf, '"\r\n');

wait_key(nil);
ExitProcess(0);


as you see in this example, strAppend will append the string from the first null character that is in the buffer, strAppend will return true on success and false if it is unable to append the buffer.

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
[348] - posted: 2011-11-05 15:55:48
one of the new functions added is strDup.

strDup

Code:
program WIN32CUI 'test';

#include 'strings.zir'; 
#include 'console.zir';


//create our first string "My String"
char buf[32];
strAppend(@buf, 'My String', 32);


//lets duplicate our string into a new allocated buffer using strDup
char* buf2 = strDup(@buf);


//we will lunarize our second string so we can see both buffers are different.
strLunarize(buf2);


//display both our strings
print('My String:         "', @buf, '"\r\n');
print('Duplicated String: "', buf2, '"\r\n');


//duplicated buffers should be deleted with the delete macro to prevent memory leaks
delete buf2;


wait_key(nil);
ExitProcess(0);


output:
Code:
My String:         "My String"
Duplicated String: "mY StRiNg"


so here we can see that strDup will take a pointer to a string and then duplicate it into a newly allocated buffer which should be deleted with the "delete" macro when finished with. Pretty straight forward smile

it should be noted that the second buffer will only be allocated enough space to store the actual string, in this case 10 bytes.

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
[511] - posted: 2011-11-09 18:23:40
let us take a look this time at a couple of the functions available for searching strings for a substring.

strOffset + strIndexOf

Code:
program WIN32CUI 'test';

#include 'strings.zir'; 
#include 'console.zir';


char buf[64];
strAppend(@buf, 'This is my first sentence. This is the second sentence.', 64);


//let us skip past first sentence using strOffset

ecx = strOffset(@buf, '. ');
add ecx, 2                   //move past the ". "
print('str = ', ecx:string, '\r\n');


//let us check if a specific word appears in the text....
eax = strIndexOf(@buf, 'second');
if (eax <> -1) {
  print('second appears in the string\r\n');
} else {
  print('second does NOT appear in the string\r\n');
}


//and again
eax = strIndexOf(@buf, '$');
if (eax <> -1) {
  print('$ appears in the string\r\n');
} else {
  print('$ does NOT appear in the string\r\n');
}

wait_key(nil);
ExitProcess(0);


From this you can see that strOffset actually returns a pointer to the position in the string that contains the found substring, but with strIndexOf, instead it returns a 0-based index of the actual position of the sub-string start.

Code:
eax = strIndexOf('test$', '$');


eax would equal 4

we can take a look at the 0-based indexing like so:

Code:
0 t
1 e
2 s
3 t
4 $


Hope this is helpful, until next time.

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 8 user(s) online. 0 member(s) and 8 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