int n = 0; int possibleWrap; boolean lastLenCheck = false;  while (true) { possibleWrap = n; n = currentString.indexOf(WhitespaceStripper.SPACE, n + 1); if (n == -1) { break;
int left = 0; int right = currentString.indexOf(WhitespaceStripper.SPACE, left+1); int lastWrap = 0; int graphicsLength = 0;  while(right > 0 && graphicsLength <= avail) { graphicsLength += FontUtil.len(c, currentString.substring(left, right), font); lastWrap = left; left = right; right = currentString.indexOf(WhitespaceStripper.SPACE, left+1); }  if(right < 0) {  graphicsLength += FontUtil.len(c, currentString.substring(left), font); }  if(graphicsLength <= avail) {  return; }  if (lastWrap != 0) { inline.setSubstring(inline.start_index, inline.start_index + lastWrap); inline.break_after = true; } else { if(left == 0) left = currentString.length(); inline.setSubstring(inline.start_index, inline.start_index + left); if (prev_align != null && !prev_align.break_after) {  inline.break_before = true; } else {  inline.break_after = true;
    public static void breakText(Context c, InlineTextBox inline, InlineBox prev_align, int avail, Font font) {        boolean db = false;        if (db) {            Uu.p("=========================");            Uu.p("breaking: " + inline);            //Uu.p("breaking : '" + inline.getSubstring() + "'");            //Uu.p("avail = " + avail);            //Uu.p("max = " + max);            //Uu.p("prev align = " + prev_align);        }        //inline.setFont(font);        // ====== handle nowrap        if (inline.whitespace == IdentValue.NOWRAP) {            return;        }        //check if we should break on the next newline        if (inline.whitespace == IdentValue.PRE ||                inline.whitespace == IdentValue.PRE_WRAP ||                inline.whitespace == IdentValue.PRE_LINE) {            // Uu.p("doing a pre line");            int n = inline.getSubstring().indexOf(WhitespaceStripper.EOL);            // Uu.p("got eol at: " + n);            if (n > -1) {                inline.end_index = inline.start_index + n + 1;                inline.break_after = true;            }        }        //check if we may wrap        if (inline.whitespace == IdentValue.PRE) {            return;        }        String currentString = inline.getSubstring();        int n = 0;        int possibleWrap;        boolean lastLenCheck = false;        while (true) {            possibleWrap = n;            n = currentString.indexOf(WhitespaceStripper.SPACE, n + 1);            if (n == -1) {                break;            }            lastLenCheck = FontUtil.len(c, currentString.substring(0, n), font) > avail;            if (lastLenCheck) {                break;            }        }        if (n == -1 && FontUtil.len(c, currentString, font) <= avail) {            return;        }        if (possibleWrap == 0) {            if (lastLenCheck) {                n = 0;            } else {                possibleWrap = currentString.length();            }        }                // (0 is a boundary condition when the first was a space)        if (n <= 0) {//unbreakable string            inline.setSubstring(inline.start_index, inline.start_index + possibleWrap);//the best we can do            if (prev_align != null && !prev_align.break_after) {                inline.break_before = true;            }//else {//I think this else should be here?            inline.break_after = true;            //}        } else {//found a place to wrap            inline.setSubstring(inline.start_index, inline.start_index + possibleWrap);            inline.break_after = true;        }        return;    }