The following warnings occurred:
Warning [2] Use of undefined constant SAPI_NAME - assumed 'SAPI_NAME' (this will throw an Error in a future version of PHP) - Line: 3388 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3388 errorHandler->error
/showthread.php 116 build_archive_link
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/inc/functions.php 3324 build_forum_breadcrumb
/showthread.php 195 build_forum_breadcrumb
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/showthread.php 195 build_forum_breadcrumb






Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOURCE] STRTOKEN
Author Message
xwerswoodx
Journeyman
*

Posts: 86
Likes Given: 4
Likes Received: 7 in 4 posts
Joined: Jun 2012
Reputation: 0

UoMMO

Post: #1
[SOURCE] STRTOKEN
Addes STRTOKEN function to sphere;

Usage: <STRTOKEN text,n,seperator>

<STRTOKEN a.b.c.d.e,3,.> returns c
<STRTOKEN a.b.c.d.e,0,.> returns 5
<STRTOKEN a.b.c.d.e,6,.> returns null

You can also specify a range of tokens:
<STRTOKEN a.b.c.d.e,2-,.> returns 2nd token onwards = b.c.d.e
<STRTOKEN a.b.c.d.e,2-4,.> returns tokens 2 through 4 = b.c.d

Installation;
Note: Please backup your files before starting to edit.

Open File: src/common/CScriptObj.cpp

find:
Code:
        case SSC_EXPLODE:

add before:
Code:
        case SSC_StrToken:
            {
                TCHAR * ppArgs[3];
                size_t iQty = Str_ParseCmds(const_cast<TCHAR *>(pszKey), ppArgs, COUNTOF(ppArgs), ",");
                if ( iQty < 3 )
                    return false;

                if ( *ppArgs[2] == '"' )
                   ppArgs[2]++;
                
                for (TCHAR * pEnd = ppArgs[2] + strlen(ppArgs[2]) - 1; pEnd >= ppArgs[2]; pEnd--)
                {
                    if ( *pEnd == '"' )
                    {
                        *pEnd = '\0';
                        break;
                    }
                }
                TCHAR * iSep = ppArgs[2];
                for (TCHAR *iSeperator = ppArgs[2] + strlen(ppArgs[2]) - 1; iSeperator > ppArgs[2]; iSeperator--)
                    *iSeperator = '\0';

                if ( *ppArgs[0] == '"' )
                    ppArgs[0]++;
                for (TCHAR * pEnd = ppArgs[0] + strlen(ppArgs[0]) - 1; pEnd >= ppArgs[0]; pEnd--)
                {
                    if ( *pEnd == '"' )
                    {
                        *pEnd = '\0';
                        break;
                    }
                }

                sVal = "";
                TCHAR *ppCmd[255];
                size_t count = Str_ParseCmds(ppArgs[0], ppCmd, COUNTOF(ppCmd), iSep);

                TCHAR * ppArrays[2];
                size_t iArrays = Str_ParseCmds(ppArgs[1], ppArrays, COUNTOF(ppArrays), "-");
                INT64    iValue = Exp_GetVal(ppArgs[1]);
                INT64     iValueEnd = iValue;
                
                if (iArrays > 1)
                {
                    iValue = Exp_GetVal(ppArrays[0]);
                    iValueEnd = Exp_GetVal(ppArrays[1]);
                    if (iValueEnd <= 0 || iValueEnd > count)
                        iValueEnd = count;                    
                }
                
                if (iValue < 0)
                    return false;
                else if (iValue > 0)
                {
                    if (iValue > count)
                        return false;
                    else if (iValue == iValueEnd)
                        sVal = ppCmd[iValue - 1];
                    else
                    {
                        sVal.Add(ppCmd[iValue - 1]);
                        INT64 i = iValue + 1;
                        for ( ; i <= iValueEnd; i++)
                        {
                            sVal.Add(iSep);
                            sVal.Add(ppCmd[i - 1]);
                        }
                    }
                }
                else
                    sVal.FormatVal(static_cast<long>(count));
            }
            return true;

Open File: src/tables/CScriptObj_functions.tbl

find:
Code:
ADD(StrSub,            "StrSub")

add after:
Code:
ADD(StrToken,        "StrToken")
(This post was last modified: 06-01-2017 08:33 AM by xwerswoodx.)
02-16-2017 03:15 AM
Find all posts by this user Like Post Quote this message in a reply
[+] 4 users Like xwerswoodx's post
rastrero
Master
**

Posts: 250
Likes Given: 41
Likes Received: 28 in 24 posts
Joined: Jan 2016
Reputation: 3



Post: #2
RE: [SOURCE] STRTOKEN
Oh its so nice... But I cant imagine why do u need this. Can you give me an example?
03-04-2017 05:08 AM
Find all posts by this user Like Post Quote this message in a reply
[+] 1 user Likes rastrero's post
xwerswoodx
Journeyman
*

Posts: 86
Likes Given: 4
Likes Received: 7 in 4 posts
Joined: Jun 2012
Reputation: 0

UoMMO

Post: #3
RE: [SOURCE] STRTOKEN
Sorry for late answer I saw your message now, basically, it lets you to seperate sentences with commas.

For example:
If you have string "1,000 2,000 3,000" and you want to get 2,000 you can use <STRTOKEN "1,000 2,000 3,000",2," ">.

For example if you have in-game forum like me, you can censor swearing words with strtoken but explode overrides commas so it's not possible if sentence has commas or if there are 6-7 commas you can use for/while to check everystring inside commas to do it.

Code:
[FUNCTION DIFF]
SERV.LOG ARGS: <ARGV[2]>
SERV.LOG STRTOKEN: <STRTOKEN "<ARGS>",3," ">
ARGS=<EXPLODE " ",<ARGS>>
SERV.LOG EXPLODE: <ARGV[2]>

23:40:'xwerswoodx' commands 'diff 1,000 2,000 5,000 100,000 9,000'=1
23:40:(insurance.scp,2)ARGS: 000 5
23:40:(insurance.scp,3)STRTOKEN: 5,000
23:40:(insurance.scp,5)EXPLODE: 2
(This post was last modified: 06-02-2017 08:17 AM by xwerswoodx.)
06-01-2017 03:07 AM
Find all posts by this user Like Post Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)