Skip to content

Commit

Permalink
Minor fix to encoding of long UTF-8 text values
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 3, 2020
1 parent f90ccdf commit 69c844c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Expand Up @@ -1928,12 +1928,12 @@ private final void _finishString2(char[] outBuf, int outPtr, int c)
case 4: // 4-byte UTF
c = _decodeUtf8_4(c);
// Let's add first part right away:
outBuf[outPtr++] = (char) (0xD800 | (c >> 10));
if (outPtr >= outBuf.length) {
outBuf = _textBuffer.finishCurrentSegment();
outPtr = 0;
outEnd = outBuf.length;
}
outBuf[outPtr++] = (char) (0xD800 | (c >> 10));
c = 0xDC00 | (c & 0x3FF);
// And let the other char output down below
break;
Expand Down
Expand Up @@ -157,18 +157,20 @@ public void _testUtf8StringTrivial(int mode) throws Exception

public void testUtf8StringValue() throws Exception
{
_testUtf8StringValue(MODE_INPUT_STREAM);
_testUtf8StringValue(MODE_DATA_INPUT);
_testUtf8StringValue(MODE_INPUT_STREAM_THROTTLED);
_testUtf8StringValue(MODE_INPUT_STREAM, 2900);
_testUtf8StringValue(MODE_DATA_INPUT, 2900);
_testUtf8StringValue(MODE_INPUT_STREAM_THROTTLED, 2900);

_testUtf8StringValue(MODE_INPUT_STREAM, 5300);
_testUtf8StringValue(MODE_DATA_INPUT, 5300);
_testUtf8StringValue(MODE_INPUT_STREAM_THROTTLED, 5300);
}

public void _testUtf8StringValue(int mode) throws Exception
public void _testUtf8StringValue(int mode, int len) throws Exception
{
Random r = new Random(13);
//int LEN = 72000;
int LEN = 720;
StringBuilder sb = new StringBuilder(LEN + 20);
while (sb.length() < LEN) {
StringBuilder sb = new StringBuilder(len + 20);
while (sb.length() < len) {
int c;
if (r.nextBoolean()) { // ascii
c = 32 + (r.nextInt() & 0x3F);
Expand All @@ -188,7 +190,7 @@ public void _testUtf8StringValue(int mode) throws Exception
sb.append((char) c);
}

ByteArrayOutputStream bout = new ByteArrayOutputStream(LEN);
ByteArrayOutputStream bout = new ByteArrayOutputStream(len + (len >> 2));
OutputStreamWriter out = new OutputStreamWriter(bout, "UTF-8");
out.write("[\"");
String VALUE = sb.toString();
Expand Down

0 comments on commit 69c844c

Please sign in to comment.