This method performs some work on a given character sheet template line, namely replacing tokens, dealing with Malformed lines and simply outputting plain text. @param aLine The line to do the work on @param output The output buffer that is effectively the character sheet template @param aPC The PC
(String aLine, BufferedWriter output, PlayerCharacter aPC)
| 1450 | * @param aPC The PC that we are outputting |
| 1451 | */ |
| 1452 | private void replaceLine(String aLine, BufferedWriter output, PlayerCharacter aPC) |
| 1453 | { |
| 1454 | // Find the last index of the | character |
| 1455 | int lastIndex = aLine.lastIndexOf('|'); |
| 1456 | |
| 1457 | // If there are no pipes and it's a non empty string, just output the fixed text |
| 1458 | if (lastIndex < 0 && !aLine.isEmpty()) |
| 1459 | { |
| 1460 | outputNonToken(aLine, output); |
| 1461 | } |
| 1462 | |
| 1463 | /* |
| 1464 | * When the line starts with a pipe and that pipe is the only |
| 1465 | * one on the line, this operation ignores the line. This is |
| 1466 | * because the token is malformed. Malformed because it should be |
| 1467 | * between pipes. |
| 1468 | */ |
| 1469 | if (lastIndex >= 1) |
| 1470 | { |
| 1471 | final StringTokenizer aTok = new StringTokenizer(aLine, "|", false); |
| 1472 | |
| 1473 | boolean inPipe = false; |
| 1474 | if (aLine.charAt(0) == '|') |
| 1475 | { |
| 1476 | inPipe = true; |
| 1477 | } |
| 1478 | |
| 1479 | boolean lastIsPipe = false; |
| 1480 | if (aLine.charAt(aLine.length() - 1) == '|') |
| 1481 | { |
| 1482 | lastIsPipe = true; |
| 1483 | } |
| 1484 | |
| 1485 | while (aTok.hasMoreTokens()) |
| 1486 | { |
| 1487 | String tok = aTok.nextToken(); |
| 1488 | |
| 1489 | if (inPipe) |
| 1490 | { |
| 1491 | if (aTok.hasMoreTokens() || lastIsPipe) |
| 1492 | { |
| 1493 | replaceToken(tok, output, aPC); |
| 1494 | } |
| 1495 | /* |
| 1496 | * No else condition because we should be between |
| 1497 | * pipes at this point i.e. this should be a token but |
| 1498 | * it appears to be malformed. Malformed because there |
| 1499 | * are no more tokens and the last character of the string |
| 1500 | * is not a pipe |
| 1501 | */ |
| 1502 | } |
| 1503 | else |
| 1504 | { |
| 1505 | outputNonToken(tok, output); |
| 1506 | } |
| 1507 | // Reverse the inPipe state, causing the next token to |
| 1508 | // take the other decision path |
| 1509 | if (aTok.hasMoreTokens()) |
no test coverage detected