HHH-13512 Optimise StringHelper#isQuoted(String, Dialect)

This commit is contained in:
Sanne Grinovero 2019-08-01 15:39:11 +01:00
parent 7f6bf82fed
commit ca444fc487
2 changed files with 15 additions and 6 deletions

View File

@ -711,12 +711,15 @@ public final class StringHelper {
*
* @return True if quoted, false otherwise
*/
public static boolean isQuoted(String name, Dialect dialect) {
return name != null && name.length() != 0
&& ( ( name.charAt( 0 ) == '`' && name.charAt( name.length() - 1 ) == '`' )
|| ( name.charAt( 0 ) == '"' && name.charAt( name.length() - 1 ) == '"' )
|| ( name.charAt( 0 ) == dialect.openQuote()
&& name.charAt( name.length() - 1 ) == dialect.closeQuote() ) );
public static boolean isQuoted(final String name, final Dialect dialect) {
if ( name == null || name.isEmpty() ) {
return false;
}
final char first = name.charAt( 0 );
final char last = name.charAt( name.length() - 1 );
return ( ( first == last ) &&
( first == '`' || first == '"' || first == dialect.closeQuote() ) );
}
/**

View File

@ -83,4 +83,10 @@ public class StringHelperTest extends BaseUnitTestCase {
assertTrue( Arrays.equals( expectation, output ) );
}
@Test
public void testIsQuotedWithDialect() {
Assert.assertFalse( StringHelper.isQuoted( "a", DIALECT ) );
Assert.assertTrue( StringHelper.isQuoted( "`a`", DIALECT ) );
}
}