Добро пожаловать на Pro Pawn - Портал о PAWN-скриптинге.
Страница 1 из 5 1 2 3 ... ПоследняяПоследняя
Показано с 1 по 10 из 41
  1. #1
    Аватар для urShadow
    Пользователь

    Статус
    Оффлайн
    Регистрация
    01.05.2016
    Сообщений
    44
    Репутация:
    53 ±

    Pawn.Regex - полная поддержка регулярных выражений

    Pawn.Regex 1.1.1


    Описание:
    Pawn.Regex - это плагин, который позволяет работать с регулярными выражениями.
    Почему он лучше других? Потому что позволяет получать результаты парсинга.

    Функции:
    PHP код:
    native regex:regex_new(const pattern[], E_REGEX_FLAG:flags REGEX_DEFAULTE_REGEX_GRAMMAR:grammar REGEX_ECMASCRIPT);
    native regex_delete(&regex:r);

    native regex_check(const str[], regex:rE_MATCH_FLAG:flags MATCH_DEFAULT);
    native regex_match(const str[], regex:r, &match_results:mE_MATCH_FLAG:flags MATCH_DEFAULT);
    native regex_search(const str[], regex:r, &match_results:m, &posstartpos 0E_MATCH_FLAG:flags MATCH_DEFAULT);
    native regex_replace(const str[], regex:r, const fmt[], dest[], E_MATCH_FLAG:flags MATCH_DEFAULTsize sizeof dest);

    native match_get_group(match_results:mindexdest[], &lengthsize sizeof dest);
    native match_free(&match_results:m); 
    Пример:
    PHP код:
    #include <Pawn.Regex>

    stock IsRpNickname(nickname[])
    {
        new 
    regex:regex_new("[A-Z][a-z]+_[A-Z][a-z]+");

        new 
    check regex_check(nicknamer);

        
    regex_delete(r);

        return 
    check;
    }

    public 
    OnPlayerCommandText(playeridcmdtext[])
    {
        new
            
    regex:r_with_param regex_new("\\/\\s*(\\w{1,15})\\s+(.+)"),
            
    match_results:m,
            
    cmd[16], params[256],
            
    cmd_lengthparams_length;

        if (
    regex_match(cmdtextr_with_paramm))
        {
            
    match_get_group(m1cmdcmd_length);
            
    match_get_group(m2paramsparams_length);

            
    match_free(m);
        }
        else
        {
            new 
    regex:regex_new("\\/\\s*(\\w{1,15})\\s*");

            if (
    regex_match(cmdtextrm))
            {
                
    match_get_group(m1cmdcmd_length);

                
    match_free(m);
            }

            
    regex_delete(r);
        }

        
    printf("cmd '%s' (%d), params '%s' (%d)"cmdcmd_lengthparamsparams_length);

        
    regex_delete(r_with_param);

        return 
    1;
    }

    stock SplitAndPrint(str[])
    {
        new 
    regex:regex_new("[^\\s]+");

        if (
    r)
        {
            new 
    match_results:m;
            new 
    startpospos;

            while (
    regex_search(strrmposstartpos))
            {
                new 
    word[128], length;

                if (!
    match_get_group(m0wordlength))
                {
                    break;
                }

                
    printf("word: %s"word);

                
    startpos += pos length;

                
    match_free(m);
            }

            
    regex_delete(r);
        }
    }

    stock ReplaceString(const str[], const regexp[], const fmt[], dest[], size sizeof dest)
    {
        new 
    regex:regex_new(regexp);

        if (
    r)
        {
            
    regex_replace(strrfmtdestMATCH_DEFAULTsize);

            
    regex_delete(r);
        }
    }

    main()
    {
        new 
    str[128];

        
    ReplaceString("Pawn.CMD""CMD""Regex"str);

        
    printf("%s"str);

        
    SplitAndPrint("4 8 15 16 23 42");

        
    OnPlayerCommandText(-1"/ban 42");
        
    OnPlayerCommandText(-1"/kill");

        
    printf("%d %d",
                        
    IsRpNickname("Your_Shadow"),
                        
    IsRpNickname("urShadow"));

    Changelog:
    1.0:
    - First release.
    1.1:
    - Fixed bugs.
    - Changed native "match_get_group"
    1.1.1:
    - Fixed error "File or function is not found"

    Download binaries:
    https://github.com/urShadow/Pawn.Regex/releases

    Source code:
    https://github.com/urShadow/Pawn.Regex
    Последний раз редактировалось urShadow; 09.07.2017 в 21:21.

  2. 8 пользователя(ей) сказали cпасибо:
    DeimoS (15.06.2016) Jonick (14.06.2016) Osetin (25.06.2016) Processing (14.06.2016) Salik_Davince (09.07.2017) seriu (19.06.2016) Unreal (16.06.2016) [ForD] (14.06.2016)
  3. #2
    Аватар для Daya
    Новичок

    Статус
    Оффлайн
    Регистрация
    12.06.2016
    Сообщений
    5
    Репутация:
    0 ±
    Хорошая программа, спасибо скача

  4. #3
    Аватар для ziggi
    Проверенный

    Статус
    Оффлайн
    Регистрация
    14.05.2015
    Сообщений
    1,181
    Репутация:
    790 ±
    Ошибка при компиляции на Linux. Заменил syntax_option и match_flag на std::regex_constants, тогда скомпилировалось.

     Версия GCC
    PHP код:
    └─ gcc --version
    gcc 
    (GCC6.1.1 20160602
    Copyright 
    (C2016 Free Software FoundationInc.
    This is free softwaresee the source for copying conditions.  There is NO
    warranty
    not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE



     Выдача компилятора
    PHP код:
    gcc -m32 --O3 --idirafter "lib" lib/SDK/amx/*.h
    g++ -m32 -c -O3 -w -idirafter "lib" -std=c++11 lib/SDK/*.cpp    
    g++ -m32 -c -O3 -w -idirafter "lib" -std=c++11 src/*.cpp
    src/Main.cpp: In static member function \u2018static cell Plugin::n_regex_new(AMX*, cell* \u2019:
    src/Main.cpp:94:16: error: \u2018ECMAScript\u2019 is not a member of \u2018Plugin::syntax_option {aka std::regex_constants::syntax_option_type}\u2019
           option = syntax_option::ECMAScript;
                    ^~~~~~~~~~~~~
    src/Main.cpp:97:16: error: \u2018basic\u2019 is not a member of \u2018Plugin::syntax_option {aka std::regex_constants::syntax_option_type}\u2019
           option = syntax_option::basic;
                    ^~~~~~~~~~~~~
    src/Main.cpp:100:16: error: \u2018extended\u2019 is not a member of \u2018Plugin::syntax_option {aka std::regex_constants::syntax_option_type}\u2019
           option = syntax_option::extended;
                    ^~~~~~~~~~~~~
    src/Main.cpp:103:16: error: \u2018awk\u2019 is not a member of \u2018Plugin::syntax_option {aka std::regex_constants::syntax_option_type}\u2019
           option = syntax_option::awk;
                    ^~~~~~~~~~~~~
    src/Main.cpp:106:16: error: \u2018grep\u2019 is not a member of \u2018Plugin::syntax_option {aka std::regex_constants::syntax_option_type}\u2019
           option = syntax_option::grep;
                    ^~~~~~~~~~~~~
    src/Main.cpp:109:16: error: \u2018egrep\u2019 is not a member of \u2018Plugin::syntax_option {aka std::regex_constants::syntax_option_type}\u2019
           option = syntax_option::egrep;
                    ^~~~~~~~~~~~~
    src/Main.cpp:114:16: error: \u2018icase\u2019 is not a member of \u2018Plugin::syntax_option {aka std::regex_constants::syntax_option_type}\u2019
          option |= syntax_option::icase;
                    ^~~~~~~~~~~~~
    src/Main.cpp:116:16: error: \u2018nosubs\u2019 is not a member of \u2018Plugin::syntax_option {aka std::regex_constants::syntax_option_type}\u2019
          option |= syntax_option::nosubs;
                    ^~~~~~~~~~~~~
    src/Main.cpp:118:16: error: \u2018optimize\u2019 is not a member of \u2018Plugin::syntax_option {aka std::regex_constants::syntax_option_type}\u2019
          option |= syntax_option::optimize;
                    ^~~~~~~~~~~~~
    src/Main.cpp:120:16: error: \u2018collate\u2019 is not a member of \u2018Plugin::syntax_option {aka std::regex_constants::syntax_option_type}\u2019
          option |= syntax_option::collate;
                    ^~~~~~~~~~~~~
    src/Main.cpp: In static member function \u2018static Plugin::match_flag Plugin::get_match_flag(E_MATCH_FLAG)\u2019:
    src/Main.cpp:458:12: error: \u2018match_default\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::match_default;
                ^~~~~~~~~~
    src/Main.cpp:460:12: error: \u2018match_not_bol\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::match_not_bol;
                ^~~~~~~~~~
    src/Main.cpp:462:12: error: \u2018match_not_eol\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::match_not_eol;
                ^~~~~~~~~~
    src/Main.cpp:464:12: error: \u2018match_not_bow\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::match_not_bow;
                ^~~~~~~~~~
    src/Main.cpp:466:12: error: \u2018match_not_eow\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::match_not_eow;
                ^~~~~~~~~~
    src/Main.cpp:468:12: error: \u2018match_any\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::match_any;
                ^~~~~~~~~~
    src/Main.cpp:470:12: error: \u2018match_not_null\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::match_not_null;
                ^~~~~~~~~~
    src/Main.cpp:472:12: error: \u2018match_continuous\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::match_continuous;
                ^~~~~~~~~~
    src/Main.cpp:474:12: error: \u2018match_prev_avail\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::match_prev_avail;
                ^~~~~~~~~~
    src/Main.cpp:476:12: error: \u2018format_sed\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::format_sed;
                ^~~~~~~~~~
    src/Main.cpp:478:12: error: \u2018format_no_copy\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::format_no_copy;
                ^~~~~~~~~~
    src/Main.cpp:480:12: error: \u2018format_first_only\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::format_first_only;
                ^~~~~~~~~~
    make: *** [makefile:9: all] Error 1 


    P.S. Годный плагин, наверное единственный, который не будет крэшить. Как на счёт реализации gettext? :)

  5. #4
    Аватар для Daya
    Новичок

    Статус
    Оффлайн
    Регистрация
    12.06.2016
    Сообщений
    5
    Репутация:
    0 ±
    Цитата Сообщение от ziggi Посмотреть сообщение
    Ошибка при компиляции на Linux. Заменил syntax_option и match_flag на std::regex_constants, тогда скомпилировалось.

     Версия GCC
    PHP код:
    └─ gcc --version
    gcc 
    (GCC6.1.1 20160602
    Copyright 
    (C2016 Free Software FoundationInc.
    This is free softwaresee the source for copying conditions.  There is NO
    warranty
    not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE



     Выдача компилятора
    PHP код:
    gcc -m32 --O3 --idirafter "lib" lib/SDK/amx/*.h
    g++ -m32 -c -O3 -w -idirafter "lib" -std=c++11 lib/SDK/*.cpp    
    g++ -m32 -c -O3 -w -idirafter "lib" -std=c++11 src/*.cpp
    src/Main.cpp: In static member function \u2018static cell Plugin::n_regex_new(AMX*, cell* \u2019:
    src/Main.cpp:94:16: error: \u2018ECMAScript\u2019 is not a member of \u2018Plugin::syntax_option {aka std::regex_constants::syntax_option_type}\u2019
           option = syntax_option::ECMAScript;
                    ^~~~~~~~~~~~~
    src/Main.cpp:97:16: error: \u2018basic\u2019 is not a member of \u2018Plugin::syntax_option {aka std::regex_constants::syntax_option_type}\u2019
           option = syntax_option::basic;
                    ^~~~~~~~~~~~~
    src/Main.cpp:100:16: error: \u2018extended\u2019 is not a member of \u2018Plugin::syntax_option {aka std::regex_constants::syntax_option_type}\u2019
           option = syntax_option::extended;
                    ^~~~~~~~~~~~~
    src/Main.cpp:103:16: error: \u2018awk\u2019 is not a member of \u2018Plugin::syntax_option {aka std::regex_constants::syntax_option_type}\u2019
           option = syntax_option::awk;
                    ^~~~~~~~~~~~~
    src/Main.cpp:106:16: error: \u2018grep\u2019 is not a member of \u2018Plugin::syntax_option {aka std::regex_constants::syntax_option_type}\u2019
           option = syntax_option::grep;
                    ^~~~~~~~~~~~~
    src/Main.cpp:109:16: error: \u2018egrep\u2019 is not a member of \u2018Plugin::syntax_option {aka std::regex_constants::syntax_option_type}\u2019
           option = syntax_option::egrep;
                    ^~~~~~~~~~~~~
    src/Main.cpp:114:16: error: \u2018icase\u2019 is not a member of \u2018Plugin::syntax_option {aka std::regex_constants::syntax_option_type}\u2019
          option |= syntax_option::icase;
                    ^~~~~~~~~~~~~
    src/Main.cpp:116:16: error: \u2018nosubs\u2019 is not a member of \u2018Plugin::syntax_option {aka std::regex_constants::syntax_option_type}\u2019
          option |= syntax_option::nosubs;
                    ^~~~~~~~~~~~~
    src/Main.cpp:118:16: error: \u2018optimize\u2019 is not a member of \u2018Plugin::syntax_option {aka std::regex_constants::syntax_option_type}\u2019
          option |= syntax_option::optimize;
                    ^~~~~~~~~~~~~
    src/Main.cpp:120:16: error: \u2018collate\u2019 is not a member of \u2018Plugin::syntax_option {aka std::regex_constants::syntax_option_type}\u2019
          option |= syntax_option::collate;
                    ^~~~~~~~~~~~~
    src/Main.cpp: In static member function \u2018static Plugin::match_flag Plugin::get_match_flag(E_MATCH_FLAG)\u2019:
    src/Main.cpp:458:12: error: \u2018match_default\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::match_default;
                ^~~~~~~~~~
    src/Main.cpp:460:12: error: \u2018match_not_bol\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::match_not_bol;
                ^~~~~~~~~~
    src/Main.cpp:462:12: error: \u2018match_not_eol\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::match_not_eol;
                ^~~~~~~~~~
    src/Main.cpp:464:12: error: \u2018match_not_bow\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::match_not_bow;
                ^~~~~~~~~~
    src/Main.cpp:466:12: error: \u2018match_not_eow\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::match_not_eow;
                ^~~~~~~~~~
    src/Main.cpp:468:12: error: \u2018match_any\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::match_any;
                ^~~~~~~~~~
    src/Main.cpp:470:12: error: \u2018match_not_null\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::match_not_null;
                ^~~~~~~~~~
    src/Main.cpp:472:12: error: \u2018match_continuous\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::match_continuous;
                ^~~~~~~~~~
    src/Main.cpp:474:12: error: \u2018match_prev_avail\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::match_prev_avail;
                ^~~~~~~~~~
    src/Main.cpp:476:12: error: \u2018format_sed\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::format_sed;
                ^~~~~~~~~~
    src/Main.cpp:478:12: error: \u2018format_no_copy\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::format_no_copy;
                ^~~~~~~~~~
    src/Main.cpp:480:12: error: \u2018format_first_only\u2019 is not a member of \u2018Plugin::match_flag {aka std::regex_constants::match_flag_type}\u2019
        flag |= match_flag::format_first_only;
                ^~~~~~~~~~
    make: *** [makefile:9: all] Error 1 


    P.S. Годный плагин, наверное единственный, который не будет крэшить. Как на счёт реализации gettext? :)
    Ты тут покажи версия G++, тут же си++ а не обычный си чеовек, у мене все роаботает.


    Последний раз редактировалось Daya; 14.06.2016 в 12:42. Причина: хах!

  6. #5
    Аватар для urShadow
    Пользователь

    Статус
    Оффлайн
    Регистрация
    01.05.2016
    Сообщений
    44
    Репутация:
    53 ±
    Успешно компилировал на этой версии:
    PHP код:
    g++ (Ubuntu 4.9.3-8ubuntu2~14.044.9.3
    Copyright 
    (C2015 Free Software FoundationInc.
    This is free softwaresee the source for copying conditions.  There is NO
    warranty
    not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
    Цитата Сообщение от ziggi Посмотреть сообщение
    Как на счёт реализации gettext? :)
    Функция match_get_group же. Подробнее в примере.

  7. #6
    Аватар для ziggi
    Проверенный

    Статус
    Оффлайн
    Регистрация
    14.05.2015
    Сообщений
    1,181
    Репутация:
    790 ±
    Цитата Сообщение от Daya Посмотреть сообщение
    Ты тут покажи версия G++, тут же си++ а не обычный си чеовек, у мене все роаботает.


    GCC уже давно не только Си, а g++ - это лишь GCC запущенный с параметром -lstdc++.

     g++ --version
    └─ $ g++ --version
    g++ (GCC) 6.1.1 20160602
    Copyright (C) 2016 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions. There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


    Цитата Сообщение от urShadow Посмотреть сообщение
    Успешно компилировал на этой версии:
    PHP код:
    g++ (Ubuntu 4.9.3-8ubuntu2~14.044.9.3
    Copyright 
    (C2015 Free Software FoundationInc.
    This is free softwaresee the source for copying conditions.  There is NO
    warranty
    not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
    Эта ветка датируется 2014 годом, моя собрана в этом месяце, видимо за это время прошло много изменений. Я не знаток C++, но если судить по этой странице, то все эти константы находятся как-раз в области видимости regex_constants. Да и ниже, в Class std::regex, показано то, как они объявляются:
    PHP код:
    static constexpr regex_constants::syntax_option_type
            icase 
    regex_constants::icase
    То есть эти константы запрашивают именно из std::regex_constants, а не из std::regex_constants::syntax_option_type.
    Поэтому то, что оно компилируется на 4.9 - это скорее ошибка компилятора, чем возможность языка.

    Цитата Сообщение от urShadow Посмотреть сообщение
    Функция match_get_group же. Подробнее в примере.
    Да не, я про реализацию GNU gettext в виде плагина, ибо для SA-MP'а ещё нет нормальных систем для создания мультиязычности.
    Последний раз редактировалось ziggi; 14.06.2016 в 13:19.

  8. 4 пользователя(ей) сказали cпасибо:
    Nash_Brigers (14.06.2016) Osetin (25.06.2016) urShadow (14.06.2016) [ForD] (14.06.2016)
  9. #7
    Аватар для urShadow
    Пользователь

    Статус
    Оффлайн
    Регистрация
    01.05.2016
    Сообщений
    44
    Репутация:
    53 ±
    Благодарю, исправил.

    Цитата Сообщение от ziggi Посмотреть сообщение
    Да не, я про реализацию GNU gettext в виде плагина, ибо для SA-MP'а ещё нет нормальных систем для создания мультиязычности.
    Записал. В будущем может быть реализую.

  10. #8
    Аватар для vovandolg
    Пользователь

    Статус
    Оффлайн
    Регистрация
    17.11.2015
    Адрес
    Stavropol
    Сообщений
    1,369
    Репутация:
    113 ±
     На одни и те же грабли)
    Цитата Сообщение от urShadow Посмотреть сообщение
    Pawn.Regex - плагин,
    Опять .so приписывать))
    [Anticheat]___Invisible Fly Hack
    [Anticheat]____Weapon/Ammo Hack
    [Function]______ResetPlayerWeaponSlot
    [Function]_______FIX_SetPlayerAmmo
    [ServerMod]______TDM | Zombie Apokalypse

  11. #9
    Аватар для urShadow
    Пользователь

    Статус
    Оффлайн
    Регистрация
    01.05.2016
    Сообщений
    44
    Репутация:
    53 ±
    Ты на название бинарника-то посмотри сначала.

  12. Пользователь сказал cпасибо:
    vovandolg (14.06.2016)
  13. #10
    Аватар для urShadow
    Пользователь

    Статус
    Оффлайн
    Регистрация
    01.05.2016
    Сообщений
    44
    Репутация:
    53 ±
    Обновлено до версии 1.1.

  14. Пользователь сказал cпасибо:
    seriu (04.07.2016)
 

 
Страница 1 из 5 1 2 3 ... ПоследняяПоследняя

Информация о теме

Пользователи, просматривающие эту тему

Эту тему просматривают: 1 (пользователей: 0 , гостей: 1)

Ваши права

  • Вы не можете создавать новые темы
  • Вы не можете отвечать в темах
  • Вы не можете прикреплять вложения
  • Вы не можете редактировать свои сообщения
  •