Java Code Examples for org.lwjgl.system.MemoryUtil#memUTF16()

The following examples show how to use org.lwjgl.system.MemoryUtil#memUTF16() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: APIBuffer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * UTF16 encodes the specified strings and ensures space for two additional
 * buffers filled with the lengths and memory addresses of the encoded
 * strings, respectively. The lengths are 4-bytes integers and the memory
 * address buffer starts immediately after the lengths buffer.
 *
 * <p>
 * The encoded buffers must be later freed with
 * {@link #pointerArrayFree(int, int)}.</p>
 *
 * @return the offset to the lengths buffer
 */
public int pointerArrayParamUTF16i(CharSequence... strings) {
    int buffersAddress = bufferParam(strings.length << POINTER_SHIFT);
    int lengthsAddress = bufferParam(strings.length << 2);

    for (int i = 0; i < strings.length; i++) {
        ByteBuffer buffer = MemoryUtil.memUTF16(strings[i]);

        pointerParam(buffersAddress, i, memAddress(buffer));
        intParam(lengthsAddress, i, buffer.remaining());
    }

    return buffersAddress;
}
 
Example 2
Source File: APIBuffer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * UTF16 encodes the specified strings and ensures space for two additional
 * buffers filled with the lengths and memory addresses of the encoded
 * strings, respectively. The lengths are pointer-sized integers and the
 * memory address buffer starts immediately after the lengths buffer.
 *
 * <p>
 * The encoded buffers must be later freed with
 * {@link #pointerArrayFree(int, int)}.</p>
 *
 * @return the offset to the lengths buffer
 */
public int pointerArrayParamUTF16p(CharSequence... strings) {
    int buffersAddress = bufferParam(strings.length << POINTER_SHIFT);
    int lengthsAddress = bufferParam(strings.length << POINTER_SHIFT);

    for (int i = 0; i < strings.length; i++) {
        ByteBuffer buffer = MemoryUtil.memUTF16(strings[i]);

        pointerParam(buffersAddress, i, memAddress(buffer));
        pointerParam(lengthsAddress, i, buffer.remaining());
    }

    return buffersAddress;
}
 
Example 3
Source File: APIBuffer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Ensures space for the specified string encoded in UTF-16, encodes the
 * string at the allocated offset and returns that offset.
 */
public int stringParamUTF16(CharSequence value, boolean nullTerminated) {
    if (value == null) {
        return -1;
    }

    int offset = bufferParam((value.length() + (nullTerminated ? 1 : 0)) << 1);
    MemoryUtil.memUTF16(value, nullTerminated, buffer, offset);
    return offset;
}
 
Example 4
Source File: APIBuffer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns the UTF16 string value at the specified byte range.
 */
public String stringValueUTF16(int offset, int limit) {
    buffer.position(offset);
    buffer.limit(limit);
    try {
        return MemoryUtil.memUTF16(buffer);
    } finally {
        buffer.clear();
    }
}
 
Example 5
Source File: APIBuffer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * UTF16 encodes the specified strings with a null-terminator and ensures
 * space for a buffer filled with the memory addresses of the encoded
 * strings.
 *
 * <p>
 * The encoded buffers must be later freed with
 * {@link #pointerArrayFree(int, int)}.</p>
 *
 * @return the offset to the memory address buffer
 */
public int pointerArrayParamUTF16(CharSequence... strings) {
    int buffersAddress = bufferParam(strings.length << POINTER_SHIFT);
    for (int i = 0; i < strings.length; i++) {
        ByteBuffer buffer = MemoryUtil.memUTF16(strings[i]);

        pointerParam(buffersAddress, i, memAddress(buffer));
    }

    return buffersAddress;
}