Returns the first $n characters of the string.

@param  int $n Number of characters to retrieve from the start.

@return static String being the first $n chars.
331101
public function first($n)
    {
        $first = '';

        if ($n > 0)
        {
            $first = UTF8::substr
            (
                $this->scalarString,
                0,
                $n,
                $this->encoding
            );
        }

        return $this->newSelf($first);
    }
664297
public function slice($n)
    {
        if ($this->length < $n) {
            throw new BufferUnderflowException();

        } elseif ($this->length === $n) {
            return new Buffer($this->buffer);

        } else {
            return new Buffer(substr($this->buffer, 0, $n));
        }
    }
905534
public function ucfirst(){
		
		if($this->isNullOrWhitespace()){
			return clone $this;
		}
		else if($this->count() === 1){
			return new static(\mb_strtoupper($this->_Value, $this->_Encoding),
					$this->_Encoding);
		}
		
		$str = $this[0]->ucfirst() . $this->substring(1);
		
		return new static($str, $this->_Encoding);
		
	}
1054689
public function encryptInteger($n) {
		if (!is_numeric($n)) return null;
		return (PHP_INT_SIZE == 4 ? self::encrypt32($n) : self::encrypt64($n)) ^ $this->encPassword;
	}
226504
public function consume($n)
    {
        if ($this->length < $n) {
            throw new BufferUnderflowException();

        } elseif ($this->length === $n) {
            $buffer = $this->buffer;
            $this->buffer = "";
            $this->length = 0;
            return $buffer;

        } else {
            $buffer = substr($this->buffer, 0, $n);
            $this->buffer = substr($this->buffer, $n);
            $this->length -= $n;
            return $buffer;
        }
    }
1231460
private function stringToNum(string $string) : BigNumber
    {
        $number = new BigNumber(0);
        foreach (str_split(strrev($string)) as $char) {
            $number->multiply($this->alphabetLength)->add(array_search($char, $this->alphabet, false));
        }

        return $number;
    }
199364
public function read($len = null)
    {
        if (!$this->getInitialized()) {
            $this->_initialize();
            $this->setInitialized(true);
        }

        $ch = -1;

        if ($this->queuedData !== null && $this->queuedData === '') {
            $this->queuedData = null;
        }

        if ($this->queuedData !== null) {
            $ch = $this->queuedData[0];
            $this->queuedData = substr($this->queuedData, 1);
            if ($this->queuedData === '') {
                $this->queuedData = null;
            }
        } else {
            $this->queuedData = $this->readLine();
            if ($this->queuedData === null) {
                $ch = -1;
            } else {
                if ($this->suffix !== null) {
                    $lf = '';
                    if (StringHelper::endsWith($this->queuedData, "\r\n")) {
                        $lf = "\r\n";
                    } elseif (StringHelper::endsWith($this->queuedData, "\n")) {
                        $lf = "\n";
                    }
                    $this->queuedData = substr($this->queuedData, 0, strlen($this->queuedData) - strlen($lf)) . $this->suffix . $lf;
                }
                return $this->read();
            }
        }
        return $ch;
    }
1158037
public function readToken($start)
    {
        $length = $this->source->getLength();
        $position = $this->positionAfterWhitespace($start);

        if ($position >= $length) {
            return new Token(Token::EOF_TYPE, $length, $length);
        }

        $code = $this->charCodeAt($position);

        switch ($code) {
            // !
            case 33:
                return new Token(Token::BANG_TYPE, $position, $position + 1);
            // $
            case 36:
                return new Token(Token::DOLLAR_TYPE, $position, $position + 1);
            // (
            case 40:
                return new Token(Token::PAREN_L_TYPE, $position, $position + 1);
            // )
            case 41:
                return new Token(Token::PAREN_R_TYPE, $position, $position + 1);
            // .
            case 46:
                if ($this->charCodeAt($position + 1) === 46 && $this->charCodeAt($position + 2) === 46) {
                    return new Token(Token::SPREAD_TYPE, $position, $position + 3);
                }
                break;
            // :
            case 58:
                return new Token(Token::COLON_TYPE, $position, $position + 1);
            // =
            case 61:
                return new Token(Token::EQUALS_TYPE, $position, $position + 1);
            // @
            case 64:
                return new Token(Token::AT_TYPE, $position, $position + 1);
            // [
            case 91:
                return new Token(Token::BRACKET_L_TYPE, $position, $position + 1);
            // ]
            case 93:
                return new Token(Token::BRACKET_R_TYPE, $position, $position + 1);
            // {
            case 123:
                return new Token(Token::BRACE_L_TYPE, $position, $position + 1);
            // |
            case 124:
                return new Token(Token::PIPE_TYPE, $position, $position + 1);
            // }
            case 125:
                return new Token(Token::BRACE_R_TYPE, $position, $position + 1);
            // A-Z
            case 65: case 66: case 67: case 68: case 69: case 70: case 71: case 72:
            case 73: case 74: case 75: case 76: case 77: case 78: case 79: case 80:
            case 81: case 82: case 83: case 84: case 85: case 86: case 87: case 88:
            case 89: case 90:
            // _
            case 95:
            // a-z
            case 97: case 98: case 99: case 100: case 101: case 102: case 103: case 104:
            case 105: case 106: case 107: case 108: case 109: case 110: case 111:
            case 112: case 113: case 114: case 115: case 116: case 117: case 118:
            case 119: case 120: case 121: case 122:
                return $this->readName($position);
            // -
            case 45:
            // 0-9
            case 48: case 49: case 50: case 51: case 52:
            case 53: case 54: case 55: case 56: case 57:
                return $this->readNumber($position, $code);
            // "
            case 34:
                return $this->readString($position);
        }

        // @todo Throw proper exception.
        throw new \Exception('Unexpected character.');
    }
