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