View Single Post
Author Message
Ludak
Member
Join Date: Oct 2014
Old 04-04-2020 , 14:51   String parsing problem
Reply With Quote #1

Hello!
I have ported this code from the AMXX:
PHP Code:
#include <sourcemod>

#pragma semicolon 1
#pragma newdecls required

public Plugin myinfo =  {
    
name "Test Parse"
    
author "Ludak"
    
description "Test Parse"
    
version "1.0.0"
    
url ""
};

public 
void OnPluginStart() {
    
AddCommandListener(Chat_Handle"say");
}

public 
Action Chat_Handle(int player, const char[] commandint argCommands) {
    if (
IsClientInGame(player)) {
        
char message[256];
        
        
GetCmdArgString(messagesizeof(message));
        
StripQuotes(message);
        
        if (!
strlen(message))
            return 
Plugin_Handled;
        
        if (
StrEqual(message"/parse")) {
            
PrintToChat(player"---------> Test <--------- ");
            
            
char results[12][256];
            
int number ParseTest("(some,(weird,string),list,1234,,(more,text,in,a,substring),some,more,$$$,###,@annotation)"results256);
            
            for (
int i 0numberi++)
            
PrintToChat(player"Part %d: %s"1results[i]);
            
            
PrintToChat(player"---------> Test <--------- ");
            return 
Plugin_Handled;
        }
    }
    
    return 
Plugin_Continue;
}

public 
int ParseTest(const char[] textchar[][] resultsint maxLength) {
    
int index 0;
    
int items 0;
    
int startIndex 0;
    
int len 0;
    
int parenthesesCounter 0;
    
    while (
text[index] != EOS) {
        if (
text[index] == '(')
            
parenthesesCounter++;
        
        if (
text[index] == ')')
            
parenthesesCounter--;
        
        if ((
text[index] == ',' || text[index 1] == EOS) && parenthesesCounter == 0) {
            
len index startIndex + (text[index 1] == EOS 0);
            
strcopy(results[items++], maxLength len maxLength lentext[startIndex]);
            
            
items++;
            
startIndex index 1;
        }
        
        
index++;
    }
    
    return 
items;

But the problem that it is not working, it just prints this output:

Instead of:
PHP Code:
Part 1some
Part 2
: (weird,string)
Part 3: list
Part 41234
Part 5

Part 6: (more,text,in,a,substring)
Part 7some
Part 8
more
Part 9
: $$$
Part 10###
Part 11: @annotation 
The original AMXX Code: https://forums.alliedmods.net/showpo...99&postcount=4

I do not know that is wrong with it, everything seems normal.
I have tried using '\0' instead of EOS, it does not work.
Can someone help me, thank you.
Also, it is possible to pass ArrayList by a reference and push the resulting string into it?
I am new to source pawn and programming in general.
Ludak is offline