public static function truncate($str, $max_len, $pos = self::TRUNC_END, $ellipsis = "...")
    {
        if (self::length($str) > $max_len) {
            $ellipsis_len = self::length($ellipsis);
            switch($pos) {
                case self::TRUNC_START:
                    $max_len -= $ellipsis_len;
                    $str = $ellipsis . self::sub($str, "-{$max_len}");
                    break;
                case self::TRUNC_MIDDLE:
                    $start   = self::sub($str, 0, round($max_len / 2) - $ellipsis_len);
                    $max_len = $max_len - self::length($start) - $ellipsis_len;
                    $end     = self::sub($str, "-{$max_len}");
                    $str     = "{$start}{$ellipsis}{$end}";
                    break;
                case self::TRUNC_END:
                    $max_len -= $ellipsis_len;
                    $str = self::sub($str, 0, $max_len) . $ellipsis;
                    break;
                default:
                    self::toss(
                        "InvalidArgumentException",
                        "Invalid truncate position '{0}'.",
                        $pos
                    );
                    break;
            }
        }
        
        return $str;
    }