MCPcopy Create free account
hub / github.com/PCGen/pcgen / replaceToken

Method replaceToken

code/src/java/pcgen/io/ExportHandler.java:1525–1686  ·  view source on GitHub ↗

Replace the token with the value it represents @param aString The string containing the token to be replaced @param output The object that will capture the output @param aPC The PC currently being exported @return value

(String aString, BufferedWriter output, PlayerCharacter aPC)

Source from the content-addressed store, hash-verified

1523 * @return value
1524 */
1525 public int replaceToken(String aString, BufferedWriter output, PlayerCharacter aPC)
1526 {
1527 try
1528 {
1529 // If it is plain text then there's no replacement necessary
1530 if (isPlainText(aString))
1531 {
1532 return 0;
1533 }
1534
1535 // If it is purely a filter everything (not a filter on a specific token)
1536 // then there is nothing to replace so return 0
1537 if ("%".equals(aString))
1538 {
1539 canWrite = true;
1540 return 0;
1541 }
1542
1543 // If the line starts with ${ and ends with } then write the JEP variable
1544 // and return the length of the line (minus any whitespace)
1545 if (aString.startsWith("${") && aString.endsWith("}"))
1546 {
1547 String jepString = aString.substring(2, aString.length() - 1);
1548 String variableValue = aPC.getVariableValue(jepString, "").toString();
1549 FileAccess.write(output, variableValue);
1550 return aString.trim().length();
1551 }
1552
1553 // TODO Why?
1554 FileAccess.maxLength(-1);
1555
1556 // Start the |%blah| token section, e.g. Deal with filtering tokens
1557 // (e.g. If it doesn't meet a criteria then don't write)
1558 // If the string is a non empty filter and does not have a '<' or a '>' in it then replace the token
1559 if (isFilterToken(aString))
1560 {
1561 return dealWithFilteredTokens(aString, aPC);
1562 }
1563
1564 String tokenString = aString;
1565
1566 // now check for max length tokens
1567 // e.g: |SUB10.ARMOR.AC|
1568 if (isValidSubToken(tokenString))
1569 {
1570 tokenString = replaceSubToken(tokenString);
1571 }
1572
1573 // Now check for the rest of the tokens
1574 populateTokenMap();
1575
1576 StringTokenizer tok = new StringTokenizer(tokenString, ".,", false);
1577 String firstToken = tok.nextToken();
1578
1579 // Get the remaining token/test string
1580 // TODO Understand this
1581 String testString = tokenString;
1582 if (testString.indexOf(',') > -1)

Callers 9

replaceTokenSkipMathMethod · 0.95
evaluateExpressionMethod · 0.95
replaceLineMethod · 0.95
replaceTokenForDforMethod · 0.95
processPipedLineMethod · 0.95
doPartyForTokenMethod · 0.95
getTokenMethod · 0.80
getFollowerOutputMethod · 0.80

Calls 15

isPlainTextMethod · 0.95
writeMethod · 0.95
maxLengthMethod · 0.95
isFilterTokenMethod · 0.95
isValidSubTokenMethod · 0.95
replaceSubTokenMethod · 0.95
populateTokenMapMethod · 0.95
isForOrDForTokenMethod · 0.95
processLoopTokenMethod · 0.95
replaceTokenOIFMethod · 0.95

Tested by

no test coverage detected