예제 #1
0
  protected void _writeFieldName(String name, boolean commaBefore)
      throws IOException, JsonGenerationException {
    // for fast+std case, need to output up to 2 chars, comma, quote
    if ((_outputTail + 1) >= _outputEnd) {
      _flushBuffer();
    }
    if (commaBefore) {
      _outputBuffer[_outputTail++] = ',';
    }

    if (IdentifierUtils.isIdStrict(name)) {
      _writeRaw(name);
      return;
    }

    // we know there's room for at least one more char
    _outputBuffer[_outputTail++] = '\'';
    // The beef:
    _writeString(name);
    // and closing quotes; need room for one more char:
    if (_outputTail >= _outputEnd) {
      _flushBuffer();
    }
    _outputBuffer[_outputTail++] = '\'';
  }
예제 #2
0
 private String randomIdentifier(int len) {
   // most characters are ID start or chars, so chances are these loops don't discard many
   // characters and are fast...
   char[] chars = new char[len];
   int pos = 0;
   while (pos < 1) {
     char ch = (char) RANDOM.nextInt();
     if (IdentifierUtils.isIdStartLenient(ch)) {
       chars[pos++] = ch;
     }
   }
   while (pos < chars.length) {
     char ch = (char) RANDOM.nextInt();
     if (IdentifierUtils.isIdCharLenient(ch)) {
       chars[pos++] = ch;
     }
   }
   return new String(chars);
 }
예제 #3
0
  @Override
  public void writeString(char[] text, int offset, int len)
      throws IOException, JsonGenerationException {
    _verifyValueWrite("write text value");

    if (IdentifierUtils.isIdStrict(text, offset, len)) {
      _writeRaw(text, offset, len);
      return;
    }

    if (_outputTail >= _outputEnd) {
      _flushBuffer();
    }
    _outputBuffer[_outputTail++] = '\'';
    _writeString(text, offset, len);
    // And finally, closing quotes
    if (_outputTail >= _outputEnd) {
      _flushBuffer();
    }
    _outputBuffer[_outputTail++] = '\'';
  }