GString - работа со строками

Добавлен , не публикуется
Библиотека которая позволяет отслеживать события в чате, к примеру:
/exp xx
/godmode=on
Blablabla
Все это делает система GString
Инструкция по использованию
RegisterPlayerToChat
Добавляет игрока в систему(аналог TriggerRegisterPlayerChatEvent...)
Пример:
-- RegisterPlayerToChat(player)
-- RegisterPlayerToChat(Player(0))
player - игрок
RegisterNewCmd
Регистрирует новое событие чата в котором можно отследить какую то часть текста
Пример:
-- RegisterNewCmd(current_string,length,min,max,select_string,"namefunc")
-- RegisterNewCmd("my_string",10,0,10,"my_string","my_func")
-- RegisterNewCmd("my_string",10,10,12,"on","my_func")
current_string - полное название слова которое должно отслеживаться в чате
length - длина слова
min,max,select_string - чем то схожа с SubString(string,start,end)
"namefunc" - название функции, которая вызывается после успешного отслеживания
FlushCmd
Очищает заданное событие чата
Пример:
-- FlushCmd(current_string)
-- FlushCmd("my string")
current_string - полное название слова которое было задано для отслежки в чате
FlushCmdEx
Очищает заданное событие чата
Пример:
-- FlushCmd(box_id)
-- FlushCmd(4)
box_id - Номер ячейки события
GetCmd_id
Пример:
-- GetCmd_id(current_string)
-- GetCmd_id("my string")
Вернет в integer номер ячейки
current_string - полное название слова которое было задано для отслежки в чате
GetFinishString
Пример:
-- GetFinishString(current_string)
-- local string s = GetFinishString("my string")
Вернет в string ваш отрезок текста который установлен в параметрах
current_string - полное название слова которое было задано для отслежки в чате
GetFinishStringEx
Пример:
-- GetFinishString(box_id)
-- local string s = GetFinishString(4)
Вернет в string ваш отрезок текста который установлен в параметрах
box_id - Номер ячейки события
library GString

    //cJASS

    ///////////////////////////////////////
    // by Goodie© 2013
    //Инструкция по использованию
    /////////////////////////////////////
    //
    //  RegisterPlayerToChat
    //  Добавляет игрока в систему(аналог  TriggerRegisterPlayerChatEvent...)
    //  Пример: RegisterPlayerToChat(player)
    //                 RegisterPlayerToChat(Player(0))
    //  player - игрок 
    //
    /////////////////////////////////////
    //
    //  RegisterNewCmd
    //  Регистрирует новое событие чата в котором можно отследить какую то часть текста
    //  Пример: RegisterNewCmd(current_string,length,min,max,select_string,"namefunc")
    //                 RegisterNewCmd("my_string",10,0,10,"my_string","my_func")
    //                 RegisterNewCmd("my_string",10,10,12,"on","my_func")
    //  current_string - полное название слова которое должно отслеживаться в чате
    //  length - длина слова
    //  min,max,select_string - чем то схожа с SubString(string,start,end)
    //  "namefunc" - название функции,которая вызывается после успешного отслеживания
    //
    ////////////////////////////////////
    //  
    //  FlushCmd
    //  Очищает заданное событие чата
    //  Пример: FlushCmd(current_string)
    //                 FlushCmd("my string")
    //  current_string - полное название слова которое было задано для отслежки в чате
    //  
    ////////////////////////////////////
    //  
    //  FlushCmdEx
    //  Очищает заданное событие чата
    //  Пример: FlushCmd(box_id)
    //                 FlushCmd(4)
    //  box_id - Номер ячейки события
    //  
    ////////////////////////////////////
    //  
    //  GetCmd_id
    //  
    //  Пример: GetCmd_id(current_string)
    //                 GetCmd_id("my string")
    //  Вернет в integer номер ячейки 
    //  current_string - полное название слова которое было задано для отслежки в чате
    //  
    ////////////////////////////////////
    //  
    //  GetFinishString
    //  
    //  Пример: GetFinishString(current_string)
    //                 local string s = GetFinishString("my string")
    //  Вернет в string ваш отрезок текста который установлен в параметрах
    //  current_string - полное название слова которое было задано для отслежки в чате
    //
    ///////////////////////////////////////
    //  
    //  GetFinishStringEx
    //  
    //  Пример: GetFinishString(box_id)
    //                 local string s = GetFinishString(4)
    //  Вернет в string ваш отрезок текста который установлен в параметрах
    //  box_id - Номер ячейки события
    //  
    ///////////////////////////////////////
    
    define 
    {
        // call functions
        RegisterPlayerToChat(p) = TriggerRegisterPlayerChatEvent(EventChatTrigger,p,"",false)
        RegisterNewCmd(c1, a, b, c, c2, name_func) = EventChat.add_cmd(c1,a,b,c,c2,name_func)
        FlushCmd(c1) = EventChat.flush_cmd(c1)
        FlushCmdEx(c2) = EventChat.flush_cmdEx(c2)
        GetCmd_id(c1) = EventChat.get_id(c1)
        GetFinishString(c1) = EventChat.get_select(c1)
        GetFinishStringEx(c1) = EventChat.get_selectEx(c1)
        // Max numbers of boxes
        private MAX_SIZE = 0x1000
        private GSTRING_DEBUG = false  // enable debug?  
        // Other...
        private get_line(a,b,c) = (SubString(event_string,a,b) == c)
        private event_chat(a) = (event_string == a)
        private get_length(a) = (Length == a)
        private next =data.id+=0x01
        private prev =data.id-=0x01
        private g_break = exitwhen true
        private g_debug(s) =
        { 
        #if (GSTRING_DEBUG==true)
            BJDebugMsg(s)
        #endif
        }
    }
        
    trigger EventChatTrigger = CreateTrigger()
    private StringData data
    private string empty_string = ""
    
    struct StringData
    {
        string current_string[MAX_SIZE] , select_string[MAX_SIZE]
        int length[MAX_SIZE],min[MAX_SIZE] , max[MAX_SIZE]
        string callfunc[MAX_SIZE]
        static int id = 0x00
    }
    
    struct EventChat
    
        static string event_string = null
        static int Length = 0x00
        
        static bool line(string c1,int a,int b,int c,string c2)
        { return (event_chat(c1) or get_length(a)) and (get_line(b,c,c2)) }
    
        static bool condition()
        {
            event_string = GetEventPlayerChatString()
            Length = StringLength(event_string)
            int index = 0x00
            do
                {
                if (line(data.current_string[index],\
                            data.length[index],\
                            data.min[index],\
                            data.max[index],\
                            data.select_string[index]))
                {
                    if (data.callfunc[index] != empty_string)
                    {
                        ExecuteFunc(data.callfunc[index])
                        g_debug("|G_String Sys| - call in cell #" + I2S(index) +  " - " + data.callfunc[index])
                    else
                        g_debug("|G_String Sys| - in cell #" + I2S(index) +  " no function")
                    }
                }
                index+=0x01
            }whilenot(index > data.id)
            return false
        }
        
        static bool add_cmd(string c1,int a,int b,int c,string c2,string name_func)
        {
            if (data.id >= MAX_SIZE)
            {
                g_debug("|G_String Sys[ERROR]| - SIZE are full")
                return false
            else
                data.current_string[data.id] = c1
                data.select_string[data.id] = c2
                data.length[data.id] = a
                data.min[data.id] = b
                data.max[data.id] = c
                data.callfunc[data.id] = name_func
                g_debug("|G_String Sys| - box #" + I2S(data.id))
                next
            }
            return true
        }
                
        static bool flush_cmd(string c1)
        {   
        int index = 0x00
        do
            {
                if (data.current_string[index] == c1)
                {
                    data.current_string[index] = empty_string
                    data.select_string[index] = empty_string
                    data.length[index] = 0x00
                    data.min[index] = 0x00
                    data.max[index] = 0x00
                    data.callfunc[index] = empty_string
                    g_debug("|G_String Sys| - " +c1 + " - flushed")
                    g_break
                else
                    g_debug("|G_String Sys[ERROR]| - " + c1 + " has not data!")
                    g_break
                    return false
                }
                index+=0x01
            }whilenot(index > data.id)
            return true
        }
        
        static bool flush_cmdEx(int index)
        {   
            if (data.current_string[index] != empty_string) and\
                (data.length[index] != 0x00) and\
                (data.min[index] != 0x00) and\
                (data.max[index] != 0x00) and\
                (data.select_string[index] != empty_string) and\
                (data.callfunc[index] != empty_string)
                {
                    data.current_string[index] = empty_string
                    data.select_string[index] = empty_string
                    data.length[index] = 0x00
                    data.min[index] = 0x00
                    data.max[index] = 0x00
                    data.callfunc[index] = empty_string
                    g_debug("|G_String Sys| - box #" + I2S(index) + " - flushed")
                else
                    g_debug("|G_String Sys[ERROR]| - box #" + I2S(index) + " has not data!")
                    return false
                }
            return true
        }
        
        static int get_id(string c1)
        {
            int index = 0x00
            do{if(data.current_string[index] == c1){g_break};index+=0x01}whilenot(index > data.id)
            g_debug("|G_String Sys[| - box #" + I2S(index))
            return index
        }
        
        static string get_selectEx(int index)
        {
            g_debug("|G_String Sys[| - box #" + I2S(index) + " - " + data.select_string[index])
            return data.select_string[index]
        }
        
        static string get_select(string c1)
        {
            int index = 0x00
            do{if(data.select_string[index] == c1){g_break};index+=0x01}whilenot(index > data.id)
            return data.select_string[index]
        }
        
        static void onInit()
        {
            data = StringData.create()
            TriggerAddCondition(EventChatTrigger,function thistype.condition)
        }
        
    endstruct
        
endlibrary
`
ОЖИДАНИЕ РЕКЛАМЫ...