@@ -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,47 @@ 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
+ String firstPart = getReservedBodyPart ();
369
+ result .append (firstPart );
369
370
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
- }
371
+ spaceCount = skipWhitespaces ();
372
+ String nextPart = getReservedBodyPart ();
373
+ if (nextPart .length () == 0 ) {
374
+ input .backup (spaceCount );
375
+ break ;
393
376
}
377
+ result .append (nextPart );
378
+ }
379
+ if (result .length () == 0 ) {
380
+ input .backup (spaceCount );
381
+ }
382
+ return result .toString ();
383
+ }
384
+
385
+ // abnf: reserved-body-part = reserved-char / escaped-char / quoted-literal
386
+ private String getReservedBodyPart () throws MFParseException {
387
+ StringBuilder result = new StringBuilder ();
388
+ int cp = input .readCodePoint ();
389
+ if (StringUtils .isReservedChar (cp )) {
390
+ result .appendCodePoint (cp );
391
+ } else if (cp == '\\' ) {
392
+ cp = input .readCodePoint ();
393
+ checkCondition (
394
+ cp == '{' || cp == '|' || cp == '}' ,
395
+ "Invalid escape sequence. Only \\ {, \\ | and \\ } are valid here." );
396
+ result .append (cp );
397
+ } else if (cp == '|' ) {
398
+ input .backup (1 );
399
+ MFDataModel .Literal quoted = getQuotedLiteral ();
400
+ result .append (quoted .value );
401
+ } else {
402
+ input .backup (1 );
394
403
}
404
+ return result .toString ();
395
405
}
396
406
397
407
// abnf: identifier = [namespace ":"] name
@@ -408,7 +418,7 @@ private String getIdentifier() throws MFParseException {
408
418
checkCondition (name != null , "Expected name after namespace '" + namespace + "'" );
409
419
return namespace + ":" + name ;
410
420
} else {
411
- input .backup ( 1 );
421
+ input .backupOneCodePoint ( );
412
422
}
413
423
return namespace ;
414
424
}
@@ -479,7 +489,7 @@ private MFDataModel.Literal getLiteral() throws MFParseException {
479
489
MFDataModel .Literal ql = getQuotedLiteral ();
480
490
return ql ;
481
491
default : // unquoted
482
- input .backup ( 1 );
492
+ input .backupOneCodePoint ( );
483
493
MFDataModel .Literal unql = getUnQuotedLiteral ();
484
494
return unql ;
485
495
}
@@ -561,7 +571,7 @@ private int skipWhitespaces() {
561
571
return skipCount ;
562
572
}
563
573
if (!StringUtils .isWhitespace (cp )) {
564
- input .backup ( 1 );
574
+ input .backupOneCodePoint ( );
565
575
return skipCount ;
566
576
}
567
577
skipCount ++;
0 commit comments