TableNameUtil { public String escapeTableName(final CharSequence tableName) { boolean toQuote = false; int apostropheCount = 0; for (int i = 0; i < tableName.length(); i++) { final char c = tableName.charAt(i); if (Character.isWhitespace(c) || c == '.') { toQuote = true; } else if (c == '\'') { toQuote = true; apostropheCount += 1; } } final StringBuilder sb = new StringBuilder(tableName.length() + (toQuote ? 2 : 0) + apostropheCount); if (toQuote) { sb.append(SINGLE_QUOTE); } for (int i = 0; i < tableName.length(); i++) { final char c = tableName.charAt(i); sb.append(c); if (c == '\'') { sb.append(SINGLE_QUOTE); } } if (toQuote) { sb.append(SINGLE_QUOTE); } return sb.toString(); }  void checkTableName(final CharSequence name); String escapeTableName(final CharSequence tableName); String unescapeFilename(final String filename); String unescapeQuotes(final String str);  }
@Test public void escapeTableNameOk() { Assert.assertEquals("no_problem", this.util.escapeTableName("no_problem")); }
@Test public void escapeTableNameSpace() { Assert.assertEquals("'a space'", this.util.escapeTableName("a space")); }
@Test public void escapeTableNameQuote() { Assert.assertEquals("'a '' quote'", this.util.escapeTableName("a ' quote")); }
@Test public void escapeTableNameTwoQuotes() { Assert.assertEquals("'two '' '' quotes'", this.util.escapeTableName("two ' ' quotes")); }
@Test public void escapeTableNameBlank() { Assert.assertEquals("'a\nnewline'", this.util.escapeTableName("a\nnewline")); }
@Test public void escapeTableNameDot() { Assert.assertEquals("'a.dot'", this.util.escapeTableName("a.dot")); }