@Immutable
    public static Memory wordwrap(String str, int width, String _break, boolean cut) {
        int length = str.length();
        StringBuilderMemory sb = new StringBuilderMemory();

        int done = 0;
        int prevSpacePos = 0;
        int start = 0;
        int wordLength = 0;
        for (int i = 0; i < length + 1; i++) {
            char ch = i == length ? ' ' : str.charAt(i);

            if (Character.isSpaceChar(ch) || (cut && wordLength + 1 >= width)) {
                if (done >= width || i == length) {
                    if (done <= width) {
                        sb.append(str.substring(start, i));
                    } else {
                        if (prevSpacePos >= start) {
                            if (cut && done > width) {
                                sb.append(str.substring(start, start + width));
                                i -= done - width;
                                prevSpacePos = i;
                            } else {
                                sb.append(str.substring(start, i));
                                prevSpacePos = i;
                            }
                        } else {
                            sb.append(str.substring(start, prevSpacePos));
                            i = prevSpacePos;
                        }
                    }
                    start = i + 1;
                    if (i != length) {
                        sb.append(_break);
                    }

                    done = 0;
                    continue;
                } else {
                    prevSpacePos = i;
                }

                wordLength = 0;
            }

            done++;
            wordLength++;
        }

        return sb;
    }
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