Raised This Month: $51 Target: $400
 12% 

Parse method


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bibu
Veteran Member
Join Date: Sep 2010
Old 02-18-2012 , 06:21   Parse method
Reply With Quote #1

What would be the difference and which one should be used?

PHP Code:
    /* 1. Method */
    
    
new szText[14], iTextLen
    read_args
(szTextsizeof(szText) - 1)
    
    
szText[sizeof(szText) - 1] = 0
    iTextLen 
strlen(szText)
        
    
szText[iTextLen 1] = 0;

    new 
szArg1[4], szArg2[3], szArg3[6]
    
parse(szText[1], szArg1sizeof(szArg1) - 1szArg2sizeof(szArg2) - 1szArg3sizeof(szArg3) - 1)
    
    
szArg1[sizeof(szArg1) - 1] = 0
    szArg2
[sizeof(szArg2) - 1] = 0
    szArg3
[sizeof(szArg3) - 1] = 0
    
    
/* 2. Method */
    
    
new szArgs[14], szArg1[4], szArg2[3], szArg3[6]
    
read_args(szArgscharsmax(szArgs))
    
remove_quotes(szArgs)
    
parse(szArgsszArg1charsmax(szArg1), szArg2charsmax(szArg2), szArg3charsmax(szArg3)) 
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
anakin_cstrike
Veteran Member
Join Date: Nov 2007
Location: Romania
Old 02-18-2012 , 09:53   Re: Parse method
Reply With Quote #2

i don't see why using 1st, pointless...
__________________

anakin_cstrike is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 02-18-2012 , 09:56   Re: Parse method
Reply With Quote #3

Quote:
Originally Posted by bibu View Post
What would be the difference...
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-18-2012 , 11:15   Re: Parse method
Reply With Quote #4

1. read_args() would return the length of the string, so that strlen() call is useless.

2. szText[sizeof(szText) - 1] = 0
That makes no sense, because it will always be 0 even without that assignment.
If you think about it, sizeof(szText) - 1 is the last index of the array, and we all know the last index of a string must be 0 to terminate it.

3. After some testing, I've found that read_args() does not always have quotes around the text.
It seems that it only does from messagemode commands (such as say).

Therefore, if you did want to go away from remove_quotes, you would do this:

Code:
    new szText[14], iStart     new iTextLen = read_args(szText, sizeof(szText) - 1)         if(iTextLen > 1 && szText[0] == '"' && szText[iTextLen - 1] == '"')     {         szText[iTextLen - 1] = 0         iStart = 1     }         new szArg1[4], szArg2[3], szArg3[6]     parse(szText[iStart], szArg1, sizeof(szArg1) - 1, szArg2, sizeof(szArg2) - 1, szArg3, sizeof(szArg3) - 1)         szArg1[sizeof(szArg1) - 1] = 0     szArg2[sizeof(szArg2) - 1] = 0     szArg3[sizeof(szArg3) - 1] = 0
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 02-18-2012 , 11:39   Re: Parse method
Reply With Quote #5

Quote:
Originally Posted by Exolent[jNr] View Post
Therefore, if you did want to go away from remove_quotes, you would do this.
Or use 2. method since it is only for messagemode.
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-18-2012 , 16:29   Re: Parse method
Reply With Quote #6

Quote:
Originally Posted by bibu View Post
Or use 2. method since it is only for messagemode.
Not exactly.
If the command is sent with quotes around it (ie. amx_test "Some string with quotes around it") then it will have quotes around it.
So you should always check for quotes with read_args()/
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Reply



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 10:40.


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