/// <exception cref="System.IO.IOException"/> /// <exception cref="com.fasterxml.jackson.core.JsonGenerationException"/> private void _writeStringCustom(char[] text, int offset, int len) { len += offset; // -> len marks the end from now on int[] escCodes = _outputEscapes; int maxNonEscaped = (_maximumNonEscapedChar < 1) ? unchecked((int)(0xFFFF)) : _maximumNonEscapedChar; int escLimit = System.Math.min(escCodes.Length, maxNonEscaped + 1); com.fasterxml.jackson.core.io.CharacterEscapes customEscapes = _characterEscapes; int escCode = 0; while (offset < len) { int start = offset; char c; while (true) { c = text[offset]; if (c < escLimit) { escCode = escCodes[c]; if (escCode != 0) { break; } } else { if (c > maxNonEscaped) { escCode = com.fasterxml.jackson.core.io.CharacterEscapes.ESCAPE_STANDARD; break; } else { if ((_currentEscape = customEscapes.getEscapeSequence(c)) != null) { escCode = com.fasterxml.jackson.core.io.CharacterEscapes.ESCAPE_CUSTOM; break; } } } if (++offset >= len) { break; } } // Short span? Better just copy it to buffer first: int newAmount = offset - start; if (newAmount < SHORT_WRITE) { // Note: let's reserve room for escaped char (up to 6 chars) if ((_outputTail + newAmount) > _outputEnd) { _flushBuffer(); } if (newAmount > 0) { System.Array.Copy(text, start, _outputBuffer, _outputTail, newAmount); _outputTail += newAmount; } } else { // Nope: better just write through _flushBuffer(); _writer.write(text, start, newAmount); } // Was this the end? if (offset >= len) { // yup break; } // Nope, need to escape the char. ++offset; _appendCharacterEscape(c, escCode); } }
public override com.fasterxml.jackson.core.JsonGenerator setRootValueSeparator(com.fasterxml.jackson.core.SerializableString sep) { _rootValueSeparator = sep; return this; }
/// <exception cref="System.IO.IOException"/> /// <exception cref="com.fasterxml.jackson.core.JsonGenerationException"/> private void _writeSegmentCustom(int end) { int[] escCodes = _outputEscapes; int maxNonEscaped = (_maximumNonEscapedChar < 1) ? unchecked((int)(0xFFFF)) : _maximumNonEscapedChar; int escLimit = System.Math.min(escCodes.Length, maxNonEscaped + 1); com.fasterxml.jackson.core.io.CharacterEscapes customEscapes = _characterEscapes; int ptr = 0; int escCode = 0; int start = ptr; while (ptr < end) { // Fast loop for chars not needing escaping char c; while (true) { c = _outputBuffer[ptr]; if (c < escLimit) { escCode = escCodes[c]; if (escCode != 0) { break; } } else { if (c > maxNonEscaped) { escCode = com.fasterxml.jackson.core.io.CharacterEscapes.ESCAPE_STANDARD; break; } else { if ((_currentEscape = customEscapes.getEscapeSequence(c)) != null) { escCode = com.fasterxml.jackson.core.io.CharacterEscapes.ESCAPE_CUSTOM; break; } } } if (++ptr >= end) { break; } } int flushLen = (ptr - start); if (flushLen > 0) { _writer.write(_outputBuffer, start, flushLen); if (ptr >= end) { goto output_loop_break; } } ++ptr; start = _prependOrWriteCharacterEscape(_outputBuffer, ptr, end, c, escCode); output_loop_continue: ; } output_loop_break: ; }
/* /********************************************************** /* Internal methods, low-level writing, text segment /* with custom escaping (possibly coupling with ASCII limits) /********************************************************** */ /* Same as "_writeString2()", except needs additional escaping * for subset of characters */ /// <exception cref="System.IO.IOException"/> /// <exception cref="com.fasterxml.jackson.core.JsonGenerationException"/> private void _writeStringCustom(int len) { // And then we'll need to verify need for escaping etc: int end = _outputTail + len; int[] escCodes = _outputEscapes; int maxNonEscaped = (_maximumNonEscapedChar < 1) ? unchecked((int)(0xFFFF)) : _maximumNonEscapedChar; int escLimit = System.Math.min(escCodes.Length, maxNonEscaped + 1); int escCode = 0; com.fasterxml.jackson.core.io.CharacterEscapes customEscapes = _characterEscapes; while (_outputTail < end) { char c; // Fast loop for chars not needing escaping while (true) { c = _outputBuffer[_outputTail]; if (c < escLimit) { escCode = escCodes[c]; if (escCode != 0) { goto escape_loop_break; } } else { if (c > maxNonEscaped) { escCode = com.fasterxml.jackson.core.io.CharacterEscapes.ESCAPE_STANDARD; goto escape_loop_break; } else { if ((_currentEscape = customEscapes.getEscapeSequence(c)) != null) { escCode = com.fasterxml.jackson.core.io.CharacterEscapes.ESCAPE_CUSTOM; goto escape_loop_break; } } } if (++_outputTail >= end) { goto output_loop_break; } escape_loop_continue: ; } escape_loop_break: ; int flushLen = (_outputTail - _outputHead); if (flushLen > 0) { _writer.write(_outputBuffer, _outputHead, flushLen); } ++_outputTail; _prependOrWriteCharacterEscape(c, escCode); output_loop_continue: ; } output_loop_break: ; }
/// <summary> /// Method called to try to either prepend character escape at front of /// given buffer; or if not possible, to write it out directly. /// </summary> /// <returns> /// Pointer to start of prepended entity (if prepended); or 'ptr' /// if not. /// </returns> /// <exception cref="System.IO.IOException"/> /// <exception cref="com.fasterxml.jackson.core.JsonGenerationException"/> private int _prependOrWriteCharacterEscape(char[] buffer, int ptr, int end, char ch, int escCode) { if (escCode >= 0) { // \\N (2 char) if (ptr > 1 && ptr < end) { // fits, just prepend ptr -= 2; buffer[ptr] = '\\'; buffer[ptr + 1] = (char)escCode; } else { // won't fit, write char[] ent = _entityBuffer; if (ent == null) { ent = _allocateEntityBuffer(); } ent[1] = (char)escCode; _writer.write(ent, 0, 2); } return ptr; } if (escCode != com.fasterxml.jackson.core.io.CharacterEscapes.ESCAPE_CUSTOM) { // std, \\uXXXX if (ptr > 5 && ptr < end) { // fits, prepend to buffer ptr -= 6; buffer[ptr++] = '\\'; buffer[ptr++] = 'u'; // We know it's a control char, so only the last 2 chars are non-0 if (ch > unchecked((int)(0xFF))) { // beyond 8 bytes int hi = (ch >> 8) & unchecked((int)(0xFF)); buffer[ptr++] = HEX_CHARS[hi >> 4]; buffer[ptr++] = HEX_CHARS[hi & unchecked((int)(0xF))]; ch &= (char)unchecked((int)(0xFF)); } else { buffer[ptr++] = '0'; buffer[ptr++] = '0'; } buffer[ptr++] = HEX_CHARS[ch >> 4]; buffer[ptr] = HEX_CHARS[ch & unchecked((int)(0xF))]; ptr -= 5; } else { // won't fit, flush and write char[] ent = _entityBuffer; if (ent == null) { ent = _allocateEntityBuffer(); } _outputHead = _outputTail; if (ch > unchecked((int)(0xFF))) { // beyond 8 bytes int hi = (ch >> 8) & unchecked((int)(0xFF)); int lo = ch & unchecked((int)(0xFF)); ent[10] = HEX_CHARS[hi >> 4]; ent[11] = HEX_CHARS[hi & unchecked((int)(0xF))]; ent[12] = HEX_CHARS[lo >> 4]; ent[13] = HEX_CHARS[lo & unchecked((int)(0xF))]; _writer.write(ent, 8, 6); } else { // We know it's a control char, so only the last 2 chars are non-0 ent[6] = HEX_CHARS[ch >> 4]; ent[7] = HEX_CHARS[ch & unchecked((int)(0xF))]; _writer.write(ent, 2, 6); } } return ptr; } string escape; if (_currentEscape == null) { escape = _characterEscapes.getEscapeSequence(ch).getValue(); } else { escape = _currentEscape.getValue(); _currentEscape = null; } int len = escape.Length; if (ptr >= len && ptr < end) { // fits in, prepend ptr -= len; Sharpen.Runtime.getCharsForString(escape, 0, len, buffer, ptr); } else { // won't fit, write separately _writer.write(escape); } return ptr; }
/* /********************************************************** /* Internal methods, low-level writing, escapes /********************************************************** */ /// <summary> /// Method called to try to either prepend character escape at front of /// given buffer; or if not possible, to write it out directly. /// </summary> /// <remarks> /// Method called to try to either prepend character escape at front of /// given buffer; or if not possible, to write it out directly. /// Uses head and tail pointers (and updates as necessary) /// </remarks> /// <exception cref="System.IO.IOException"/> /// <exception cref="com.fasterxml.jackson.core.JsonGenerationException"/> private void _prependOrWriteCharacterEscape(char ch, int escCode) { if (escCode >= 0) { // \\N (2 char) if (_outputTail >= 2) { // fits, just prepend int ptr = _outputTail - 2; _outputHead = ptr; _outputBuffer[ptr++] = '\\'; _outputBuffer[ptr] = (char)escCode; return; } // won't fit, write char[] buf = _entityBuffer; if (buf == null) { buf = _allocateEntityBuffer(); } _outputHead = _outputTail; buf[1] = (char)escCode; _writer.write(buf, 0, 2); return; } if (escCode != com.fasterxml.jackson.core.io.CharacterEscapes.ESCAPE_CUSTOM) { // std, \\uXXXX if (_outputTail >= 6) { // fits, prepend to buffer char[] buf = _outputBuffer; int ptr = _outputTail - 6; _outputHead = ptr; buf[ptr] = '\\'; buf[++ptr] = 'u'; // We know it's a control char, so only the last 2 chars are non-0 if (ch > unchecked((int)(0xFF))) { // beyond 8 bytes int hi = (ch >> 8) & unchecked((int)(0xFF)); buf[++ptr] = HEX_CHARS[hi >> 4]; buf[++ptr] = HEX_CHARS[hi & unchecked((int)(0xF))]; ch &= (char)unchecked((int)(0xFF)); } else { buf[++ptr] = '0'; buf[++ptr] = '0'; } buf[++ptr] = HEX_CHARS[ch >> 4]; buf[++ptr] = HEX_CHARS[ch & unchecked((int)(0xF))]; return; } // won't fit, flush and write char[] buf_1 = _entityBuffer; if (buf_1 == null) { buf_1 = _allocateEntityBuffer(); } _outputHead = _outputTail; if (ch > unchecked((int)(0xFF))) { // beyond 8 bytes int hi = (ch >> 8) & unchecked((int)(0xFF)); int lo = ch & unchecked((int)(0xFF)); buf_1[10] = HEX_CHARS[hi >> 4]; buf_1[11] = HEX_CHARS[hi & unchecked((int)(0xF))]; buf_1[12] = HEX_CHARS[lo >> 4]; buf_1[13] = HEX_CHARS[lo & unchecked((int)(0xF))]; _writer.write(buf_1, 8, 6); } else { // We know it's a control char, so only the last 2 chars are non-0 buf_1[6] = HEX_CHARS[ch >> 4]; buf_1[7] = HEX_CHARS[ch & unchecked((int)(0xF))]; _writer.write(buf_1, 2, 6); } return; } string escape; if (_currentEscape == null) { escape = _characterEscapes.getEscapeSequence(ch).getValue(); } else { escape = _currentEscape.getValue(); _currentEscape = null; } int len = escape.Length; if (_outputTail >= len) { // fits in, prepend int ptr = _outputTail - len; _outputHead = ptr; Sharpen.Runtime.getCharsForString(escape, 0, len, _outputBuffer, ptr); return; } // won't fit, write separately _outputHead = _outputTail; _writer.write(escape); }
/// <summary> /// Method called to append escape sequence for given character, at the /// end of standard output buffer; or if not possible, write out directly. /// </summary> /// <exception cref="System.IO.IOException"/> /// <exception cref="com.fasterxml.jackson.core.JsonGenerationException"/> private void _appendCharacterEscape(char ch, int escCode) { if (escCode >= 0) { // \\N (2 char) if ((_outputTail + 2) > _outputEnd) { _flushBuffer(); } _outputBuffer[_outputTail++] = '\\'; _outputBuffer[_outputTail++] = (char)escCode; return; } if (escCode != com.fasterxml.jackson.core.io.CharacterEscapes.ESCAPE_CUSTOM) { // std, \\uXXXX if ((_outputTail + 2) > _outputEnd) { _flushBuffer(); } int ptr = _outputTail; char[] buf = _outputBuffer; buf[ptr++] = '\\'; buf[ptr++] = 'u'; // We know it's a control char, so only the last 2 chars are non-0 if (ch > unchecked((int)(0xFF))) { // beyond 8 bytes int hi = (ch >> 8) & unchecked((int)(0xFF)); buf[ptr++] = HEX_CHARS[hi >> 4]; buf[ptr++] = HEX_CHARS[hi & unchecked((int)(0xF))]; ch &= (char)unchecked((int)(0xFF)); } else { buf[ptr++] = '0'; buf[ptr++] = '0'; } buf[ptr++] = HEX_CHARS[ch >> 4]; buf[ptr++] = HEX_CHARS[ch & unchecked((int)(0xF))]; _outputTail = ptr; return; } string escape; if (_currentEscape == null) { escape = _characterEscapes.getEscapeSequence(ch).getValue(); } else { escape = _currentEscape.getValue(); _currentEscape = null; } int len = escape.Length; if ((_outputTail + len) > _outputEnd) { _flushBuffer(); if (len > _outputEnd) { // very very long escape; unlikely but theoretically possible _writer.write(escape); return; } } Sharpen.Runtime.getCharsForString(escape, 0, len, _outputBuffer, _outputTail); _outputTail += len; }
/// <summary> /// Method that allows overriding String used for separating root-level /// JSON values (default is single space character) /// </summary> /// <param name="sep"> /// Separator to use, if any; null means that no separator is /// automatically added /// </param> /// <since>2.1</since> public virtual com.fasterxml.jackson.core.JsonFactory setRootValueSeparator(string sep) { _rootValueSeparator = (sep == null) ? null : new com.fasterxml.jackson.core.io.SerializedString (sep); return this; }
/// <summary>Constructor used when copy()ing a factory instance.</summary> /// <since>2.2.1</since> protected internal JsonFactory(com.fasterxml.jackson.core.JsonFactory src, com.fasterxml.jackson.core.ObjectCodec codec) { _objectCodec = null; _factoryFeatures = src._factoryFeatures; _parserFeatures = src._parserFeatures; _generatorFeatures = src._generatorFeatures; _characterEscapes = src._characterEscapes; _inputDecorator = src._inputDecorator; _outputDecorator = src._outputDecorator; _rootValueSeparator = src._rootValueSeparator; }