@Immutable
    public static String quotemeta(String string) {
        int len = string.length();
        StringBuilder sb = new StringBuilder(len * 5 / 4);

        for (int i = 0; i < len; i++) {
            char ch = string.charAt(i);

            switch (ch) {
                case '.':
                case '\\':
                case '+':
                case '*':
                case '?':
                case '[':
                case '^':
                case ']':
                case '(':
                case ')':
                case '$':
                    sb.append("\\");
                    sb.append(ch);
                    break;
                default:
                    sb.append(ch);
            }
        }
        return sb.toString();
    }
Parses the cslashes bitmap returning an actual bitmap.

@param charset the bitmap string

@return the actual bitmap
exts/jphp-zend-ext/src/main/java/org/develnext/jphp/zend/ext/standard/StringFunctions.java