class CharSequenceAccessor {

    static public CharArrayWrapper access(CharSequence str) {
        if (str == null) {
            return null;
        }
        try {
            if (str instanceof String) {
                if (hasStringFields) {
                    CharArrayWrapper w = new CharArrayWrapper();
                    w.value = (char[])stringValueField.get(str);
                    w.offset = stringOffsetField.getInt(str);
                    w.length = stringCountField.getInt(str);
                    return w;
                }
            } else if (str instanceof StringBuilder) {
                if (hasStringBuilderFields) {
                    CharArrayWrapper w = new CharArrayWrapper();
                    w.value = (char[])stringBuilderValueField.get(str);
                    w.length = stringBuilderCountField.getInt(str);
                    return w;
                }
            }
        } catch (Throwable t) {
            // do nothing
        }
        return null;
    }

}