MCPcopy Create free account
hub / github.com/Aghajari/MathParser / fix

Method fix

MathParser/src/com/aghajari/math/MathParser.java:238–273  ·  view source on GitHub ↗
(String src, String function, char c)

Source from the content-addressed store, hash-verified

236 }
237
238 private String fix(String src, String function, char c) {
239 int index;
240 while ((index = src.indexOf(c)) != -1) {
241 boolean applyToFirst = true, ph = false;
242 int count = 0;
243
244 for (int i = index - 1; i >= 0; i--) {
245 if (i == index - 1 && src.charAt(i) == ')') {
246 ph = true;
247 count++;
248 continue;
249 }
250 if (ph) {
251 if (src.charAt(i) == ')') {
252 count++;
253 } else if (src.charAt(i) == '(') {
254 count--;
255 }
256 if (count != 0)
257 continue;
258 ph = false;
259 }
260 if (!isSpecialSign(src.charAt(i)))
261 continue;
262
263 String sign = isSpecialSign(src.charAt(i)) ? "" : "*";
264 i++;
265 src = src.substring(0, i) + sign + function + "(" + src.substring(i, index) + ")" + src.substring(index + 1);
266 applyToFirst = false;
267 break;
268 }
269 if (applyToFirst)
270 src = function + "(" + src.substring(0, index) + ")" + src.substring(index + 1);
271 }
272 return src;
273 }
274
275 /**
276 * (2e+2) -> (200.0)

Callers 2

fixDegreesMethod · 0.95
fixFactorialMethod · 0.95

Calls 1

isSpecialSignMethod · 0.95

Tested by

no test coverage detected