List of usage examples for java.lang StringBuilder indexOf
@Override public int indexOf(String str)
From source file:com.cohort.util.String2.java
/** * This goes beyond indexOfIgnoreCase by looking after punctuation removed. * * @param s// ww w .j a v a2s. c o m * @param find * @return true if find is loosely in s. Return false if s or find !isSomething. */ public static boolean looselyContains(String s, String find) { if (s == null || find == null) return false; int sLength = s.length(); StringBuilder ssb = new StringBuilder(); for (int i = 0; i < sLength; i++) { char ch = s.charAt(i); if (Character.isLetterOrDigit(ch)) ssb.append(Character.toLowerCase(ch)); } if (ssb.length() == 0) return false; int fLength = find.length(); StringBuilder fsb = new StringBuilder(); for (int i = 0; i < fLength; i++) { char ch = find.charAt(i); if (Character.isLetterOrDigit(ch)) fsb.append(Character.toLowerCase(ch)); } if (fsb.length() == 0) return false; return ssb.indexOf(fsb.toString()) >= 0; }
From source file:com.quinsoft.epamms.ZGlobal1_Operation.java
public int DecipherUsageKeyword(StringBuilder sbName, String openKey, String closeKey, StringBuilder sbKeyword, int keywordMaxLth, StringBuilder sbKeyValue, int keyValueMaxLth) { sbKeyword.setLength(0);// w ww . j a v a2 s . co m sbKeyValue.setLength(0); int nLth = openKey.length(); int nPos1 = sbName.indexOf(openKey); if (nPos1 >= 0) { int nPos2 = sbName.indexOf(closeKey, nPos1 + nLth); if (nPos2 >= 0) { String key = sbName.substring(nPos1 + nLth, nPos2); sbName.delete(nPos1, nPos2 + closeKey.length()); sbKeyValue.append("(" + key + ")"); int nPos = key.indexOf(' ', nLth); if (nPos > 0 && nPos < key.length() - 1) // ignore if space is leading or trailing { key = key.substring(0, nPos) + "#"; } sbKeyword.append(key); sbName.insert(nPos1, "{{" + key + "}}"); return 0; } } return -1; }
From source file:com.quinsoft.epamms.ZGlobal1_Operation.java
private String ScrunchCamelCase(String s) { if (s.length() < 2) return s; if (s.charAt(0) == '(' && s.charAt(s.length() - 1) == ')') s = s.substring(1, s.length() - 1); String[] sub = s.split(" "); StringBuilder sb = new StringBuilder(); int k = 0;//from www.java2 s . com while (k < sub.length) { if (sub[k].length() > 0 && (sub.length == 1 || (sub[k].compareToIgnoreCase("or") != 0 && sub[k].compareToIgnoreCase("and") != 0))) { sb.append(sub[k].substring(0, 1).toUpperCase()).append(sub[k].substring(1)); } k++; } k = sb.indexOf("PpmActive"); if (k >= 0) { sb.replace(k, k + 9, "PPM"); } return sb.toString(); }
From source file:com.quinsoft.zeidon.vml.VmlOperation.java
protected static final String zSearchAndReplace(String tgtString, int tgtLth, String searchString, String replaceString) {/*from ww w .j a v a2 s. co m*/ StringBuilder sb = new StringBuilder(tgtString); int position = sb.indexOf(searchString); while (position >= 0) { //sbString.replace( position, position + searchString.length( ) - 1, replaceString ); sb.replace(position, position + searchString.length(), replaceString); position = position + replaceString.length(); position = sb.indexOf(searchString, position); } return sb.toString(); }
From source file:com.quinsoft.zeidon.vml.VmlOperation.java
protected static final int zSearchAndReplace(StringBuilder sbString, int tgtLth, String searchString, String replaceString) {/* w w w . j a v a 2 s . co m*/ int position = sbString.indexOf(searchString); while (position >= 0) { //sbString.replace( position, position + searchString.length( ) - 1, replaceString ); sbString.replace(position, position + searchString.length(), replaceString); position = position + replaceString.length(); position = sbString.indexOf(searchString, position); } return sbString.length(); }
From source file:org.grible.servlets.ui.Home.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse * response)/* ww w . j ava2 s . c om*/ */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); try { if (!GlobalSettings.getInstance().init(getServletContext().getRealPath(""))) { response.sendRedirect("/firstlaunch"); return; } StringBuilder responseHtml = new StringBuilder(); responseHtml.append("<!DOCTYPE html>"); responseHtml.append("<html>"); responseHtml.append("<head>"); responseHtml.append("<title>Grible</title>"); responseHtml.append("<link rel=\"shortcut icon\" href=\"img/favicon.ico\" >"); responseHtml.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/style.css\" />"); responseHtml .append("<link href=\"css/jquery.contextMenu.css\" rel=\"stylesheet\" type=\"text/css\" />"); responseHtml.append("<script type=\"text/javascript\" src=\"js/jquery-1.11.0.min.js\"></script>"); responseHtml.append("<script type=\"text/javascript\" src=\"js/jquery-ui.min.js\"></script>"); responseHtml.append("<script type=\"text/javascript\" src=\"lang/current.json\"></script>"); responseHtml.append("<script type=\"text/javascript\" src=\"js/home.js\"></script>"); responseHtml.append("<script type=\"text/javascript\" src=\"js/jquery.contextMenu.js\"></script>"); responseHtml.append("<script type=\"text/javascript\" src=\"js/noty/jquery.noty.js\"></script>"); responseHtml.append("<script type=\"text/javascript\" src=\"js/noty/top.js\"></script>"); responseHtml.append("<script type=\"text/javascript\" src=\"js/noty/defaultVarsHome.js\"></script>"); responseHtml.append("<script type=\"text/javascript\" src=\"js/noty/default.js\"></script>"); responseHtml.append("<script type=\"text/javascript\">"); responseHtml.append("var appType = \"") .append(GlobalSettings.getInstance().getAppType().toString().toLowerCase()).append("\";"); if (!isMultipleUsers()) { responseHtml.append("var productsWhosePathsNotExist = ").append(getProductsWhosePathsNotExist()) .append(";"); } else { responseHtml.append("var productsWhosePathsNotExist = [];"); } responseHtml.append("</script>"); responseHtml.append("</head>"); responseHtml.append("<body>"); if (isMultipleUsers() && request.getSession(false).getAttribute("userName") == null) { responseHtml.append("<div id=\"login-form\" class=\"table\">"); responseHtml.append("<div class=\"table-row\">"); responseHtml.append("<div id=\"login-grible-logo\" class=\"table-cell\">"); responseHtml.append("<img id=\"login-logo\" src=\"img/grible_logo.png\">"); responseHtml.append("</div>"); responseHtml.append("<div id=\"outer-credentials\" class=\"table-cell\">"); responseHtml.append("<form method=\"post\" action=\"Login\">"); responseHtml.append("<div id=\"credentials\" class=\"table\">"); responseHtml.append("<div class=\"table-row\">"); responseHtml.append("<div class=\"table-cell dialog-cell dialog-label\">"); responseHtml.append(Lang.get("username")); responseHtml.append(":</div>"); responseHtml.append("<div class=\"table-cell dialog-cell dialog-edit\">"); responseHtml.append("<input class=\"dialog-edit\" name=\"username\" style=\"width: 250px\"></div>"); responseHtml.append("</div>"); responseHtml.append("<div class=\"table-row\">"); responseHtml.append("<div class=\"table-cell dialog-cell dialog-label\">"); responseHtml.append(Lang.get("password")); responseHtml.append(":</div>"); responseHtml.append("<div class=\"table-cell dialog-cell dialog-edit\">"); responseHtml.append( "<input type=\"password\" class=\"dialog-edit\" name=\"pass\" style=\"width: 250px\"></div>"); responseHtml.append("</div>"); responseHtml.append("</div>"); if (request.getParameter("url") != null) { responseHtml.append( "<input type=\"hidden\" name=\"url\" value=\"" + request.getParameter("url") + "\">"); } responseHtml.append("<div class=\"login-dialog-buttons table\">"); responseHtml.append("<div class=\"table-row\">"); responseHtml.append("<div id=\"outer-dialog-error-message\" class=\"table-cell\">"); if (request.getSession(false).getAttribute("loginFailed") != null) { String message = (String) request.getSession(false).getAttribute("loginFailed"); responseHtml.append("<span class=\"dialog-error-message\">" + message + "</span>"); } responseHtml.append("</div>"); responseHtml.append("<div class=\"table-cell\">"); responseHtml.append("<script type=\"text/javascript\">document.write("); responseHtml.append("'<input type=\"submit\" value=\"'+ lang['login'] + '\" "); responseHtml.append("class=\"ui-button\">')</script>"); responseHtml.append("</div>"); responseHtml.append("</div>"); responseHtml.append("</div>"); responseHtml.append("</form>"); responseHtml.append("</div>"); responseHtml.append("</div>"); responseHtml.append("</div>"); } else { User user = null; if (isMultipleUsers()) { String userName = (String) request.getSession(false).getAttribute("userName"); user = new PostgresDao().getUserByName(userName); responseHtml.append(ServletHelper.getUserPanel(user)); } else { responseHtml.append(ServletHelper.getUserPanel()); } responseHtml.append("<div id=\"breadcrumb\" class=\"header-text\">"); responseHtml.append("<span id=\"home-image\"><img src=\"img/grible_logo_mini.png\"></span>"); responseHtml.append("<a href=\".\"><span id=\"home\">"); responseHtml.append(Lang.get("home")); responseHtml.append("</span></a>"); if (request.getParameter("product") != null) { if (StringUtils.isNumeric(request.getParameter("product"))) { int id = Integer.parseInt(request.getParameter("product")); Product product = DataManager.getInstance().getDao().getProduct(id); if (product != null) { responseHtml.replace(responseHtml.indexOf("id=\"home\">") + 9, responseHtml.indexOf("id=\"home\">") + 10, " class=\"link-infront\">"); responseHtml.append("<span class=\"extends-symbol\"> > </span>"); responseHtml.append("<a href=\"?product=" + id + "\"><span id=\"product-name\">"); responseHtml.append(product.getName()); responseHtml.append("</span></a></div>"); if (isMultipleUsers() && (!user.hasAccessToProduct(product.getId()))) { responseHtml.append("<br/><br/>"); responseHtml.append("<div class=\"error-message\">"); responseHtml.append(Lang.get("nopermissions") + "</div>"); } else { includeSections(responseHtml, product); } } else { response.sendRedirect("/"); } } else { response.sendRedirect("/"); } } else { responseHtml.append("</div>"); responseHtml.append("<div class=\"table\">"); List<Product> products = DataManager.getInstance().getDao().getProducts(); for (Product product : products) { if ((isMultipleUsers() && user.hasAccessToProduct(product.getId())) || (!isMultipleUsers())) { responseHtml.append("<div class=\"table-row\">"); responseHtml.append("<div class=\"table-cell section-cell\">"); responseHtml.append("<a href=\"?product=" + product.getId() + "\"><span id=\"" + product.getId() + "\" class=\"section product-item\">" + product.getName() + "</span></a>"); responseHtml.append("</div>"); responseHtml.append("</div>"); } } responseHtml.append("</div>"); if ((isMultipleUsers() && user.isAdmin()) || (!isMultipleUsers())) { responseHtml.append("<div class=\"under-sections\">"); responseHtml.append("<div class=\"icon-button button-enabled\" id=\"btn-add-product\">"); responseHtml.append("<img src=\"img/add-icon.png\" class=\"icon-enabled\">"); responseHtml.append( "<span class=\"icon-button-text\"> " + Lang.get("addproduct") + "</span></div>"); responseHtml.append("<p><img src=\"img/info-icon.png\"><span class=\"msg-text\">" + "<a href=\"#\" id=\"lnk-product-info\">" + Lang.get("whatisproduct") + "</a></span></p>"); responseHtml.append("</div>"); } responseHtml.append("<div id=\"video-tutorial-msg\">"); responseHtml.append("<img src=\"img/info-icon.png\"> "); responseHtml.append("<span class=\"msg-text\">" + Lang.get("newtogrible1")); responseHtml.append("<a href=\"http://www.grible.org/docs.php#video\" "); responseHtml.append("target=\"_blank\">" + Lang.get("video") + "</a>"); responseHtml.append(Lang.get("newtogrible2")); responseHtml.append("</span>"); responseHtml.append("</div>"); } responseHtml.append(ServletHelper.getFooter(getServletContext().getRealPath(""))); } responseHtml.append("</body>"); responseHtml.append("</html>"); out.print(responseHtml.toString()); } catch (Exception e) { e.printStackTrace(out); } finally { out.flush(); out.close(); } }
From source file:forge.game.card.Card.java
private StringBuilder abilityTextInstantSorcery(CardState state) { final StringBuilder sb = new StringBuilder(); // Give spellText line breaks for easier reading sb.append(text.replaceAll("\\\\r\\\\n", "\r\n")); // NOTE:/*from w w w.j a va 2 s . com*/ if (sb.toString().contains(" (NOTE: ")) { sb.insert(sb.indexOf("(NOTE: "), "\r\n"); } if (sb.toString().contains("(NOTE: ") && sb.toString().endsWith(".)") && !sb.toString().endsWith("\r\n")) { sb.append("\r\n"); } // I think SpellAbilities should be displayed after Keywords // Add SpellAbilities for (final SpellAbility element : state.getSpellAbilities()) { sb.append(formatSpellAbility(element)); } // Add Keywords final List<String> kw = getKeywords(state); // Triggered abilities for (final Trigger trig : state.getTriggers()) { if (!trig.isSecondary()) { sb.append(trig.toString()).append("\r\n"); } } // Replacement effects for (final ReplacementEffect replacementEffect : state.getReplacementEffects()) { sb.append(replacementEffect.toString()).append("\r\n"); } // static abilities for (final StaticAbility stAb : state.getStaticAbilities()) { final String stAbD = stAb.toString(); if (!stAbD.equals("")) { sb.append(stAbD).append("\r\n"); } } // TODO A lot of these keywords should really show up before the SAs // keyword descriptions for (final String keyword : kw) { if ((keyword.startsWith("Ripple") && !sb.toString().contains("Ripple")) || (keyword.startsWith("Dredge") && !sb.toString().contains("Dredge")) || (keyword.startsWith("CARDNAME is ") && !sb.toString().contains("CARDNAME is "))) { sb.append(keyword.replace(":", " ")).append("\r\n"); } else if ((keyword.startsWith("Madness") && !sb.toString().contains("Madness")) || (keyword.startsWith("Recover") && !sb.toString().contains("Recover")) || (keyword.startsWith("Miracle") && !sb.toString().contains("Miracle"))) { String[] parts = keyword.split(":"); sb.append(parts[0]).append(" ").append(ManaCostParser.parse(parts[1])).append("\r\n"); } else if (keyword.equals("CARDNAME can't be countered.") || keyword.startsWith("May be played") || keyword.startsWith("Conspire") || keyword.startsWith("Cascade") || keyword.startsWith("Wither") || (keyword.startsWith("Epic") && !sb.toString().contains("Epic")) || (keyword.startsWith("Split second") && !sb.toString().contains("Split second")) || (keyword.startsWith("Devoid"))) { sb.append(keyword).append("\r\n"); } else if (keyword .equals("You may cast CARDNAME as though it had flash if you pay 2 more to cast it.")) { sb.append(keyword).append("\r\n"); } else if (keyword.startsWith("Flashback")) { sb.append("Flashback"); if (keyword.contains(" ")) { final Cost fbCost = new Cost(keyword.substring(10), true); if (!fbCost.isOnlyManaCost()) { sb.append(" -"); } sb.append(" ").append(fbCost.toString()).delete(sb.length() - 2, sb.length()); if (!fbCost.isOnlyManaCost()) { sb.append("."); } } sb.append("\r\n"); } else if (keyword.startsWith("Splice")) { final Cost cost = new Cost(keyword.substring(19), false); sb.append("Splice onto Arcane ").append(cost.toSimpleString()).append("\r\n"); } else if (keyword.startsWith("Buyback")) { final Cost cost = new Cost(keyword.substring(8), false); sb.append("Buyback ").append(cost.toSimpleString()); sb.append( " (You may pay an additional cost as you cast CARDNAME. If you do, put CARDNAME back into your hand as it resolves.)"); sb.append("\r\n"); } else if (keyword.startsWith("Entwine")) { final Cost cost = new Cost(keyword.substring(8), false); sb.append("Entwine ").append(cost.toSimpleString()); sb.append(" (Choose both if you pay the entwine cost.)"); sb.append("\r\n"); } else if (keyword.startsWith("Multikicker")) { if (!keyword.endsWith("Generic")) { final Cost cost = new Cost(keyword.substring(7), false); sb.append("Multikicker ").append(cost.toSimpleString()).append("\r\n"); } } else if (keyword.startsWith("Kicker")) { if (!keyword.endsWith("Generic")) { final Cost cost = new Cost(keyword.substring(7), false); sb.append("Kicker ").append(cost.toSimpleString()).append("\r\n"); } } else if (keyword.startsWith("AlternateAdditionalCost")) { final String costString1 = keyword.split(":")[1]; final String costString2 = keyword.split(":")[2]; final Cost cost1 = new Cost(costString1, false); final Cost cost2 = new Cost(costString2, false); sb.append("As an additional cost to cast ").append(state.getName()).append(", ") .append(cost1.toSimpleString()).append(" or pay ").append(cost2.toSimpleString()) .append(".\r\n"); } else if (keyword.startsWith("Storm")) { if (sb.toString().contains("Target") || sb.toString().contains("target")) { sb.insert(sb.indexOf( "Storm (When you cast this spell, copy it for each spell cast before it this turn.") + 81, " You may choose new targets for the copies."); } } else if (keyword.startsWith("Replicate") && !sb.toString().contains("you paid its replicate cost.")) { if (sb.toString().endsWith("\r\n\r\n")) { sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3); } sb.append(keyword); sb.append(" (When you cast this spell, copy it for each time you paid its replicate cost."); if (sb.toString().contains("Target") || sb.toString().contains("target")) { sb.append(" You may choose new targets for the copies."); } sb.append(")\r\n"); } else if (keyword.startsWith("Haunt")) { if (sb.toString().endsWith("\r\n\r\n")) { sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3); } sb.append("Haunt ("); if (state.getType().isCreature()) { sb.append("When this creature dies, exile it haunting target creature."); } else { sb.append("When this spell card is put into a graveyard after resolving, "); sb.append("exile it haunting target creature."); } sb.append(")\r\n"); } else if (keyword.equals("Convoke")) { if (sb.toString().endsWith("\r\n\r\n")) { sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3); } sb.append( "Convoke (Each creature you tap while casting this spell pays for {1} or one mana of that creature's color.)\r\n"); } else if (keyword.equals("Delve")) { if (sb.toString().endsWith("\r\n\r\n")) { sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3); } sb.append( "Delve (Each card you exile from your graveyard while casting this spell pays for {1}.)\r\n"); } else if (keyword.endsWith(" offering")) { if (sb.toString().endsWith("\r\n\r\n")) { sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3); } String offeringType = keyword.split(" ")[0]; sb.append(keyword); sb.append(" (You may cast this card any time you could cast an instant by sacrificing a "); sb.append(offeringType); sb.append("and paying the difference in mana costs between this and the sacrificed "); sb.append(offeringType); sb.append(". Mana cost includes color.)"); } else if (keyword .equals("Remove CARDNAME from your deck before playing if you're not playing for ante.")) { if (sb.toString().endsWith("\r\n\r\n")) { sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3); } sb.append("Remove CARDNAME from your deck before playing if you're not playing for ante.\r\n"); } else if (keyword.equals("Rebound")) { sb.append(keyword).append( " (If you cast this spell from your hand, exile it as it resolves. At the beginning of your next upkeep, you may cast this card from exile without paying its mana cost.)\r\n"); } } return sb; }
From source file:com.quinsoft.zeidon.vml.VmlOperation.java
protected String zExpungeAllSubstring(String string, String subString) { int nLth = subString.length(); int k;//from w w w .jav a 2 s.c om if (nLth > 0) { StringBuilder sb = new StringBuilder(string); nLth--; while ((k = sb.indexOf(subString)) >= 0) { sb.replace(k, k + nLth, ""); } string = sb.toString(); } return string; }
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
/** * Pdf verify./*from w w w. j av a2 s . c om*/ * * @param filePath * the file path * @param pageNumberRange * the page number range * @param verifyType * the verify type * @param inputString * the input string * @param stopOnFaliure * the stop on faliure */ private void pdfVerify(final String filePath, final String pageNumberRange, final String verifyType, final String inputString, final boolean stopOnFaliure, final Object[] customError) { String pageText; if ("RELATIVE".equalsIgnoreCase(verifyType)) { String[] inputStringSeperate = inputString.split("\\,"); String key = inputStringSeperate[0]; String value = inputStringSeperate[1]; String[] pageSeperate = pageNumberRange.split("\\-"); int startPage = Integer.parseInt(pageSeperate[0]); int endPage = Integer.parseInt(pageSeperate[1]); try { File file = new File(filePath); PDDocument pdfDoc = PDDocument.load(file); PDFTextStripper reader = new PDFTextStripper(); reader.setStartPage(startPage); reader.setEndPage(endPage); reader.setSuppressDuplicateOverlappingText(false); pageText = reader.getText(pdfDoc); BufferedReader br = new BufferedReader(new StringReader(pageText)); String tmp = ""; boolean isPresent = false; StringBuilder entireString = new StringBuilder(); while ((tmp = br.readLine()) != null) { if (tmp.equals(key)) { String val = br.readLine(); if (val != null && val.equals(value)) { isPresent = true; break; } else { continue; } } entireString.append(tmp); } if (entireString.toString().contains(key)) { int index = entireString.indexOf(key); String subEntire = entireString.toString().substring(index); String newString = subEntire.replace(key, ""); if (newString.trim().startsWith(value)) { isPresent = true; } } if (isPresent) { reportresult(true, "CHECK DOCUMENT :", "PASSED", "CheckDocument command: Verified text as expected. Expected Value : " + inputString); } else { if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) { reportresult(true, "CHECK DOCUMENT :", "FAILED", " Custom Error :" + generateCustomError(customError) + " System generated Error : CheckDocument command: Verified text as not expected. Expected Value : " + inputString); checkTrue(false, stopOnFaliure, " Custom Error :" + generateCustomError(customError) + " System generated Error : CheckDocument command: Verified text as not expected. Expected Value : " + inputString); } else { reportresult(true, "CHECK DOCUMENT :", "FAILED", "CheckDocument command: Verified text as not expected. Expected Value : " + inputString); checkTrue(false, stopOnFaliure, "CheckDocument command: Verified text as not expected : " + inputString); } } } catch (Exception e) { if (customError != null && !(customError[0].equals("null") || customError[0].equals(""))) { reportresult(true, "CHECK DOCUMENT :", "FAILED", " Custom Error :" + generateCustomError(customError) + " System generated Error : CheckDocument command: Text Verification failed: " + inputString); checkTrue(false, stopOnFaliure, " Custom Error :" + generateCustomError(customError) + " System generated Error : CheckDocument command: Text Verification failed: " + inputString + e.getMessage()); } else { reportresult(true, "CHECK DOCUMENT :", "FAILED", "CheckDocument command: Verified text as not expected. Expected Value : " + inputString); checkTrue(false, stopOnFaliure, "CheckDocument command: Verified text as not expected : " + inputString); } } } }
From source file:forge.game.card.Card.java
public String getAbilityText(final CardState state) { final CardTypeView type = state.getType(); final StringBuilder sb = new StringBuilder(); if (!mayPlay.isEmpty()) { sb.append("May be played by: "); sb.append(//from w w w . j av a 2 s . co m Lang.joinHomogenous(mayPlay.entrySet(), new Function<Entry<Player, CardPlayOption>, String>() { @Override public String apply(final Entry<Player, CardPlayOption> entry) { return entry.getKey().toString() + entry.getValue().toString(); } })); sb.append("\r\n"); } if (type.isInstant() || type.isSorcery()) { sb.append(abilityTextInstantSorcery(state)); if (haunting != null) { sb.append("Haunting: ").append(haunting); sb.append("\r\n"); } while (sb.toString().endsWith("\r\n")) { sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + 3); } return sb.toString().replaceAll("CARDNAME", state.getName()); } if (monstrous) { sb.append("Monstrous\r\n"); } if (renowned) { sb.append("Renowned\r\n"); } if (manifested) { sb.append("Manifested\r\n"); } sb.append(keywordsToText(getUnhiddenKeywords(state))); // Give spellText line breaks for easier reading sb.append("\r\n"); sb.append(text.replaceAll("\\\\r\\\\n", "\r\n")); sb.append("\r\n"); // Triggered abilities for (final Trigger trig : state.getTriggers()) { if (!trig.isSecondary()) { sb.append(trig.toString().replaceAll("\\\\r\\\\n", "\r\n")).append("\r\n"); } } // Replacement effects for (final ReplacementEffect replacementEffect : state.getReplacementEffects()) { if (!replacementEffect.isSecondary()) { sb.append(replacementEffect.toString()).append("\r\n"); } } // static abilities for (final StaticAbility stAb : state.getStaticAbilities()) { sb.append(stAb.toString()).append("\r\n"); } final List<String> addedManaStrings = new ArrayList<>(); boolean primaryCost = true; boolean isNonAura = !type.hasSubtype("Aura"); for (final SpellAbility sa : state.getSpellAbilities()) { // only add abilities not Spell portions of cards if (sa == null || !state.getType().isPermanent()) { continue; } boolean isNonAuraPermanent = (sa instanceof SpellPermanent) && isNonAura; if (isNonAuraPermanent && primaryCost) { // For Alt costs, make sure to display the cost! primaryCost = false; continue; } final String sAbility = formatSpellAbility(sa); if (sa.getManaPart() != null) { if (addedManaStrings.contains(sAbility)) { continue; } addedManaStrings.add(sAbility); } if (isNonAuraPermanent) { sb.insert(0, "\r\n"); sb.insert(0, sAbility); } else if (!sAbility.endsWith(state.getName() + "\r\n")) { sb.append(sAbility); sb.append("\r\n"); } } // NOTE: if (sb.toString().contains(" (NOTE: ")) { sb.insert(sb.indexOf("(NOTE: "), "\r\n"); } if (sb.toString().contains("(NOTE: ") && sb.toString().contains(".) ")) { sb.insert(sb.indexOf(".) ") + 3, "\r\n"); } // replace triple line feeds with double line feeds int start; final String s = "\r\n\r\n\r\n"; while (sb.toString().contains(s)) { start = sb.lastIndexOf(s); if ((start < 0) || (start >= sb.length())) { break; } sb.replace(start, start + 4, "\r\n"); } return sb.toString().replaceAll("CARDNAME", state.getName()).trim(); }