| 185 | } |
| 186 | |
| 187 | @Override |
| 188 | public int writeWrap(String wrap) |
| 189 | throws IOException { |
| 190 | int n = 0; |
| 191 | // if want wrap and not already at start of line (last char was \n) |
| 192 | // and we have hit or exceeded the threshold |
| 193 | if ( lineWidth!= NO_WRAP&& wrap!=null && !atStartOfLine && charPosition>=lineWidth ) { |
| 194 | // ok to wrap |
| 195 | // Walk wrap string and look for A\nB. Spit out A\n |
| 196 | // then spit indent or anchor, whichever is larger |
| 197 | // then spit out B. |
| 198 | for (int i = 0; i < wrap.length(); i++) { |
| 199 | char c = wrap.charAt(i); |
| 200 | if ( c=='\r' ) { |
| 201 | continue; |
| 202 | } |
| 203 | else if ( c=='\n' ) { |
| 204 | out.write(newline); |
| 205 | n += newline.length(); |
| 206 | charPosition = 0; |
| 207 | charIndex += newline.length(); |
| 208 | n += indent(); |
| 209 | // continue writing any chars out |
| 210 | } |
| 211 | else { // write A or B part |
| 212 | n++; |
| 213 | out.write(c); |
| 214 | charPosition++; |
| 215 | charIndex++; |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | return n; |
| 220 | } |
| 221 | |
| 222 | public int indent() |
| 223 | throws IOException { |