You are here

public static function ParagonIE_Sodium_Core_Util::substr in Automatic Updates 8

Same name and namespace in other branches
  1. 7 vendor/paragonie/sodium_compat/src/Core/Util.php \ParagonIE_Sodium_Core_Util::substr()

Safe substring

@internal You should not use this directly from another application

@ref mbstring.func_overload

Parameters

string $str:

int $start:

int $length:

Return value

string

Throws

TypeError

108 calls to ParagonIE_Sodium_Core_Util::substr()
ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt in vendor/paragonie/sodium_compat/src/Compat.php
Authenticated Encryption with Associated Data: Decryption
ParagonIE_Sodium_Compat::crypto_kx_client_session_keys in vendor/paragonie/sodium_compat/src/Compat.php
ParagonIE_Sodium_Compat::crypto_kx_publickey in vendor/paragonie/sodium_compat/src/Compat.php
ParagonIE_Sodium_Compat::crypto_kx_secretkey in vendor/paragonie/sodium_compat/src/Compat.php
ParagonIE_Sodium_Compat::crypto_kx_server_session_keys in vendor/paragonie/sodium_compat/src/Compat.php

... See full list

File

vendor/paragonie/sodium_compat/src/Core/Util.php, line 799

Class

ParagonIE_Sodium_Core_Util
Class ParagonIE_Sodium_Core_Util

Code

public static function substr($str, $start = 0, $length = null) {

  /* Type checks: */
  if (!is_string($str)) {
    throw new TypeError('String expected');
  }
  if ($length === 0) {
    return '';
  }
  if (self::isMbStringOverride()) {
    if (PHP_VERSION_ID < 50400 && $length === null) {
      $length = self::strlen($str);
    }
    $sub = (string) mb_substr($str, $start, $length, '8bit');
  }
  elseif ($length === null) {
    $sub = (string) substr($str, $start);
  }
  else {
    $sub = (string) substr($str, $start, $length);
  }
  if ($sub !== '') {
    return $sub;
  }
  return '';
}