MCPcopy
hub / github.com/formatjs/formatjs / bumpTo

Method bumpTo

packages/icu-messageformat-parser/parser.ts:1217–1241  ·  view source on GitHub ↗

* Bump the parser to the target offset. * If target offset is beyond the end of the input, bump the parser to the end of the input.

(targetOffset: number)

Source from the content-addressed store, hash-verified

1215 * If target offset is beyond the end of the input, bump the parser to the end of the input.
1216 */
1217 private bumpTo(targetOffset: number) {
1218 if (this.offset() > targetOffset) {
1219 throw Error(
1220 `targetOffset ${targetOffset} must be greater than or equal to the current offset ${this.offset()}`
1221 )
1222 }
1223
1224 targetOffset = Math.min(targetOffset, this.message.length)
1225 while (true) {
1226 const offset = this.offset()
1227 if (offset === targetOffset) {
1228 break
1229 }
1230 if (offset > targetOffset) {
1231 throw Error(
1232 `targetOffset ${targetOffset} is at invalid UTF-16 code unit boundary`
1233 )
1234 }
1235
1236 this.bump()
1237 if (this.isEOF()) {
1238 break
1239 }
1240 }
1241 }
1242
1243 /** advance the parser through all whitespace to the next non-whitespace code unit. */
1244 private bumpSpace() {

Callers 2

bumpUntilMethod · 0.95

Calls 3

offsetMethod · 0.95
bumpMethod · 0.95
isEOFMethod · 0.95

Tested by

no test coverage detected