Transform a CamelCase string to underscore_case string
'CMSCategories' => 'cms_categories'
'RangePrice' => 'range_price'
@param string $val
@param string $sep
@return string
346745
public static function snakeCase($val, string $sep = '_'): string
    {
        if (!$val || !\is_string($val)) {
            return '';
        }

        $val = \preg_replace('/([A-Z][a-z])/', $sep . '$1', $val);

        return self::lowercase(\trim($val, $sep));
    }
176953
public function displayVal($val, array $options = [])
    {
        if ($val === null || $val === '') {
            return '';
        }

        /** Parse multilingual values */
        if ($this->l10n()) {
            $propertyValue = $this->l10nVal($val, $options);
            if ($propertyValue === null) {
                return '';
            }
        } elseif ($val instanceof Translation) {
            $propertyValue = (string)$val;
        } else {
            $propertyValue = $val;
        }

        $separator = $this->multipleSeparator();

        /** Parse multiple values / ensure they are of array type. */
        if ($this->multiple()) {
            if (!is_array($propertyValue)) {
                $propertyValue = explode($separator, $propertyValue);
            }
        }

        if ($separator === ',') {
            $separator = ', ';
        }

        if (is_array($propertyValue)) {
            foreach ($propertyValue as &$value) {
                if (is_string($value)) {
                    $value = $this->choiceLabel($value);
                    if (!is_string($value)) {
                        $value = $this->l10nVal($value, $options);
                    }
                }
            }
            $propertyValue = implode($separator, $propertyValue);
        } elseif (is_string($propertyValue)) {
            $propertyValue = $this->choiceLabel($propertyValue);
            if (!is_string($propertyValue)) {
                $propertyValue = $this->l10nVal($propertyValue, $options);
            }
        }

        return $propertyValue;
    }
95516
public static function slug($string, $separator = '-') {
        $q_separator = preg_quote($separator, '#');
        $code = array(
            '&.+?;' => '',
            '[^a-z0-9 _-]' => '',
            '\s+' => $separator,
            '(' . $q_separator . ')+' => $separator
        );

        $string = strip_tags($string);
        foreach ($code as $key => $val) {
            $string = preg_replace('#' . $key . '#i', $val, $string);
        }

        $string = strtolower($string);

        return trim($string);
    }
675805
protected function replaceNamesAndAliasIn($val)
    {
        $quoted = $this->replaceNamesIn($val);
        $pos    = strripos($quoted, ' AS ');
        if ($pos) {
            $alias  = $this->replaceName(substr($quoted, $pos + 4));
            $quoted = substr($quoted, 0, $pos) . " AS $alias";
        }
        return $quoted;
    }
1184205
public function inputVal($val, array $options = [])
    {
        $val = $this->dateTimeVal($val);

        if ($val instanceof DateTimeInterface) {
            return $val->format('Y-m-d H:i:s');
        } else {
            return '';
        }
    }
253698
public function escape($VAL)
    {
        // save data
        if (is_numeric($VAL)) {
            if (floatval($VAL) == intval($VAL)) {
                $VAL = intval($VAL);
                settype($VAL, 'integer');
            } else {
                $VAL = floatval($VAL);
                settype($VAL, 'float');
            }
        } else {
            // \PDO::quote() also adds colon before and after the string, so we
            //  have to remove it to keep it compatible with old style.
            $VAL = substr($this->sql->quote(strval($VAL), \PDO::PARAM_STR), 1, -1);
        }

        return $VAL;
    }
93878
private static function contextValueToString($val)
    {

        if (is_bool($val)) {
            return var_export($val, true);

        } elseif (is_scalar($val)) {
            return (string)$val;

        } elseif (is_null($val)) {
            return 'NULL';

        } elseif (is_object($val)) {
            if (is_callable(array($val, '__toString'))) {
                return (string)$val;
            }
            return get_class($val);
        }
        return gettype($val);
    }
