private void writeString(String string) throws JSONException {

// Special case for empty strings.

        if (string.length() == 0) {
            zero();
            zero();
            write(end, this.substringhuff);
            zero();
        } else {
            Kim kim = new Kim(string);

// Look for the string in the strings keep. If it is found, emit its
// integer and count that as a use.

            int integer = this.stringkeep.find(kim);
            if (integer != none) {
                one();
                writeAndTick(integer, this.stringkeep);
            } else {

// But if it is not found, emit the string's substrings. Register the string
// so that the next lookup will succeed.

                writeSubstring(kim);
                this.stringkeep.register(kim);
            }
        }
    }