Skip to content

Commit

Permalink
Merge pull request #525 from waahhh/feature/add-string-functions-trim
Browse files Browse the repository at this point in the history
Add String functions(�trim)
  • Loading branch information
shouwn authored Nov 22, 2023
2 parents 63d4967 + 787893b commit b7a6bf5
Show file tree
Hide file tree
Showing 29 changed files with 1,512 additions and 0 deletions.
108 changes: 108 additions & 0 deletions dsl/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import com.linecorp.kotlinjdsl.dsl.jpql.delete.DeleteQueryWhereStep
import com.linecorp.kotlinjdsl.dsl.jpql.delete.impl.DeleteQueryDsl
import com.linecorp.kotlinjdsl.dsl.jpql.expression.CaseThenFirstStep
import com.linecorp.kotlinjdsl.dsl.jpql.expression.CaseValueWhenFirstStep
import com.linecorp.kotlinjdsl.dsl.jpql.expression.TrimFromStep
import com.linecorp.kotlinjdsl.dsl.jpql.expression.impl.CaseThenFirstStepDsl
import com.linecorp.kotlinjdsl.dsl.jpql.expression.impl.CaseValueWhenFirstStepDsl
import com.linecorp.kotlinjdsl.dsl.jpql.expression.impl.TrimBothDsl
import com.linecorp.kotlinjdsl.dsl.jpql.expression.impl.TrimDsl
import com.linecorp.kotlinjdsl.dsl.jpql.expression.impl.TrimLeadingDsl
import com.linecorp.kotlinjdsl.dsl.jpql.expression.impl.TrimTrailingDsl
import com.linecorp.kotlinjdsl.dsl.jpql.join.AssociationJoinOnStep
import com.linecorp.kotlinjdsl.dsl.jpql.join.JoinOnStep
import com.linecorp.kotlinjdsl.dsl.jpql.join.impl.AssociationFetchJoinDsl
Expand Down Expand Up @@ -40,6 +45,7 @@ import com.linecorp.kotlinjdsl.querymodel.jpql.sort.Sort
import java.math.BigDecimal
import java.math.BigInteger
import kotlin.internal.Exact
import kotlin.internal.LowPriorityInOverloadResolution
import kotlin.reflect.KClass
import kotlin.reflect.KFunction1
import kotlin.reflect.KProperty1
Expand Down Expand Up @@ -1084,6 +1090,108 @@ open class Jpql : JpqlDsl {
return Expressions.type(path.toPath())
}

/**
* Creates an expression that represents a string with the whitespaces all trimmed
* from the both sides of the string.
*/
@SinceJdsl("3.1.0")
fun trim(value: String): Expression<String> {
return Expressions.trim(value = Expressions.value(value))
}

/**
* Creates an expression that represents a string with the whitespaces all trimmed
* from the both sides of the string.
*/
@SinceJdsl("3.1.0")
fun trim(value: Expressionable<String>): Expression<String> {
return Expressions.trim(value = value.toExpression())
}

/**
* Creates an expression that represents a string with the specified characters all trimmed
* from the both sides of the string.
* If the character is not specified, it will be assumed to be whitespace.
*/
@LowPriorityInOverloadResolution
@SinceJdsl("3.1.0")
fun trim(character: Char? = null): TrimFromStep {
return TrimDsl(character?.let { Expressions.value(it) })
}

/**
* Creates an expression that represents a string with the specified characters all trimmed
* from the both sides of the string.
* If the character is not specified, it will be assumed to be whitespace.
*/
@SinceJdsl("3.1.0")
fun trim(character: Expressionable<Char>? = null): TrimFromStep {
return TrimDsl(character?.let { it.toExpression() })
}

/**
* Creates an expression that represents a string with the specified characters all trimmed
* from the leading side of the string.
* If the character is not specified, it will be assumed to be whitespace.
*/
@LowPriorityInOverloadResolution
@SinceJdsl("3.1.0")
fun trimLeading(character: Char? = null): TrimFromStep {
return TrimLeadingDsl(character?.let { Expressions.value(it) })
}

/**
* Creates an expression that represents a string with the specified characters all trimmed
* from the leading side of the string.
* If the character is not specified, it will be assumed to be whitespace.
*/
@SinceJdsl("3.1.0")
fun trimLeading(character: Expressionable<Char>? = null): TrimFromStep {
return TrimLeadingDsl(character?.let { it.toExpression() })
}

/**
* Creates an expression that represents a string with the specified characters all trimmed
* from the trailing side of the string.
* If the character is not specified, it will be assumed to be whitespace.
*/
@LowPriorityInOverloadResolution
@SinceJdsl("3.1.0")
fun trimTrailing(character: Char? = null): TrimFromStep {
return TrimTrailingDsl(character?.let { Expressions.value(it) })
}

/**
* Creates an expression that represents a string with the specified characters all trimmed
* from the trailing side of the string.
* If the character is not specified, it will be assumed to be whitespace.
*/
@SinceJdsl("3.1.0")
fun trimTrailing(character: Expressionable<Char>? = null): TrimFromStep {
return TrimTrailingDsl(character?.let { it.toExpression() })
}

/**
* Creates an expression that represents a string with the specified characters all trimmed
* from the both sides of the string.
* If the character is not specified, it will be assumed to be whitespace.
*/
@LowPriorityInOverloadResolution
@SinceJdsl("3.1.0")
fun trimBoth(character: Char? = null): TrimFromStep {
return TrimBothDsl(character?.let { Expressions.value(it) })
}

