/* /********************************************************** /* Public API /********************************************************** */ /// <summary> /// Method that will quote text contents using JSON standard quoting, /// and return results as a character array /// </summary> public char[] quoteAsString(string input) { com.fasterxml.jackson.core.util.TextBuffer textBuffer = _text; if (textBuffer == null) { // no allocator; can add if we must, shouldn't need to _text = textBuffer = new com.fasterxml.jackson.core.util.TextBuffer(null); } char[] outputBuffer = textBuffer.emptyAndGetCurrentSegment(); int[] escCodes = com.fasterxml.jackson.core.io.CharTypes.get7BitOutputEscapes(); int escCodeCount = escCodes.Length; int inPtr = 0; int inputLen = input.Length; int outPtr = 0; while (inPtr < inputLen) { while (true) { char c = input[inPtr]; if (c < escCodeCount && escCodes[c] != 0) { goto tight_loop_break; } if (outPtr >= outputBuffer.Length) { outputBuffer = textBuffer.finishCurrentSegment(); outPtr = 0; } outputBuffer[outPtr++] = c; if (++inPtr >= inputLen) { goto outer_break; } tight_loop_continue: ; } tight_loop_break: ; // something to escape; 2 or 6-char variant? char d = input[inPtr++]; int escCode = escCodes[d]; int length = (escCode < 0) ? _appendNumeric(d, _qbuf) : _appendNamed(escCode, _qbuf ); if ((outPtr + length) > outputBuffer.Length) { int first = outputBuffer.Length - outPtr; if (first > 0) { System.Array.Copy(_qbuf, 0, outputBuffer, outPtr, first); } outputBuffer = textBuffer.finishCurrentSegment(); int second = length - first; System.Array.Copy(_qbuf, first, outputBuffer, 0, second); outPtr = second; } else { System.Array.Copy(_qbuf, 0, outputBuffer, outPtr, length); outPtr += length; } outer_continue: ; } outer_break: ; textBuffer.setCurrentLength(outPtr); return textBuffer.contentsAsArray(); }
public SegmentedStringWriter(com.fasterxml.jackson.core.util.BufferRecycler br) : base() { _buffer = new com.fasterxml.jackson.core.util.TextBuffer(br); }