public static function buildAttribString($attribs)
    {
        if (\is_string($attribs)) {
            return \rtrim(' '.\trim($attribs));
        }
        $attribPairs = array();
        foreach ($attribs as $k => $v) {
            if (\is_int($k)) {
                $k = $v;
                $v = true;
            }
            $k = \strtolower($k);
            if (\strpos($k, 'data-') === 0) {
                $v = \json_encode($v);
                $v = \trim($v, '"');
            } elseif (\is_bool($v)) {
                $v = self::buildAttribBoolVal($k, $v);
            } elseif (\is_array($v) || $k === 'class') {
                $v = self::buildAttribArrayVal($k, $v);
            }
            if (\array_filter(array(
                $v === null,
                $v === '' && \in_array($k, array('class', 'style'))
            ))) {
                // don't include
                continue;
            }
            $v = \trim($v);
            $attribPairs[] = $k.'="'.\htmlspecialchars($v).'"';
        }
        \sort($attribPairs);
        return \rtrim(' '.\implode(' ', $attribPairs));
    }