public static function chomp($str)
    {
        if (true === self::isEmpty($str)) {
            return $str;
        }

        if (1 === self::length($str)) {
            $firstChar = self::charAt($str, 0);

            if ("\r" === $firstChar || "\n" === $firstChar) {
                return self::EMPTY_STR;
            }

            return $str;
        }

        $lastIndex = self::length($str) - 1;
        $lastChar = self::charAt($str, $lastIndex);

        if ("\n" === $lastChar) {
            if ("\r" === self::charAt($str, $lastIndex - 1)) {
                --$lastIndex;
            }
        } elseif ("\r" !== $lastChar) {
            ++$lastIndex;
        }

        return self::substring($str, 0, $lastIndex);
    }