@param string $buf

@return bool

@throws CasbinException
355861
private function parseBuffer($buf)
    {
        $section = null;
        $lineNum = 0;
        $buffer = '';
        $canWrite = null;

        $buf = preg_replace('/[\r\n]+/', PHP_EOL, $buf);
        $buf = explode(PHP_EOL, $buf);

        for ($i = 0; $i <= \count($buf); ++$i) {
            if ($canWrite) {
                $this->write($section, $lineNum, $buffer);
                $canWrite = false;
            }

            ++$lineNum;
            $line = isset($buf[$i]) ? $buf[$i] : '';
            if ($i == \count($buf)) {
                if (\strlen($buffer) > 0) {
                    $this->write($section, $lineNum, $buffer);
                }

                break;
            }
            $line = trim($line);

            if ('' == $line || self::DEFAULT_COMMENT == substr($line, 0, 1) || self::DEFAULT_COMMENT_SEM == substr($line, 0, 1)) {
                $canWrite = true;

                continue;
            } elseif ('[' == substr($line, 0, 1) && ']' == substr($line, -1)) {
                if (\strlen($buffer) > 0) {
                    $this->write($section, $lineNum, $buffer);
                    $canWrite = false;
                }
                $section = substr($line, 1, -1);
            } else {
                $p = '';
                if (self::DEFAULT_MULTI_LINE_SEPARATOR == substr($line, -1)) {
                    $p = trim(substr($line, 0, -1));
                } else {
                    $p = $line;
                    $canWrite = true;
                }
                $buffer .= $p;
            }
        }

        return true;
    }
381272
public static function conf($conf = null) {
        if (null !== $conf) {
            if (is_array($conf)) {
                Toolkit::override(static::$_conf, $conf);
                return static::$_conf;
            }

            if (is_string($conf)) {
                return static::$_conf[$conf] ?? null;
            }
        }
        if (!static::$_confObject instanceof stdClass) {
            /** @noinspection ReturnNullInspection */
            static::$_confObject = json_decode(json_encode(static::$_conf));
        }
        return static::$_confObject;
    }
419620
public static boolean isText(ByteBuf buf, Charset charset) {
        return isText(buf, buf.readerIndex(), buf.readableBytes(), charset);
    }
69454
public static boolean isWhiteSpace(StringBuffer buf)
  {

    int n = buf.length();

    for (int i = 0; i < n; i++)
    {
      if (!isWhiteSpace(buf.charAt(i)))
        return false;
    }

    return true;
  }
12584
private function _createDBFFile()
    {
        if (! self::supportsDbase() || ! is_array($this->DBFHeader) || count($this->DBFHeader) == 0) {
            $this->DBFFile = null;

            return true;
        }
        $dbf_name = $this->_getFilename('.dbf');

        /* Unlink existing file */
        if (file_exists($dbf_name)) {
            unlink($dbf_name);
        }

        /* Create new file */
        $this->DBFFile = @dbase_create($dbf_name, $this->DBFHeader);
        if ($this->DBFFile === false) {
            $this->setError(sprintf('It wasn\'t possible to create the DBase file "%s"', $dbf_name));

            return false;
        }

        return true;
    }
213627
public function write($buf)
    {
        if (!$this->isOpen()) {
            throw new TTransportException('transport is closed');
        }

        $ok = @socket_write($this->socket, $buf);
        if ($ok === false) {
            throw new TTransportException('socket_write failed');
        }
    }
264231
public function isDummyValue($cpf)
    {
        return (
            $cpf == '00000000000' ||
            $cpf == '11111111111' ||
            $cpf == '22222222222' ||
            $cpf == '33333333333' ||
            $cpf == '44444444444' ||
            $cpf == '55555555555' ||
            $cpf == '66666666666' ||
            $cpf == '77777777777' ||
            $cpf == '88888888888' ||
            $cpf == '99999999999'
        );
    }
1066534
public function forceSwitch($dbHost, $dbName, $dbUser, $dbPassword, array $dbOptions = array())
    {
        if ($this->getSession()->has(self::SESSION_CONNECTION_KEY)) {
            $current = $this->getSession()->get(self::SESSION_CONNECTION_KEY);
            if ($current[self::PARAM_HOST] === $dbHost && $current[self::PARAM_DATABASE] === $dbName) {
                return false;
            }
        }

        $this->getSession()->set(self::SESSION_CONNECTION_KEY, array(
            self::PARAM_DRIVER_OPTIONS => $dbOptions,
            self::PARAM_HOST           => $dbHost,
            self::PARAM_DATABASE       => $dbName,
            self::PARAM_USER           => $dbUser,
            self::PARAM_PASSWORD       => $dbPassword,
        ));

        if ($this->isConnected()) {
            $this->close();
        }

        return true;
    }
