| 43 | } |
| 44 | |
| 45 | export class PathIterator implements IKeyIterator<string> { |
| 46 | |
| 47 | private _value!: string; |
| 48 | private _from!: number; |
| 49 | private _to!: number; |
| 50 | |
| 51 | constructor( |
| 52 | private readonly _splitOnBackslash: boolean = true, |
| 53 | private readonly _caseSensitive: boolean = true |
| 54 | ) { } |
| 55 | |
| 56 | reset(key: string): this { |
| 57 | this._value = key.replace(/\\$|\/$/, ''); |
| 58 | this._from = 0; |
| 59 | this._to = 0; |
| 60 | return this.next(); |
| 61 | } |
| 62 | |
| 63 | hasNext(): boolean { |
| 64 | return this._to < this._value.length; |
| 65 | } |
| 66 | |
| 67 | next(): this { |
| 68 | // this._data = key.split(/[\\/]/).filter(s => !!s); |
| 69 | this._from = this._to; |
| 70 | let justSeps = true; |
| 71 | for (; this._to < this._value.length; this._to++) { |
| 72 | const ch = this._value.charCodeAt(this._to); |
| 73 | if (ch === CharCode.Slash || this._splitOnBackslash && ch === CharCode.Backslash) { |
| 74 | if (justSeps) { |
| 75 | this._from++; |
| 76 | } else { |
| 77 | break; |
| 78 | } |
| 79 | } else { |
| 80 | justSeps = false; |
| 81 | } |
| 82 | } |
| 83 | return this; |
| 84 | } |
| 85 | |
| 86 | cmp(a: string): number { |
| 87 | return this._caseSensitive |
| 88 | ? compareSubstring(a, this._value, 0, a.length, this._from, this._to) |
| 89 | : compareSubstringIgnoreCase(a, this._value, 0, a.length, this._from, this._to); |
| 90 | } |
| 91 | |
| 92 | value(): string { |
| 93 | return this._value.substring(this._from, this._to); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | class TernarySearchTreeNode<K, V> { |
| 98 | segment!: string; |
nothing calls this directly
no outgoing calls
no test coverage detected