925043
private static function parseInlineTable($val)
    {
        // Check valid inline table
        if($val[0] == '{' && substr($val, -1) == '}')
        {
            $val = substr($val, 1, -1);
        }
        else
        {
            throw new Exception('Invalid inline table definition: ' . $val);
        }

        $result = new stdClass();
        $openString = false;
        $openLString = false;
        $buffer = '';

        $strLen = strlen($val);
        for($i = 0; $i < $strLen; $i++)
        {
            // Handle strings
            if($val[$i] == '"' && $val[$i - 1] != "\\")
            {
                $openString = !$openString;
            }
            elseif($val[$i] == "'") {
                $openLString = !$openLString;
            }

            if( $val[$i] == ',' && !$openString && !$openLString )
            {
                // Parse buffer
                $kv = explode('=', $buffer, 2);
                $result->{trim($kv[0])} = self::parseValue( trim($kv[1]) );

                // Clear buffer
                $buffer = '';
            }
            else
            {
                $buffer .= $val[$i];
            }
        }

        // Parse last buffer
        $kv = explode('=', $buffer, 2);
        $result->{trim($kv[0])} = self::parseValue( trim($kv[1]) );

        return $result;
    }
92925
private static function formatArrayValue(string $col, array $val, string $op): string
    {
        return \sprintf(" %s %s ('%s')", $col, $op, \implode("','", $val));
    }
415174
public function separator(string $sep): CollectionFlattener
    {
        if (mb_strlen($sep) != 1 || $sep === '*') {
            throw new Exception(__CLASS__.': Separator must be 1 character and cannot be an asterisk (*)');
        }
        $this->separator = $sep;
        return $this;
    }
1197667
public function escape($val)
    {
        if ($val === UNDEFINED) {
            return '';
        }
        if (is_array($val)) {
            $out = array();
            foreach ($val as $v) {
                $out[] = $this->escape($v);
            }

            return $out;
        }
        $name = ':'.$this->param_base;
        $name = $this->_unique($this->params, $name);
        $this->params[$name] = $val;

        return $name;
    }
985844
public static function substringBefore($string, $separator)
    {
        $pos = mb_strpos($string, $separator);
        return $pos !== false ? mb_substr($string, 0, $pos) : $string;
    }
1337647
public static function str2array($str, $sep = ',')
    {
        $str = trim($str, "$sep ");

        if (!$str) {
            return [];
        }

        return preg_split("/\s*$sep\s*/", $str, -1, PREG_SPLIT_NO_EMPTY);
    }
197105
public function setRawMimeDirValue($val)
    {
        // Normally we don't need to do any type of unescaping for these
        // properties, however.. we've noticed that Google Contacts
        // specifically escapes the colon (:) with a blackslash. While I have
        // no clue why they thought that was a good idea, I'm unescaping it
        // anyway.
        //
        // Good thing backslashes are not allowed in urls. Makes it easy to
        // assume that a backslash is always intended as an escape character.
        if ('URL' === $this->name) {
            $regex = '#  (?: (\\\\ (?: \\\\ | : ) ) ) #x';
            $matches = preg_split($regex, $val, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
            $newVal = '';
            foreach ($matches as $match) {
                switch ($match) {
                    case '\:':
                        $newVal .= ':';
                        break;
                    default:
                        $newVal .= $match;
                        break;
                }
            }
            $this->value = $newVal;
        } else {
            $this->value = strtr($val, ['\,' => ',']);
        }
    }
330190
public static function incrementSeparated(string $string, string $separator = '-'): string
    {
        if (preg_match('/' . $separator . '(\d+)$/', $string, $matches)) {
            $string = self::stripRight($string, $separator . $matches[1]);
            $duplicateNo = ((int) $matches[1]) + 1;
        } else {
            $duplicateNo = 2;
        }

        $newString = $string . $separator . $duplicateNo;

        return $newString;
    }
1288846
function __addSpacesSeparator(val) {
    var reg = /(\d+)(\d{3})/,
        sep = ' ';
    // val must be a type String
    val += '';

    while (reg.test(val)) {
        val = val.replace(reg, '$1' + sep + '$2');
    }
    return val;
}
551733
protected static function snakeCase($input, $glue = '_', $separator = '-')
    {
        $input = preg_split('/(?<=[a-z])(?=[A-Z])/x', $input);
        $input = join($input, $glue);
        $input = str_replace($separator, $glue, $input);

        return strtolower($input);
    }