@@ -53,12 +53,12 @@ private MFDataModel.Message parseImpl() throws MFParseException {
53
53
cp = input .readCodePoint ();
54
54
cp = input .peekChar ();
55
55
if (cp == '{' ) { // `{{`, complex body without declarations
56
- input .backup ( 1 ); // let complexBody deal with the wrapping {{ and }}
56
+ input .backupOneCodePoint ( ); // let complexBody deal with the wrapping {{ and }}
57
57
MFDataModel .Pattern pattern = getQuotedPattern ();
58
58
skipOptionalWhitespaces ();
59
59
result = new MFDataModel .PatternMessage (new ArrayList <>(), pattern );
60
60
} else { // placeholder
61
- input .backup ( 1 ); // We want the '{' present, to detect the part as placeholder.
61
+ input .backupOneCodePoint ( ); // We want the '{' present, to detect the part as placeholder.
62
62
MFDataModel .Pattern pattern = getPattern ();
63
63
result = new MFDataModel .PatternMessage (new ArrayList <>(), pattern );
64
64
}
@@ -129,7 +129,7 @@ private String getText() {
129
129
if (StringUtils .isContentChar (cp ) || StringUtils .isWhitespace (cp )) {
130
130
result .appendCodePoint (cp );
131
131
} else {
132
- input .backup ( 1 );
132
+ input .backupOneCodePoint ( );
133
133
return result .toString ();
134
134
}
135
135
}
@@ -361,37 +361,48 @@ private MFDataModel.Attribute getAttribute() throws MFParseException {
361
361
return null ;
362
362
}
363
363
364
- // abnf: reserved-body = *([s] 1*(reserved-char / reserved-escape / quoted))
365
- // abnf: reserved-escape = backslash ( backslash / "{" / "|" / "}" )
364
+ // abnf: reserved-body = reserved-body-part *([s] reserved-body-part)
366
365
private String getReservedBody () throws MFParseException {
367
366
int spaceCount = skipWhitespaces ();
368
367
StringBuilder result = new StringBuilder ();
368
+ input .dump ();
369
+ String firstPart = getReservedBodyPart ();
370
+ result .append (firstPart );
369
371
while (true ) {
370
- int cp = input .readCodePoint ();
371
- if (StringUtils .isReservedChar (cp )) {
372
- result .appendCodePoint (cp );
373
- } else if (cp == '\\' ) {
374
- cp = input .readCodePoint ();
375
- checkCondition (
376
- cp == '{' || cp == '|' || cp == '}' ,
377
- "Invalid escape sequence. Only \\ {, \\ | and \\ } are valid here." );
378
- result .append (cp );
379
- } else if (cp == '|' ) {
380
- input .backup (1 );
381
- MFDataModel .Literal quoted = getQuotedLiteral ();
382
- result .append (quoted .value );
383
- } else if (cp == EOF ) {
384
- return result .toString ();
385
- } else {
386
- if (result .length () == 0 ) {
387
- input .backup (spaceCount + 1 );
388
- return "" ;
389
- } else {
390
- input .backup (1 );
391
- return result .toString ();
392
- }
372
+ spaceCount = skipWhitespaces ();
373
+ String nextPart = getReservedBodyPart ();
374
+ if (nextPart .length () == 0 ) {
375
+ input .backup (spaceCount );
376
+ break ;
393
377
}
378
+ result .append (nextPart );
379
+ }
380
+ if (result .length () == 0 ) {
381
+ input .backup (spaceCount );
382
+ }
383
+ return result .toString ();
384
+ }
385
+
386
+ // abnf: reserved-body-part = reserved-char / escaped-char / quoted-literal
387
+ private String getReservedBodyPart () throws MFParseException {
388
+ StringBuilder result = new StringBuilder ();
389
+ int cp = input .readCodePoint ();
390
+ if (StringUtils .isReservedChar (cp )) {
391
+ result .appendCodePoint (cp );
392
+ } else if (cp == '\\' ) {
393
+ cp = input .readCodePoint ();
394
+ checkCondition (
395
+ cp == '{' || cp == '|' || cp == '}' ,
396
+ "Invalid escape sequence. Only \\ {, \\ | and \\ } are valid here." );
397
+ result .append (cp );
398
+ } else if (cp == '|' ) {
399
+ input .backup (1 );
400
+ MFDataModel .Literal quoted = getQuotedLiteral ();
401
+ result .append (quoted .value );
402
+ } else {
403
+ input .backup (1 );
394
404
}
405
+ return result .toString ();
395
406
}
396
407
397
408
// abnf: identifier = [namespace ":"] name
@@ -408,7 +419,7 @@ private String getIdentifier() throws MFParseException {
408
419
checkCondition (name != null , "Expected name after namespace '" + namespace + "'" );
409
420
return namespace + ":" + name ;
410
421
} else {
411
- input .backup ( 1 );
422
+ input .backupOneCodePoint ( );
412
423
}
413
424
return namespace ;
414
425
}
@@ -479,7 +490,7 @@ private MFDataModel.Literal getLiteral() throws MFParseException {
479
490
MFDataModel .Literal ql = getQuotedLiteral ();
480
491
return ql ;
481
492
default : // unquoted
482
- input .backup ( 1 );
493
+ input .backupOneCodePoint ( );
483
494
MFDataModel .Literal unql = getUnQuotedLiteral ();
484
495
return unql ;
485
496
}
@@ -561,7 +572,7 @@ private int skipWhitespaces() {
561
572
return skipCount ;
562
573
}
563
574
if (!StringUtils .isWhitespace (cp )) {
564
- input .backup ( 1 );
575
+ input .backupOneCodePoint ( );
565
576
return skipCount ;
566
577
}
567
578
skipCount ++;
0 commit comments