@@ -351,45 +351,41 @@ int indexOfLastLineEnding(String yaml, int offset) {
351351 String yaml,
352352 int start,
353353) {
354- var startOffset = max (0 , start - 1 );
355-
356- scanner:
357- while (true ) {
358- switch (yaml[startOffset]) {
359- // This is either indent or separation space
360- case ' ' || '\t ' :
361- {
362- startOffset = yaml.lastIndexOf (_nonSpaceMatch, startOffset);
363- if (startOffset == - 1 ) break scanner;
364- }
365-
366- case '\r ' || '\n ' :
367- return (compactCharOffset: - 1 , lineEndingIndex: startOffset);
368-
369- /// Block sequences and explicit keys/values can be used to declare block
370- /// maps in a compact-inline notation.
371- ///
372- /// - a: b
373- /// c: d
374- ///
375- /// OR as an explicit key with its explicit value
376- ///
377- /// ? a: b
378- /// c: d
379- /// : e: f
380- /// g: h
381- ///
382- /// See "Example 8.19 Compact Block Mappings" at
383- /// https://yaml.org/spec/1.2.2/#822-block-mappings
384- case '-' || '?' || ':' :
385- return (compactCharOffset: startOffset, lineEndingIndex: - 1 );
354+ /// Look back past the indent/separation space.
355+ final startOffset = max (
356+ 0 ,
357+ yaml.lastIndexOf (_nonSpaceMatch, max (0 , start - 1 )),
358+ );
386359
387- default :
388- break scanner;
389- }
390- }
360+ return switch (yaml[startOffset]) {
361+ '\r ' || '\n ' => (compactCharOffset: - 1 , lineEndingIndex: startOffset),
391362
392- return (compactCharOffset: - 1 , lineEndingIndex: - 1 );
363+ /// Block sequences and explicit keys/values can be used to declare block
364+ /// maps/sequences in a compact-inline notation.
365+ ///
366+ /// - a: b
367+ /// c: d
368+ ///
369+ /// - - a
370+ /// - b
371+ ///
372+ /// OR as an explicit key with its explicit value
373+ ///
374+ /// ? a: b
375+ /// c: d
376+ /// : e: f
377+ /// g: h
378+ ///
379+ /// ? - sequence
380+ /// - as key
381+ /// : - sequence
382+ /// - as value
383+ ///
384+ /// See "Example 8.19 Compact Block Mappings" at
385+ /// https://yaml.org/spec/1.2.2/#822-block-mappings
386+ '-' || '?' || ':' => (compactCharOffset: startOffset, lineEndingIndex: - 1 ),
387+ _ => (compactCharOffset: - 1 , lineEndingIndex: - 1 )
388+ };
393389}
394390
395391typedef NextBlockNodeInfo = ({int nearestLineEnding, int nextNodeColStart});
0 commit comments