Append $substring if string doesn't end with it.

@param $substring
@param null $encoding

@return TransformerWorker
506178
public function ensureSuffix($substring, $encoding = null)
    {
        if (!$this->hasMbstring()) {
            $len = \strlen($substring);
            if (\substr($this->string, -$len) == $substring) {
                return $this;
            }
        } else {
            $encoding = $this->encoding($encoding);

            $len = \mb_strlen($substring, $encoding);
            if (\mb_substr($this->string, -$len, \mb_strlen($this->string, $encoding), $encoding) == $substring) {
                return $this;
            }
        }

        return $this->suffix($substring);
    }
924593
public function removeLeft($substring)
    {
        $stringy = static::create($this->str, $this->encoding);

        if ($stringy->startsWith($substring)) {
            $substringLength = \mb_strlen($substring, $stringy->encoding);
            return $stringy->substr($substringLength);
        }

        return $stringy;
    }
446793
public static function ensureLeft(string $str, string $substring): string
    {
        return (string)BaseStringy::create($str)->ensureLeft($substring);
    }
218637
public function getSubstr($str, $charset, $start, $length = null)
    {
        $mb = $this->getMbCharset($charset);
        if ($mb !== false) {
            return mb_substr($str, $start, $length, $mb);
        }
        $ic = $this->getIconvAlias($charset);
        if ($length === null) {
            $length = iconv_strlen($str, $ic);
        }
        return iconv_substr($str, $start, $length, $ic);
    }
693088
public SubString substring(int start) {
		JcNumber sub = new JcNumber(start, this, OPERATOR.Common.COMMA_SEPARATOR);
		SubString ret = new SubString(null, sub,
				new FunctionInstance(FUNCTION.String.SUBSTRING, 2));
		QueryRecorder.recordInvocationConditional(this, "substring", ret, QueryRecorder.literal(start));
		return ret;
	}
1329755
public function insert($substring, $index)
    {
        $stringy = static::create($this->str, $this->encoding);
        if ($index > $stringy->length()) {
            return $stringy;
        }

        $start = \mb_substr($stringy->str, 0, $index, $stringy->encoding);
        $end = \mb_substr($stringy->str, $index, $stringy->length(),
            $stringy->encoding);

        $stringy->str = $start . $substring . $end;

        return $stringy;
    }
86059
public function substr($start, $length=null)
    {
        return $this->newInstance(mb_substr($this->toString(), $start, $length, $this->getEncoding()));
    }
1018693
SubString getParenSubString(int i)
    {
        if (parens != null && i < parens.length) {
            SubString parsub = parens[i];
            if (parsub != null) {
                return parsub;
            }
        }
        return new SubString();
    }
1314856
static function substring($input, $start, $length = null) {
		return self::substr($input, $start, $length, "utf-8");
	}
466409
public function substr($start, $length = null, $encoding = null)
    {
        if (!$this->hasMbstring()) {
            return $this->transform('\substr', $start, $length);
        }

        $encoding = $this->encoding($encoding);

        // workaround for php < 5.4.8
        if (is_null($length)) {
            $length = \mb_strlen($this->string, $encoding);
        }

        return $this->transform('\mb_substr', $start, $length, $encoding);
    }
918078
public function startsWithIgnoreCase($substring) {
		$substring = mb_strtolower($substring, $this->encoding);
		$substringLength = mb_strlen($substring, $this->encoding);
		$startOfStr = mb_strtolower(mb_substr($this->string, 0, $substringLength, $this->encoding));

		return (string) $substring === $startOfStr;
	}
962761
public String substring(int start, int end) {
        char[] buf = new char[end - start];
        getChars(start, end, buf, 0);
        return new String(buf);
    }
173785
@Override
    public String substring(int beginIndex, int endIndex) {
        if (beginIndex < 0) {
            throw new StringIndexOutOfBoundsException(beginIndex);
        }
        char[] buf = this.buf;
        int sz = buf.length;
        if (endIndex > sz) {
            throw new StringIndexOutOfBoundsException(endIndex);
        }
        int subLen = endIndex - beginIndex;
        if (subLen < 0) {
            throw new StringIndexOutOfBoundsException(subLen);
        }
        return ((beginIndex == 0) && (endIndex == sz)) ? toString()
                : new String(buf, toInternalId(beginIndex), subLen);
    }
863974
public static function ensureRight(string $str, string $substring): string
    {
        return (string)BaseStringy::create($str)->ensureRight($substring);
    }
418409
public function startsWith($substring) {
		$substringLength = mb_strlen($substring, $this->encoding);
		$startOfStr = mb_substr($this->string, 0, $substringLength, $this->encoding);

		return (string) $substring === $startOfStr;
	}
352907
public function insert($substring, $idx, $encoding = null)
    {
        return $this->addModifier('insert', array($substring, $idx, $encoding));
    }
758458
public function substr($key, $start, $end) {
        return $this->returnCommand(['SUBSTR'], $key, [$key, $start, $end]);
    }