MCPcopy Index your code
hub / github.com/formatjs/formatjs / next

Method next

packages/intl-segmenter/segmenter.ts:412–454  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

410 }
411
412 next():
413 | {
414 done: boolean
415 value: {
416 segment: string
417 index: number
418 input: string
419 isWordLike?: boolean
420 }
421 }
422 | {
423 done: boolean
424 value: undefined
425 } {
426 //using only the relevant bit of the string
427 let checkString = this.input.substring(this.lastSegmentIndex)
428
429 //loop from the start of the checkString, until exactly length (breaksAt returns break at pos=== lenght)
430 for (let position = 1; position <= checkString.length; position++) {
431 const {breaks, matchingRule} = this.segmenter.breaksAt(
432 position,
433 checkString
434 )
435 if (breaks) {
436 const segment = checkString.substring(0, position)
437 const index = this.lastSegmentIndex
438 this.lastSegmentIndex += position
439
440 return {
441 done: false,
442 value: createSegmentDataObject(
443 this.segmenter,
444 segment,
445 index,
446 this.input,
447 matchingRule
448 ),
449 }
450 }
451 }
452 //no segment was found by the loop, therefore the segmentation is done
453 return {done: true, value: undefined}
454 }
455
456 containing(positionInput: number):
457 | {

Callers 3

stringListFromIterableFunction · 0.80
collectSegmentsFunction · 0.80
compareCodePointsFunction · 0.80

Calls 2

createSegmentDataObjectFunction · 0.85
breaksAtMethod · 0.80

Tested by

no test coverage detected