code: private String replaceScriptEscapeAndNewLines(String str) {
          StringBuilder result = new StringBuilder(str.length());
          char c = '\0';
          char prevC = '\0';
          boolean atEscape = false;
          for (int i = 0; i < str.length(); i++) {
              prevC = c;
              c = str.charAt(i);
              // set atEscape flag
              if (c == '\\') {
                  // deal with 2nd '\\' char
                  if (atEscape) {
                      result.append(c);
                      atEscape = false;
                      // set c to '\0' so that prevC doesn't match '\\'
                      // the next time round
                      c = '\0';
                  } else {
                      atEscape = true;
                  }
              } else if (atEscape) {
                  if (c == 'n') {
                      result.append("\n");
                  } else {
                      result.append(c);
                  }
              } else {
                  result.append(c);
              }
              // unset atEscape flag if required
              if (prevC == '\\') {
                  if (atEscape) {
                      atEscape = false;
                  }
              }
          }
          return result.toString();
      }
docs: /*
  Converts \\ to \ and \n in Script  to '\n'