/**
* Creates an expression that represents a string with the specified characters all trimmed
* from the both sides of the string.
* If the character is not specified, it will be assumed to be whitespace.
*/
@SinceJdsl("3.1.0")
fun trimBoth(character: Expressionable<Char>? = null): TrimFromStep {
return TrimBothDsl(character?.let { it.toExpression() })
}

/**
* Creates an expression that represents the string in uppercase.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.linecorp.kotlinjdsl.dsl.jpql.expression

import com.linecorp.kotlinjdsl.SinceJdsl
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressionable

@SinceJdsl("3.1.0")
interface TrimFromStep {
/**
* Creates a from in a trim expression.
*/
@SinceJdsl("3.1.0")
fun from(value: String): Expressionable<String>

/**
* Creates a from in a trim expression.
*/
@SinceJdsl("3.1.0")
fun from(value: Expressionable<String>): Expressionable<String>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.linecorp.kotlinjdsl.dsl.jpql.expression.impl

import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions

internal data class TrimBothBuilder(
private val character: Expression<Char>? = null,
) {
private lateinit var value: Expression<String>

fun from(value: Expression<String>): TrimBothBuilder {
this.value = value

return this
}

fun build(): Expression<String> {
return Expressions.trimBoth(
character = character,
value = value,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.linecorp.kotlinjdsl.dsl.jpql.expression.impl

import com.linecorp.kotlinjdsl.dsl.jpql.expression.TrimFromStep
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressionable
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions

@PublishedApi
internal data class TrimBothDsl(
private val builder: TrimBothBuilder,
) : TrimFromStep, Expressionable<String> {
constructor(
character: Expression<Char>? = null,
) : this(TrimBothBuilder(character))

override fun from(value: String): Expressionable<String> {
builder.from(Expressions.value(value))

return this
}

override fun from(value: Expressionable<String>): Expressionable<String> {
builder.from(value.toExpression())

return this
}

override fun toExpression(): Expression<String> {
return builder.build()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.linecorp.kotlinjdsl.dsl.jpql.expression.impl

import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions

internal data class TrimBuilder(
private val character: Expression<Char>? = null,
) {
private lateinit var value: Expression<String>

fun from(value: Expression<String>): TrimBuilder {
this.value = value

return this
}

fun build(): Expression<String> {
return Expressions.trim(
character = character,
value = value,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.linecorp.kotlinjdsl.dsl.jpql.expression.impl

import com.linecorp.kotlinjdsl.dsl.jpql.expression.TrimFromStep
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressionable
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions

@PublishedApi
internal data class TrimDsl(
private val builder: TrimBuilder,
) : TrimFromStep, Expressionable<String> {
constructor(
character: Expression<Char>? = null,
) : this(TrimBuilder(character))

override fun from(value: String): Expressionable<String> {
builder.from(Expressions.value(value))

return this
}

override fun from(value: Expressionable<String>): Expressionable<String> {
builder.from(value.toExpression())

return this
}

override fun toExpression(): Expression<String> {
return builder.build()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.linecorp.kotlinjdsl.dsl.jpql.expression.impl

import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions

internal data class TrimLeadingBuilder(
private val character: Expression<Char>? = null,
) {
private lateinit var value: Expression<String>

fun from(value: Expression<String>): TrimLeadingBuilder {
this.value = value

return this
}

fun build(): Expression<String> {
return Expressions.trimLeading(
character = character,
value = value,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.linecorp.kotlinjdsl.dsl.jpql.expression.impl

import com.linecorp.kotlinjdsl.dsl.jpql.expression.TrimFromStep
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressionable
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions

@PublishedApi
internal data class TrimLeadingDsl(
private val builder: TrimLeadingBuilder,
) : TrimFromStep, Expressionable<String> {
constructor(
character: Expression<Char>? = null,
) : this(TrimLeadingBuilder(character))

override fun from(value: String): Expressionable<String> {
builder.from(Expressions.value(value))

return this
}

override fun from(value: Expressionable<String>): Expressionable<String> {
builder.from(value.toExpression())

return this
}

override fun toExpression(): Expression<String> {
return builder.build()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.linecorp.kotlinjdsl.dsl.jpql.expression.impl

import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions

internal data class TrimTrailingBuilder(
private val character: Expression<Char>? = null,
) {
private lateinit var value: Expression<String>

fun from(value: Expression<String>): TrimTrailingBuilder {
this.value = value

return this
}

fun build(): Expression<String> {
return Expressions.trimTrailing(
character = character,
value = value,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.linecorp.kotlinjdsl.dsl.jpql.expression.impl

import com.linecorp.kotlinjdsl.dsl.jpql.expression.TrimFromStep
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expression
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressionable
import com.linecorp.kotlinjdsl.querymodel.jpql.expression.Expressions

@PublishedApi
internal data class TrimTrailingDsl(
private val builder: TrimTrailingBuilder,
) : TrimFromStep, Expressionable<String> {
constructor(
character: Expression<Char>? = null,
) : this(TrimTrailingBuilder(character))

override fun from(value: String): Expressionable<String> {
builder.from(Expressions.value(value))

return this
}

override fun from(value: Expressionable<String>): Expressionable<String> {
builder.from(value.toExpression())

return this
}

override fun toExpression(): Expression<String> {
return builder.build()
}
}
Loading

0 comments on commit b7a6bf5

Please sign in to comment.