Skip to content

Commit 90a8e2a

Browse files
committed
Remove getCharacterLastIndex
1 parent 8176950 commit 90a8e2a

3 files changed

Lines changed: 2 additions & 40 deletions

File tree

src/source.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import * as angular from '@angular/compiler';
22
import type * as babel from '@babel/types';
33

44
import type { LocationInformation, NGNode, RawNGSpan } from './types.ts';
5-
import {
6-
getCharacterIndex,
7-
getCharacterLastIndex,
8-
sourceSpanToLocationInformation,
9-
} from './utils.ts';
5+
import { getCharacterIndex, sourceSpanToLocationInformation } from './utils.ts';
106

117
export class Source {
128
text;
@@ -19,10 +15,6 @@ export class Source {
1915
return getCharacterIndex(this.text, pattern, index);
2016
}
2117

22-
getCharacterLastIndex(pattern: RegExp | string, index: number) {
23-
return getCharacterLastIndex(this.text, pattern, index);
24-
}
25-
2618
transformSpan(span: RawNGSpan): LocationInformation {
2719
return sourceSpanToLocationInformation(span);
2820
}

src/utils.test.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
import { getCharacterIndex, getCharacterLastIndex } from './utils.ts';
1+
import { getCharacterIndex } from './utils.ts';
22

33
test('getCharacterIndex', () => {
44
expect(getCharacterIndex('foobar', /o/, 0)).toBe(1);
55
expect(getCharacterIndex('foobar', /o/, 1)).toBe(1);
66
expect(getCharacterIndex('foobar', 'o', 0)).toBe(1);
77
expect(() => getCharacterIndex('foobar', '_', 0)).toThrow();
88
});
9-
10-
test('getCharacterLastIndex', () => {
11-
expect(getCharacterLastIndex('foobar', /o/, 6)).toBe(2);
12-
expect(getCharacterLastIndex('foobar', /o/, 2)).toBe(2);
13-
expect(getCharacterLastIndex('foobar', 'o', 6)).toBe(2);
14-
expect(() => getCharacterLastIndex('foobar', '_', 6)).toThrow();
15-
});

src/utils.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,6 @@ function getCharacterSearchTestFunction(pattern: RegExp | string) {
88
return (character: string) => pattern.test(character);
99
}
1010

11-
export function getCharacterLastIndex(
12-
text: string,
13-
pattern: RegExp | string,
14-
fromIndex: number,
15-
) {
16-
const test = getCharacterSearchTestFunction(pattern);
17-
18-
for (let index = fromIndex; index >= 0; index--) {
19-
const character = text[index];
20-
21-
if (test(character)) {
22-
return index;
23-
}
24-
}
25-
26-
/* c8 ignore next 4 @preserve */
27-
throw new Error(
28-
`Cannot find front char ${pattern} from index ${fromIndex} in ${JSON.stringify(
29-
text,
30-
)}`,
31-
);
32-
}
33-
3411
export function getCharacterIndex(
3512
text: string,
3613
pattern: RegExp | string,

0 commit comments

Comments
 (0)