224388
public static function decodeUnsigned(string $buf, int &$x): int
    {
        $x = 0;
        $s = 0;
        for ($i = 0; $i < strlen($buf); $i++) {
            $b = ord($buf[$i]);
            if ($b < 0x80) {
                if ($i > 9 || $i == 9 && $b > 1) {
                    // overflow
                    $x = 0;
                    return -($i + 1);
                }
                $x = $x | $b << $s;
                return $i + 1;
            }
            $x |= ($b & 0x7f) << $s;
            $s += 7;
        }
        $x = 0;
        return 0;
    }
1350968
public static void recycle(@NotNull ByteBuf buf) {
		int slab = 32 - numberOfLeadingZeros(buf.array.length - 1);
		ByteBufConcurrentStack stack = slabs[slab];
		stack.push(buf);
	}
1066182
public function endTransaction($commit)
    {
        if ($commit) {
            $result = $this->commit();
        } else {
            $result = $this->rollback();
        }

        switch ($this->mode) {

            case "mysql":
                if (!$this->server->autocommit(true)) {
                    $result = false;
                }
                break;

            case "postgres":
                $result = $this->query("SET AUTOCOMMIT = ON");
                break;

            case "redshift":
                # Do nothing, and use the result from the commit/rollback
                break;

            case "odbc":
                if (!odbc_autocommit($this->server, true)) {
                    $result = false;
                }
                break;

            default:
                throw new \Exception("endTransaction() not supported in this mode (" . $this->mode . ")");
        }

        if (!$result) {
            $this->error();
        }

        $this->transaction = false;

        return true;
    }
783772
public static function isValidCif(string $cif): bool
    {
        if (!preg_match(self::CIF_REGEX, $cif, $matches)) {
            return false;
        }

        return self::isValidNifCheck($cif, $matches);
    }
1277483
public function hasNodeRef(NodeRef $nodeRef): bool
    {
        if (null === $this->getNodeBatchRequest) {
            return false;
        }

        return $this->getNodeBatchRequest->isInSet('node_refs', $nodeRef);
    }
995421
public function _($string, $jsSafe = false)
	{
		//$key = str_replace( ' ', '_', strtoupper( trim( $string ) ) );echo '<br />'.$key;
        $key = strtoupper($string);
		$key = (substr($key, 0, 1) === '_') ? substr($key, 1) : $key;

		if (isset($this->_strings[$key])) {

            $string = $this->_debug ? "&bull;".$this->_strings[$key]."&bull;" : $this->_strings[$key];

            if ($this->_debug) {
                $caller = $this->_getCallerInfo();

                if (!array_key_exists($key, $this->_used)) {
					$this->_used[$key] = array();
				}

				$this->_used[$key][] = $caller;
			}

		} else {

            if (defined($string)) {

                $string = $this->_debug ? '!!'.constant($string).'!!' : constant($string);

				// Store debug information
				if ( $this->_debug ) {
                    $caller = $this->_getCallerInfo();

					if (!array_key_exists($key, $this->_used)) {
						$this->_used[$key] = array();
					}

					$this->_used[$key][] = $caller;
				}

			} elseif ($this->_debug) {

                $caller	= $this->_getCallerInfo();
				$caller['string'] = $string;

				if(!array_key_exists($key, $this->_orphans)) {
					$this->_orphans[$key] = array();
				}

				$this->_orphans[$key][] = $caller;
				$string = '??'.$string.'??';
			}
		}

		if ($jsSafe) {
			$string = addslashes($string);
		}

		return $string;
	}
1243499
public static function existsKphpDB($dbid)
	{
		if(!self::$_started)
		{
			self::addDebug("KeepassPHP is not started!");
			return false;
		}
		return self::$_kphpdbManager->existsKey($dbid);
	}
362931
public static function decodeSigned(string $buf, int &$x): int
    {
        $ux = 0;
        $cnt = self::decodeUnsigned($buf, $ux);
        $x = $ux >> 1;
        if ($ux&1 != 0) {
            $x = ~$x;
        }
        return $cnt;
    }
1090365
public function isWebSocket($fdinfo)
    {
        if (empty($fdinfo)) {
            throw new \Exception('fd not exist');
        }
        if (array_key_exists('websocket_status', $fdinfo) && $fdinfo['websocket_status'] == WEBSOCKET_STATUS_FRAME) {
            return $fdinfo['server_port'];
        }
        return false;
    }