HHH-13512 Optimise StringHelper#isQuoted(String, Dialect)
This commit is contained in:
parent
7f6bf82fed
commit
ca444fc487
|
@ -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() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue