File tree Expand file tree Collapse file tree 1 file changed +14
-8
lines changed
src/commonMain/kotlin/io/github/optimumcode/json/pointer Expand file tree Collapse file tree 1 file changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -72,17 +72,23 @@ public operator fun JsonPointer.plus(otherPointer: JsonPointer): JsonPointer {
72
72
* @throws IllegalArgumentException when [other] is an empty pointer
73
73
*/
74
74
public fun JsonPointer.relative (other : JsonPointer ): JsonPointer {
75
- if (this is EmptyPointer ) {
75
+ if (this ! is SegmentPointer ) {
76
76
return other
77
77
}
78
- require(other !is EmptyPointer ) { " empty pointer is not relative to any" }
79
- val currentValue = this .toString()
80
- val otherValue = other.toString()
81
- val relative = otherValue.substringAfter(currentValue)
82
- return if (relative == otherValue) {
83
- other
78
+ require(other is SegmentPointer ) { " empty pointer is not relative to any" }
79
+ var currentValue: JsonPointer = this
80
+ var otherValue: JsonPointer = other
81
+ while (currentValue is SegmentPointer && otherValue is SegmentPointer ) {
82
+ if (currentValue.propertyName != otherValue.propertyName) {
83
+ return other
84
+ }
85
+ currentValue = currentValue.next
86
+ otherValue = otherValue.next
87
+ }
88
+ return if (currentValue is EmptyPointer ) {
89
+ otherValue
84
90
} else {
85
- JsonPointer (relative)
91
+ other
86
92
}
87
93
}
88
94
You can’t perform that action at this time.
0 commit comments