/**
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package foam.lib.json;

import foam.lib.parse.*;

public class StringParser implements Parser {
  private char delim_;
  private char escape_;

  public StringParser() {
    escape_ = '\\';
  }

  public PStream parse(PStream ps, ParserContext x) {
    delim_ = ps.head();
    if ( delim_ != '"' && delim_ != '\'' ) {
      return null;
    }

    ps = ps.tail();
    char lastc = delim_;

    StringBuilder sb = new StringBuilder();

    while ( ps.valid() ) {
      char c = ps.head();
      if ( c == delim_ && lastc != escape_ ) {
        break;
      }

      if ( c != escape_ ) sb.append(c);

      PStream tail = ps.tail();

      if ( c == '\\' ) {
        char nextChar = ps.tail().head();
        Parser escapeSeqParser = null;

        if ( nextChar == 'u' ) {
          escapeSeqParser = new UnicodeParser();
        } else if ( nextChar == 'n' ) {
          escapeSeqParser = new ASCIIEscapeParser();
        }

        if ( escapeSeqParser != null ) {
          PStream escapePS = escapeSeqParser.parse(ps, x);

          if ( escapePS != null ) {
            sb.append(escapePS.value());
            tail = escapePS;

            c = ((Character) escapePS.value()).charValue();
          }
        }
      }

      ps = tail;
      lastc = c;
    }

    return ps.tail().setValue(sb.toString());
  }
}

@@ -220,49 +220,70 @@
 %0A  p
-rivate char delim_;
+ublic final static char ESCAPE = '%5C%5C';%0A
 %0A  pr
-iva
+otec
 te
+d
  char 
-escape
+delim
 _;%0A%0A
@@ -312,28 +312,8 @@
 ) %7B%0A
-    escape_ = '%5C%5C';%0A
   %7D%0A
@@ -363,24 +363,24 @@
 ontext x) %7B%0A
-
     delim_ =
@@ -387,24 +387,25 @@
  ps.head();%0A
+%0A
     if ( del
@@ -642,23 +642,22 @@
 astc != 
-escape_
+ESCAPE
  ) %7B%0A   
@@ -697,15 +697,14 @@
  != 
-escape_
+ESCAPE
  ) s

Make string parser escape_ into a constant ESCAPE.