Added length function in NameConditions

This commit is contained in:
2022-09-08 04:39:00 +08:00
parent e09d3282f0
commit 11e1beca3a
2 changed files with 44 additions and 0 deletions

View File

@@ -88,6 +88,24 @@ fun matches(regex: Regex)
> 正则字符匹配。 > 正则字符匹配。
### length *- method*
```kotlin
fun length(num: Int)
```
```kotlin
fun length(numRange: IntRange)
```
**变更记录**
`v1.0.93` `新增`
**功能描述**
> 字符长度与范围匹配。
### thisSynthetic0 *- method* ### thisSynthetic0 *- method*
```kotlin ```kotlin

View File

@@ -55,6 +55,12 @@ class NameConditions @PublishedApi internal constructor() {
/** 正则字符匹配条件 */ /** 正则字符匹配条件 */
private var cdsMatches: Regex? = null private var cdsMatches: Regex? = null
/** 字符长度匹配条件 */
private var cdsLength = -1
/** 字符长度范围匹配条件 */
private var cdsLengthRange = IntRange.EMPTY
/** 标识为匿名类的主类调用对象条件 */ /** 标识为匿名类的主类调用对象条件 */
private var isThisSynthetic0 = false private var isThisSynthetic0 = false
@@ -143,6 +149,22 @@ class NameConditions @PublishedApi internal constructor() {
cdsMatches = regex cdsMatches = regex
} }
/**
* 字符长度匹配
* @param num 预期的长度
*/
fun length(num: Int) {
cdsLength = num
}
/**
* 字符长度范围匹配
* @param numRange 预期的长度范围
*/
fun length(numRange: IntRange) {
cdsLengthRange = numRange
}
/** /**
* 标识为匿名类的主类调用对象 * 标识为匿名类的主类调用对象
* *
@@ -247,6 +269,8 @@ class NameConditions @PublishedApi internal constructor() {
if (cdsEndsWith != null) cdsEndsWith?.apply { conditions = conditions && it.endsWith(first, second) } if (cdsEndsWith != null) cdsEndsWith?.apply { conditions = conditions && it.endsWith(first, second) }
if (cdsContains != null) cdsContains?.apply { conditions = conditions && it.contains(first, second) } if (cdsContains != null) cdsContains?.apply { conditions = conditions && it.contains(first, second) }
if (cdsMatches != null) cdsMatches?.apply { conditions = conditions && it.matches(regex = this) } if (cdsMatches != null) cdsMatches?.apply { conditions = conditions && it.matches(regex = this) }
if (cdsLength >= 0) conditions = conditions && it.length == cdsLength
if (cdsLengthRange != IntRange.EMPTY) conditions = conditions && it.length in cdsLengthRange
} }
return conditions return conditions
} }
@@ -265,6 +289,8 @@ class NameConditions @PublishedApi internal constructor() {
if (cdsEndsWith != null) cdsEndsWith?.apply { conditions += "<EndsWith:[suffix: $first, isIgnoreCase: $second]> " } if (cdsEndsWith != null) cdsEndsWith?.apply { conditions += "<EndsWith:[suffix: $first, isIgnoreCase: $second]> " }
if (cdsContains != null) cdsContains?.apply { conditions += "<Contains:[other: $first, isIgnoreCase: $second]> " } if (cdsContains != null) cdsContains?.apply { conditions += "<Contains:[other: $first, isIgnoreCase: $second]> " }
if (cdsMatches != null) cdsMatches?.apply { conditions += "<Matches:[regex: $this]> " } if (cdsMatches != null) cdsMatches?.apply { conditions += "<Matches:[regex: $this]> " }
if (cdsLength >= 0) conditions += "<Length:[num: $cdsLength]> "
if (cdsLengthRange != IntRange.EMPTY) conditions += "<LengthRange:[numRange: $cdsLengthRange]> "
return "[${conditions.trim()}]" return "[${conditions.trim()}]"
} }
} }