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

Method getToken

code/src/java/plugin/exporttokens/TextToken.java:54–161  ·  view source on GitHub ↗
(String tokenSource, PlayerCharacter pc, ExportHandler eh)

Source from the content-addressed store, hash-verified

52 }
53
54 @Override
55 public String getToken(String tokenSource, PlayerCharacter pc, ExportHandler eh)
56 {
57
58 StringTokenizer aTok = new StringTokenizer(tokenSource, ".");
59 aTok.nextToken(); //this should be VAR
60
61 StringBuilder action = new StringBuilder();
62 StringBuilder varName = new StringBuilder();
63 if (aTok.hasMoreElements())
64 {
65 action = new StringBuilder(aTok.nextToken());
66 if (action.toString().startsWith("REPLACE"))
67 {
68 // Make sure that any "." in the token itself stay together
69 while (action.charAt(action.length() - 1) != '}')
70 {
71 action.append('.').append(aTok.nextToken());
72 }
73 }
74 }
75 if (aTok.hasMoreElements())
76 {
77 varName.append(aTok.nextToken());
78 }
79 while (aTok.hasMoreElements())
80 {
81 varName.append('.').append(aTok.nextToken());
82 }
83
84 StringWriter writer = new StringWriter();
85 BufferedWriter bw = new BufferedWriter(writer);
86 eh.replaceToken(varName.toString(), bw, pc);
87 try
88 {
89 bw.flush();
90 }
91 catch (IOException e)
92 {
93 Logging.errorPrint("TextToken error", e);
94 }
95 String retString = writer.getBuffer().toString();
96
97 if (action.toString().equalsIgnoreCase("UPPER") || action.toString().equalsIgnoreCase("UPPERCASE"))
98 {
99 retString = retString.toUpperCase(Locale.getDefault());
100 }
101 else if (action.toString().equalsIgnoreCase("LOWER") || action.toString().equalsIgnoreCase("LOWERCASE"))
102 {
103 retString = retString.toLowerCase(Locale.getDefault());
104 }
105 else if (action.toString().equalsIgnoreCase("SENTENCE") || action.toString().equalsIgnoreCase("SENTENCECASE"))
106 {
107 retString = changeToSentenceCase(retString);
108 }
109 else if (action.toString().equalsIgnoreCase("TITLE") || action.toString().equalsIgnoreCase("TITLECASE"))
110 {
111 retString = changeToTitleCase(retString);

Callers 3

testTextFormattingMethod · 0.95
testNumSuffixMethod · 0.95
testNumSuffixDirectMethod · 0.95

Calls 15

errorPrintMethod · 0.95
changeToSentenceCaseMethod · 0.95
changeToTitleCaseMethod · 0.95
buildNumSuffixMethod · 0.95
nextTokenMethod · 0.80
replaceTokenMethod · 0.80
equalsIgnoreCaseMethod · 0.80
trimMethod · 0.80
toStringMethod · 0.65
getDefaultMethod · 0.65
indexOfMethod · 0.65
appendMethod · 0.45

Tested by 3

testTextFormattingMethod · 0.76
testNumSuffixMethod · 0.76
testNumSuffixDirectMethod · 0.76