code: private boolean shouldEscape(StringBuilder content, int charPosition)
      {
          int counter = 0;
          int pos = charPosition - 1;
          while (pos > -1 && content.charAt(pos) == ESCAPE_CHAR) {
              counter++;
              pos--;
          }
          return counter % 2 != 0;
      }
docs: Count the number of escape chars before a given character and if that number is odd then that character should be
  escaped.
  
  @param content the content in which to check for escapes
  @param charPosition the position of the char for which to decide if it should be escaped or not
  @return true if the character should be escaped