/** * Unescapes CSS string by removing all backslash characters from it. */ protected String unescape(final String value) { if (value.indexOf('\\') == -1) { return value; } return StringUtil.remove(value, '\\'); }
@Test void testRemove() { String s = "qwertyq"; assertEquals("qwertyq", StringUtil.remove(s, "W")); assertEquals("qertyq", StringUtil.remove(s, "w")); assertEquals("", StringUtil.remove(s, "qwertyq")); assertEquals("qwertyq", StringUtil.remove(s, "")); assertEquals("werty", StringUtil.remove(s, "q")); assertEquals("qq", StringUtil.remove(s, "werty")); assertEquals("werty", StringUtil.removeChars(s, "q")); assertEquals("werty", StringUtil.remove(s, 'q')); assertEquals(s, StringUtil.remove(s, 'x')); assertEquals("qeryq", StringUtil.removeChars(s, "wt")); assertEquals("qeryq", StringUtil.removeChars(s, 'w', 't')); assertEquals("", StringUtil.removeChars(s, "qwerty".toCharArray())); assertEquals("", StringUtil.removeChars(s, "qwerty")); }
/** * Converts all tabs on a line to spaces according to the provided tab width. * This is not a simple tab to spaces replacement, since the resulting * indentation remains the same. */ public static String convertTabsToSpaces(String line, int tabWidth) { int tab_index, tab_size; int last_tab_index = 0; int added_chars = 0; if (tabWidth == 0) { return remove(line, '\t'); } StringBuilder result = new StringBuilder(); while ((tab_index = line.indexOf('\t', last_tab_index)) != -1) { tab_size = tabWidth - ((tab_index + added_chars) % tabWidth); if (tab_size == 0) { tab_size = tabWidth; } added_chars += tab_size - 1; result.append(line.substring(last_tab_index, tab_index)); result.append(repeat(' ', tab_size)); last_tab_index = tab_index+1; } if (last_tab_index == 0) { return line; } result.append(line.substring(last_tab_index)); return result.toString(); }
/** * Converts all tabs on a line to spaces according to the provided tab width. * This is not a simple tab to spaces replacement, since the resulting * indentation remains the same. */ public static String convertTabsToSpaces(final String line, final int tabWidth) { int tab_index, tab_size; int last_tab_index = 0; int added_chars = 0; if (tabWidth == 0) { return StringUtil.remove(line, '\t'); } StringBuilder result = new StringBuilder(); while ((tab_index = line.indexOf('\t', last_tab_index)) != -1) { tab_size = tabWidth - ((tab_index + added_chars) % tabWidth); if (tab_size == 0) { tab_size = tabWidth; } added_chars += tab_size - 1; result.append(line, last_tab_index, tab_index); result.append(StringUtil.repeat(' ', tab_size)); last_tab_index = tab_index+1; } if (last_tab_index == 0) { return line; } result.append(line.substring(last_tab_index)); return result.toString(); }
@Test void testBytes() { try { File file = new File(dataRoot + "/file/a.txt"); byte[] bytes = FileUtil.readBytes(dataRoot + "/file/a.txt"); assertEquals(file.length(), bytes.length); String content = new String(bytes); content = StringUtil.remove(content, '\r'); assertEquals("test file\n", content); } catch (IOException ioex) { fail(ioex.toString()); } }
@Test public void smtest() throws IOException { String html = read("smtest.html", false); LagartoDOMBuilder lagartoDOMBuilder = new LagartoDOMBuilder(); lagartoDOMBuilder.enableHtmlPlusMode(); lagartoDOMBuilder.enableDebug(); Document doc = lagartoDOMBuilder.parse(html); html = html(doc); String out = read("smtest-out.html", true); // still not working out = StringUtil.remove(out, "<tbody>\n"); out = StringUtil.remove(out, "</tbody>\n"); html = StringUtil.replace(html, "<td>\nnotworking</td>", "<tr>\n<td>\nnotworking</td>\n</tr>"); assertEquals(out, html); }
@Test void testText1() { String html = readFile("text1.html"); String text = jerry(html).$("div.demo-container").text(); String sub = (SystemUtil.info().isWindows()) ? "\r\n" : "\n"; text = StringUtil.remove(text, sub).trim(); text = StringUtil.compressChars(text, ' '); assertEquals("Demonstration Box list item 1 list item 2", text); }
@Test void testNoClassHintsForCollections() { JsonParser.Defaults.classMetadataName = "class"; JsonSerializer.Defaults.classMetadataName = "class"; JsonParsers.forEachParser(jsonParser -> { Hero superman = creator.createSuperman(); String json = new JsonSerializer() .include("powers") // redudant .include("powers.class") .withSerializer("powers.class", new SimpleClassnameTransformer()) .exclude("*.class") .serialize(superman); int count = StringUtil.count(json, "***"); assertEquals(4, count); json = StringUtil.remove(json, "***"); Hero jsonSuperMan = jsonParser .map("lair", SecretLair.class) .map("secretIdentity", SecretIdentity.class) .parse(json, Hero.class); assertEquals("Fortress of Solitude", jsonSuperMan.getLair().getName()); assertHeroHasSuperPowers(jsonSuperMan); }); }
/** * Unescapes CSS string by removing all backslash characters from it. */ protected String unescape(String value) { if (value.indexOf('\\') == -1) { return value; } return StringUtil.remove(value, '\\'); }
/** * Unescapes CSS string by removing all backslash characters from it. */ protected String unescape(final String value) { if (value.indexOf('\\') == -1) { return value; } return StringUtil.remove(value, '\\'); }
/** * Converts all tabs on a line to spaces according to the provided tab width. * This is not a simple tab to spaces replacement, since the resulting * indentation remains the same. */ public static String convertTabsToSpaces(final String line, final int tabWidth) { int tab_index, tab_size; int last_tab_index = 0; int added_chars = 0; if (tabWidth == 0) { return StringUtil.remove(line, '\t'); } StringBuilder result = new StringBuilder(); while ((tab_index = line.indexOf('\t', last_tab_index)) != -1) { tab_size = tabWidth - ((tab_index + added_chars) % tabWidth); if (tab_size == 0) { tab_size = tabWidth; } added_chars += tab_size - 1; result.append(line, last_tab_index, tab_index); result.append(StringUtil.repeat(' ', tab_size)); last_tab_index = tab_index+1; } if (last_tab_index == 0) { return line; } result.append(line.substring(last_tab_index)); return result.toString(); }
/** * Converts all tabs on a line to spaces according to the provided tab width. * This is not a simple tab to spaces replacement, since the resulting * indentation remains the same. */ public static String convertTabsToSpaces(String line, int tabWidth) { int tab_index, tab_size; int last_tab_index = 0; int added_chars = 0; if (tabWidth == 0) { return remove(line, '\t'); } StringBuilder result = new StringBuilder(); while ((tab_index = line.indexOf('\t', last_tab_index)) != -1) { tab_size = tabWidth - ((tab_index + added_chars) % tabWidth); if (tab_size == 0) { tab_size = tabWidth; } added_chars += tab_size - 1; result.append(line.substring(last_tab_index, tab_index)); result.append(repeat(' ', tab_size)); last_tab_index = tab_index + 1; } if (last_tab_index == 0) { return line; } result.append(line.substring(last_tab_index)); return result.toString(); }