721059
protected function _rawread($n)
    {
        if ($this->_bufferedInput) {
            $result = '';
            $read = 0;
            while ($read < $n && !feof($this->_bufferedInput->realSock()) &&
                   (false !== ($buffer = fread($this->_bufferedInput->realSock(), $n - $read)))
            ) {
                // get status of socket to determine whether or not it has timed out
                $info = stream_get_meta_data($this->_bufferedInput->realSock());
                if($info['timed_out']) {
                    throw new \Exception('Error reading data. Socket connection timed out');
                }

                $read += strlen($buffer);
                $result .= $buffer;
            }

            if (strlen($result) != $n) {
                throw new \Exception(
                    sprintf(
                            'Error reading data. Recevived %d instead of '.
                            'expected %d bytes', strlen($result), $n
                         )
                    );
            }

            $this->_offset += $n;
        } else {
            if (strlen($this->_str) < $n) {
                throw new \Exception(
                    sprintf(
                        'Error reading data. Requested %d bytes while string '.
                        'buffer has only %s', $n, strlen($this->_str)
                    )
                );
            }
            $result = substr($this->_str, 0, $n);
            $this->_str = substr($this->_str, $n);
            $this->_offset += $n;
        }
        return $result;
    }
1051929
protected static function mbUcFirst($string)
    {
        $firstChar = mb_strtoupper(mb_substr($string, 0, 1, 'utf-8'), 'utf-8');
        return $firstChar . mb_substr($string, 1, mb_strlen($string, 'utf-8'), 'utf-8');
    }
526814
public function read($len = null)
    {
        if (!$this->getInitialized()) {
            $this->_initialize();
            $this->setInitialized(true);
        }

        $buffer = $this->in->read($len);

        if ($buffer === -1) {
            return -1;
        }

        $lines = explode("\n", $buffer);
        $filtered = [];

        $commentsSize = count($this->_comments);

        foreach ($lines as $line) {
            for ($i = 0; $i < $commentsSize; $i++) {
                $comment = $this->_comments[$i]->getValue();
                if (StringHelper::startsWith($comment, ltrim($line))) {
                    $line = null;
                    break;
                }
            }
            if ($line !== null) {
                $filtered[] = $line;
            }
        }

        $filtered_buffer = implode("\n", $filtered);

        return $filtered_buffer;
    }
517298
public static function lcFirst($string)
    {
        $lcFirst = static::sub($string, 0, 1);
        $lcFirst = static::low($lcFirst);

        return $lcFirst . static::sub($string, 1);
    }
63520
public function niceNumberFunc($n)
    {
        if (!\is_float($n) && !\is_int($n)) {
            if (!\is_string($n) || $n === '') {
                return false;
            }

            // Strip any thousand formatting and find the first number.
            $list = array_filter(preg_split("/\D+/", str_replace(',', '', $n)));
            $n = reset($list);

            if (!\is_numeric($n)) {
                return false;
            }

            $n = (float)$n;
        }

        // now filter it;
        if ($n > 1000000000000) {
            return round($n/1000000000000, 2).' t';
        }
        if ($n > 1000000000) {
            return round($n/1000000000, 2).' b';
        }
        if ($n > 1000000) {
            return round($n/1000000, 2).' m';
        }
        if ($n > 1000) {
            return round($n/1000, 2).' k';
        }

        return number_format($n);
    }
291930
static char getFirstCharLocName(String name) {
        final char first;
        int i = name.indexOf('}');
        if (i < 0)
            first = name.charAt(0);
        else
            first = name.charAt(i+1);
        return first;
    }
15099
public function firstDifference($old, $new)
    {
        // loop through old and new character by character and compare
        $oldLen = mb_strlen($old);
        $newLen = mb_strlen($new);

        if ($oldLen === 0) {
            return 0;
        }

        for ($i = 0; $i < $oldLen && $i < $newLen; $i++) {
            if (mb_substr($old, $i, 1) !== mb_substr($new, $i, 1)) {
                return $i;
            }
        }
        if ($i < $oldLen || $i < $newLen) {
            return $i;
        }
        return -1;
    }
382858
public function getNextBytes($n)
	{
		$s = "";
		$nRem = $n;
		while ($nRem > 0)
		{
			if ($this->_outputPos == 64)
				$this->nextOutput();
			$nCopy = min(64 - $this->_outputPos, $nRem);
			$s .= substr($this->_output, $this->_outputPos, $nCopy);

			$nRem -= $nCopy;
			$this->_outputPos += $nCopy;
		}
		return $s;
	}
968530
public function txts($string, $n)
	{
		$args  = func_get_args();
		$count = count($args);

		if ($count > 1)
		{
			// Try the key from the language plural potential suffixes
			$found = false;
			$suffixes = $this->getPluralSuffixes((int) $n);
			array_unshift($suffixes, (int) $n);
			foreach ($suffixes as $suffix)
			{
				$key = $string . '_' . $suffix;
				if ($this->hasKey($key))
				{
					$found = true;
					break;
				}
			}
			if (!$found)
			{
				// Not found so revert to the original.
				$key = $string;
			}
			if (is_array($args[$count - 1]))
			{
				$args[0] = $this->translate(
					$key, array_key_exists('jsSafe', $args[$count - 1]) ? $args[$count - 1]['jsSafe'] : false,
					array_key_exists('interpretBackSlashes', $args[$count - 1]) ? $args[$count - 1]['interpretBackSlashes'] : true
				);
			}
			else
			{
				$args[0] = $this->translate($key);
			}
			return call_user_func_array('sprintf', $args);
		}
		elseif ($count > 0)
		{

			// Default to the normal sprintf handling.
			$args[0] = $this->translate($string);
			return call_user_func_array('sprintf', $args);
		}

		return '';
	}