code: static void escape(final char[] text, final int offset, final int len, final Writer writer)
                         throws IOException {
  
          if (text == null || text.length == 0) {
              return;
          }
  
          final int max = (offset + len);
  
          int readOffset = offset;
  
          for (int i = offset; i < max; i++) {
  
              final char c = text[i];
  
  
              /*
               * Shortcut: most characters will be Alphanumeric, and we won't need to do anything at
               * all for them.
               */
              if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) {
                  continue;
              }
  
  
              /*
               * At this point we know for sure we will need some kind of escape, so we
               * initialize the string builder.
               */
              if (readOffset == offset) {
                  // If we need this, it's because we have non-alphanumeric chars. And that means
                  // we should enclose in double-quotes.
                  writer.write(DOUBLE_QUOTE);
              }
  
              /*
               * Now we copy all the contents pending up to this point.
               */
              if (i - readOffset > 0) {
                  writer.write(text, readOffset, (i - readOffset));
              }
  
              readOffset = i + 1;
  
              /*
               * Check whether the character is a double-quote (in which case, we escape it)
               */
              if (c == DOUBLE_QUOTE) {
                  writer.write(TWO_DOUBLE_QUOTES);
                  continue;
              }
  
              writer.write(c);
  
          }
  
  
          /*
           * -----------------------------------------------------------------------------------------------
           * Final cleaning: append the remaining unescaped text to the string builder and return.
           * -----------------------------------------------------------------------------------------------
           */
  
          if (max - readOffset > 0) {
              writer.write(text, readOffset, (max - readOffset));
          }
  
          if (readOffset > offset) {
              // If we reached here, it's because we had non-alphanumeric chars. And that means
              // we should enclose in double-quotes.
              writer.write(DOUBLE_QUOTE);
          }
  
      }
docs: /*
  Perform an escape operation, based on char[], according to the specified level and type.