Skip to content

Commit

Permalink
Prepare 0.13.2.
Browse files Browse the repository at this point in the history
Signed-off-by: Kenneth J. Shackleton <[email protected]>
  • Loading branch information
kennethshackleton committed Jun 5, 2021
1 parent e6bdd0f commit 39d8d7d
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Change Log
==========

## Version 0.13.2

### Optimisations

* Optimise trimming an SQL statement string just before resolving for its statement type.

## Version 0.13.1

### Fixes
Expand Down
4 changes: 3 additions & 1 deletion Lib/src/main/kotlin/com/bloomberg/selekt/SQLStatement.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.bloomberg.selekt

import com.bloomberg.selekt.commons.isNotEnglishLetter
import com.bloomberg.selekt.commons.trimStartByIndex
import javax.annotation.concurrent.ThreadSafe

internal enum class SQLStatementType(
Expand Down Expand Up @@ -44,7 +46,7 @@ internal enum class SQLStatementType(

private const val SUFFICIENT_SQL_PREFIX_LENGTH = 3

internal fun CharSequence.resolvedSqlStatementType() = trimStart(Char::isWhitespace).run {
internal fun String.resolvedSqlStatementType() = trimStartByIndex(Char::isNotEnglishLetter).run {
if (length < SUFFICIENT_SQL_PREFIX_LENGTH) {
return SQLStatementType.OTHER
}
Expand Down
21 changes: 21 additions & 0 deletions Lib/src/main/kotlin/com/bloomberg/selekt/commons/Chars.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2021 Bloomberg Finance L.P.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bloomberg.selekt.commons

internal fun Char.isEnglishLetter() = this in 'A'..'Z' || this in 'a'..'z'

internal fun Char.isNotEnglishLetter() = !isEnglishLetter()
31 changes: 31 additions & 0 deletions Lib/src/main/kotlin/com/bloomberg/selekt/commons/Strings.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2021 Bloomberg Finance L.P.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bloomberg.selekt.commons

import com.bloomberg.selekt.annotations.Generated

@Generated
internal inline fun String.trimStartByIndex(predicate: (Char) -> Boolean): String {
var i = 0
while (i < length) {
if (!predicate(this[i])) {
return substring(i)
}
++i
}
return ""
}
42 changes: 42 additions & 0 deletions Lib/src/test/kotlin/com/bloomberg/selekt/commons/CharsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2021 Bloomberg Finance L.P.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bloomberg.selekt.commons

import org.junit.jupiter.api.Test
import kotlin.test.assertTrue

internal class CharsTest {
@Test
fun isEnglishLetterLowercase() {
assertTrue('a'.isEnglishLetter())
}

@Test
fun isEnglishLetterUppercase() {
assertTrue('A'.isEnglishLetter())
}

@Test
fun isNotEnglishLetterDigit() {
assertTrue('1'.isNotEnglishLetter())
}

@Test
fun isNotEnglishLetterSymbol() {
assertTrue('{'.isNotEnglishLetter())
}
}
56 changes: 56 additions & 0 deletions Lib/src/test/kotlin/com/bloomberg/selekt/commons/StringsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2021 Bloomberg Finance L.P.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bloomberg.selekt.commons

import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
import kotlin.test.assertSame

internal class StringsTest {
@Test
fun trimStartByIndexEmptyBlankSpace() {
"".let {
assertSame(it, it.trimStartByIndex(Char::isWhitespace))
}
}

@Test
fun trimStartByIndexNoBlankSpace() {
"SELECT * FROM Foo".let {
assertSame(it, it.trimStartByIndex(Char::isWhitespace))
}
}

@Test
fun trimStartByIndexWithBlankSpace() {
val sql = " SELECT * FROM Foo"
assertEquals("SELECT * FROM Foo", sql.trimStartByIndex(Char::isWhitespace))
}

@Test
fun trimStartByIndexWithBlankSpaceOnlyAfter() {
"SELECT * FROM Foo ".let {
assertEquals(it, it.trimStartByIndex(Char::isWhitespace))
}
}

@Test
fun trimStartByIndexWithBlankSpaceBeforeAndAfter() {
val sql = " SELECT * FROM Foo "
assertEquals("SELECT * FROM Foo ", sql.trimStartByIndex(Char::isWhitespace))
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
selekt.versionName=0.13.1
selekt.versionName=0.13.2

openssl.version=1.1.1
openssl.version.suffix=d
Expand Down

0 comments on commit 39d8d7d

Please sign in to comment.