HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: //usr/share/swig4.0/python/std_string_view.i
/* -----------------------------------------------------------------------------
 * std_string_view.i
 *
 * SWIG typemaps for std::string_view types
 * ----------------------------------------------------------------------------- */

%include <exception.i>

%{
#include <string_view>

#if PY_VERSION_HEX < 0x03000000
# error std_string_view.i not supported for Python 2
#endif
%}

namespace std {

    %naturalvar string_view;

    class string_view;

    %typemap(typecheck,precedence=SWIG_TYPECHECK_STRINGVIEW) string_view, const string_view & %{
#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
        $1 = PyBytes_Check($input);
#else
        $1 = PyUnicode_Check($input) || PyBytes_Check($input);
#endif
    %}

    %typemap(in) string_view (PyObject *bytes = NULL) %{
        Py_ssize_t len;
#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
        const char *p = PyBytes_AsString($input);
        if (!p) SWIG_fail;
        len = PyBytes_Size($input);
#else
        const char *p;
        if (PyUnicode_Check($input)) {
          p = SWIG_PyUnicode_AsUTF8AndSize($input, &len, &bytes);
          if (!p) SWIG_fail;
        } else {
          p = PyBytes_AsString($input);
          if (!p) SWIG_fail;
          len = PyBytes_Size($input);
        }
#endif
        $1 = std::string_view(p, len);
    %}

    %typemap(freearg) string_view %{
        Py_XDECREF(bytes$argnum);
    %}

    %typemap(in) const string_view & ($*1_ltype temp, PyObject *bytes = NULL) %{
        Py_ssize_t len;
#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
        const char *p = PyBytes_AsString($input);
        if (!p) SWIG_fail;
        len = PyBytes_Size($input);
#else
        const char *p;
        if (PyUnicode_Check($input)) {
          p = SWIG_PyUnicode_AsUTF8AndSize($input, &len, &bytes);
          if (!p) SWIG_fail;
        } else {
          p = PyBytes_AsString($input);
          if (!p) SWIG_fail;
          len = PyBytes_Size($input);
        }
#endif
        temp = std::string_view(p, len);
        $1 = &temp;
    %}

    %typemap(freearg) const string_view & %{
        Py_XDECREF(bytes$argnum);
    %}

    %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) string_view {
        Py_ssize_t len;
%#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
        const char *p = PyBytes_AsString($input);
        if (p) len = PyBytes_Size($input);
%#else
        const char *p;
        PyObject *bytes = NULL;
        if (PyUnicode_Check($input)) {
          p = SWIG_PyUnicode_AsUTF8AndSize($input, &len, &bytes);
          // Avoid undefined behaviour (p will be pointing to a temporary
          // if bytes is not NULL which happens when Py_LIMITED_API is defined
          // and < 0x030A0000) and just leak by not calling Py_XDECREF.
          // Py_XDECREF(bytes);
        } else {
          p = PyBytes_AsString($input);
          if (p) len = PyBytes_Size($input);
        }
%#endif
        if (p) $result = std::string_view(p, len);
    }


    %typemap(out) string_view %{
#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
        $result = PyBytes_FromStringAndSize($1.data(), $1.size());
#else
        $result = PyUnicode_FromStringAndSize($1.data(), $1.size());
#endif
    %}

    %typemap(varout) string_view %{
#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
        $result = PyBytes_FromStringAndSize($1.data(), $1.size());
#else
        $result = PyUnicode_FromStringAndSize($1.data(), $1.size());
#endif
    %}

    %typemap(directorin) string_view, const string_view & %{
#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
        $input = PyBytes_FromStringAndSize($1.data(), $1.size());
#else
        $input = PyUnicode_FromStringAndSize($1.data(), $1.size());
#endif
    %}

    %typemap(out) const string_view & %{
#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
        $result = PyBytes_FromStringAndSize($1->data(), $1->size());
#else
        $result = PyUnicode_FromStringAndSize($1->data(), $1->size());
#endif
    %}

}