Get a substring based on byte limits

@see _strlen()

@param string $binary_string The input string
@param int $start
@param int $length

@internal
@return string The substring
359892
function _substr($binary_string, $start, $length) {
        if (function_exists('mb_substr')) {
            return mb_substr($binary_string, $start, $length, '8bit');
        }
        return substr($binary_string, $start, $length);
    }
893382
public static function slice($string, $start, $length = null)
    {
        if (function_exists('mb_substr')) {
            return mb_substr($string, $start, $length, '8bit');
        }
        return substr($string, $start, $length);
    }
105192
public static function substr($string, $start = 0, $length, $dot = null)
    {
        $string = self::byteSubstr($string, $start, $length);
        return $dot ? $string . $dot : $string;
    }
1355142
public static function slice($string, $start, $length = null)
    {
        if (function_exists('mb_substr')) {
            return mb_substr($string, $start, $length, 'UTF-8');
        }
        return implode('', array_slice(preg_split('//u', $string, - 1, PREG_SPLIT_NO_EMPTY), $start, $length));
    }
483441
protected static function ourSubstr($str, $start = 0, $length = null)
    {
        // Premature optimization: cache the function_exists() result
        static $exists = null;
        if ($exists === null) {
            $exists = \function_exists('\\mb_substr');
        }

        // If it exists, we need to make sure we're using 8bit mode
        if ($exists) {
            return \mb_substr($str, $start, $length, '8bit');
        } elseif ($length !== null) {
            return \substr($str, $start, $length);
        }
        return \substr($str, $start);
    }
380683
public function substr($start, $length = null)
    {
        $str = mb_substr($this->value, $start, $length);

        return static::make($str);
    }
465264
public static function substr($str, $start, $length, $suffix = false) {
        if (mb_strlen($str, 'utf-8') <= $length) return $str;
        $slice = mb_substr($str, $start, $length, 'utf-8');
		if ($suffix) return $slice."…";
		return $slice;
	}
177205
public function substring(int $start, int $length = null): self
    {
        if ($this->length() === 0) {
            return $this;
        }

        $sub = \mb_substr($this->value, $start, $length, (string) $this->encoding());

        return new self($sub, $this->encoding);
    }
212654
public String substring(int start, int end) {

    return new String(this.buffer, this.initialOffset + start, end - start);
  }
910358
public static function substr(string $string, int $start, int $length = null): string
    {
        return \mb_substr($string, $start, $length, '8bit');
    }
142290
protected function generateString($length)
    {
        $bytes = ceil($length / 2);
        $string = bin2hex(random_bytes($bytes));

        return substr($string, 0, $length);
    }
1193657
public static function betweenSubstr($string, $start, $end = null)
    {
        if (($start_pos = strpos($string, $start)) !== false) {
            if ($end) {
                if (($end_pos = strpos($string, $end, $start_pos + strlen($start))) !== false) {
                    return substr($string, $start_pos + strlen($start), $end_pos - ($start_pos + strlen($start)));
                }
            } else {
                return substr($string, $start_pos);
            }
        }
        return false;
    }
47414
public static function getSlice($string, $offset, $length = null)
    {
        if (self::checkMB()) {
            return mb_substr($string, $offset, $length, '8bit');
        }
        if ($length === null) {
            $length = strlen($string);
        }
        return substr($string, $offset, $length);
    }
873012
static public byte[] byteSubstring(byte[] bytes, int start, int end) {

        byte[] rc = null;

        if (0 > start || start > bytes.length || start > end) {
            // invalid start position
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Invalid start position in byteSubstring: " + start);
            }
        } else if (0 > end || end > bytes.length) {
            // invalid end position
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Invalid end position in byteSubstring: " + end);
            }
        } else {
            // now pull the substring
            int len = end - start;
            rc = new byte[len];
            System.arraycopy(bytes, start, rc, 0, len);
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "byteSubstring returning: [" + getEnglishString(rc) + "]");
        }
        return rc;
    }
628722
public function getBinarySlice($binary, $start, $size, $binaryLength)
    {
        $binary >>= $binaryLength - ($start + $size);
        $mask = ((1 << $size) - 1);

        return $binary & $mask;
    }
962761
public String substring(int start, int end) {
        char[] buf = new char[end - start];
        getChars(start, end, buf, 0);
        return new String(buf);
    }
1115730
public function subString($startPosition, $length)
    {
        if (!$this->isNumber($startPosition)) {
            throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [
                '$startPosition',
                'integer'
            ]);
        }

        if (!$this->isNumber($length)) {
            throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [
                '$length',
                'integer'
            ]);
        }

        if ($length == 0) {
            $length = null;
        }
        $value = mb_substr($this->val(), $startPosition, $length, self::DEF_ENCODING);
        $this->val($value);

        return $this;
    }