This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

[REQ] Empty()


  
 
 
Thread Tools Display Modes
Author Message
P34nut
AMX Mod X Beta Tester
Join Date: Feb 2006
Location: Netherlands
Old 05-21-2006 , 07:21   [REQ] Empty()
#1

Please add empty() native..

this function checks if a string is empty(like in PHP)
__________________
All you need to change the world is one good lie and a river of blood
P34nut is offline
Greenberet
AMX Mod X Beta Tester
Join Date: Apr 2004
Location: Vienna
Old 05-21-2006 , 07:26  
#2

Code:
stock bool:empty( str[] ) {         return str[0] ? false : true; }
you just have to check if the first character is 0, then it is empty
Greenberet is offline
Send a message via ICQ to Greenberet Send a message via MSN to Greenberet
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 05-21-2006 , 11:02  
#3

Quote:
Originally Posted by Greenberet
Code:
stock bool:empty( str[] ) {         return str[0] ? false : true; }
you just have to check if the first character is 0, then it is empty
not always, especially when dealing with NULL terminated strings returned in a socket request. not even equal(str,"") would pick that up correctly though, not sure that anything would. When querying servers using sockets you get stuff back like this.

Code:
kingpin hosted server\0de_dust\0cstrike
\0 == null == false

So a string could start out with \0 and still have content after it, but it is not very likely.
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181
Greenberet
AMX Mod X Beta Tester
Join Date: Apr 2004
Location: Vienna
Old 05-21-2006 , 11:30  
#4

strings are null terminated
your version is just a line of bytes...
Greenberet is offline
Send a message via ICQ to Greenberet Send a message via MSN to Greenberet
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 05-21-2006 , 15:44  
#5

Quote:
Originally Posted by Greenberet
strings are null terminated
your version is just a line of bytes...
I know what I'm talking about, that was just an example. But it is rare to encounter such a string.
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181
BAILOPAN
Join Date: Jan 2004
Old 05-21-2006 , 15:48  
#6

Greenberet is correct, such a native (even as a stock) is redundant/inefficient.

Just check if the first cell is 0.
__________________
egg
BAILOPAN is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:17.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode