Added length { ... } function in NameConditions

This commit is contained in:
2022-09-12 23:06:27 +08:00
parent 41a42cc590
commit 113719b0d2
2 changed files with 19 additions and 1 deletions

View File

@@ -98,13 +98,17 @@ fun length(num: Int)
fun length(numRange: IntRange) fun length(numRange: IntRange)
``` ```
```kotlin
fun length(conditions: IntConditions)
```
**变更记录** **变更记录**
`v1.0.93` `新增` `v1.0.93` `新增`
**功能描述** **功能描述**
> 字符长度与范围匹配。 > 字符长度与范围及条件匹配。
### thisSynthetic0 *- method* ### thisSynthetic0 *- method*

View File

@@ -29,6 +29,7 @@
package com.highcapable.yukihookapi.hook.core.finder.type package com.highcapable.yukihookapi.hook.core.finder.type
import com.highcapable.yukihookapi.hook.utils.IntConditions
import java.lang.reflect.Field import java.lang.reflect.Field
import java.lang.reflect.Member import java.lang.reflect.Member
import java.lang.reflect.Method import java.lang.reflect.Method
@@ -61,6 +62,9 @@ class NameConditions @PublishedApi internal constructor() {
/** 字符长度范围匹配条件 */ /** 字符长度范围匹配条件 */
private var cdsLengthRange = IntRange.EMPTY private var cdsLengthRange = IntRange.EMPTY
/** 字符长度条件匹配条件 */
private var cdsLengthConditions: IntConditions? = null
/** 标识为匿名类的主类调用对象条件 */ /** 标识为匿名类的主类调用对象条件 */
private var isThisSynthetic0 = false private var isThisSynthetic0 = false
@@ -165,6 +169,14 @@ class NameConditions @PublishedApi internal constructor() {
cdsLengthRange = numRange cdsLengthRange = numRange
} }
/**
* 字符长度条件匹配
* @param conditions 条件方法体
*/
fun length(conditions: IntConditions) {
cdsLengthConditions = conditions
}
/** /**
* 标识为匿名类的主类调用对象 * 标识为匿名类的主类调用对象
* *
@@ -271,6 +283,7 @@ class NameConditions @PublishedApi internal constructor() {
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 (cdsLength >= 0) conditions = conditions && it.length == cdsLength
if (cdsLengthRange.isEmpty().not()) conditions = conditions && it.length in cdsLengthRange if (cdsLengthRange.isEmpty().not()) conditions = conditions && it.length in cdsLengthRange
if (cdsLengthConditions != null) conditions = conditions && cdsLengthConditions?.invoke(it.length) == true
} }
return conditions return conditions
} }
@@ -291,6 +304,7 @@ class NameConditions @PublishedApi internal constructor() {
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 (cdsLength >= 0) conditions += "<Length:[num: $cdsLength]> "
if (cdsLengthRange.isEmpty().not()) conditions += "<LengthRange:[numRange: $cdsLengthRange]> " if (cdsLengthRange.isEmpty().not()) conditions += "<LengthRange:[numRange: $cdsLengthRange]> "
if (cdsLengthConditions != null) conditions += "<LengthConditions:[conditions: existed]> "
return "[${conditions.trim()}]" return "[${conditions.trim()}]"
} }
} }