Java 类com.alibaba.fastjson.parser.CharTypes 实例源码

项目:android_http_demo    文件:SerializeWriter.java   
private void writeKeyWithSingleQuote(String text) {
    final boolean[] specicalFlags_singleQuotes = CharTypes.specicalFlags_singleQuotes;

    int len = text.length();
    int newcount = count + len + 3;
    if (newcount > buf.length) {
        expandCapacity(newcount);
    }

    int start = count + 1;
    int end = start + len;

    buf[count] = '\'';
    text.getChars(0, len, buf, start);
    count = newcount;

    for (int i = start; i < end; ++i) {
        char ch = buf[i];
        if (ch < specicalFlags_singleQuotes.length
            && specicalFlags_singleQuotes[ch] //
            || (ch == '\t' && isEnabled(SerializerFeature.WriteTabAsSpecial))
            || (ch == '/' && isEnabled(SerializerFeature.WriteSlashAsSpecial))) {
            newcount++;
            if (newcount > buf.length) {
                expandCapacity(newcount);
            }
            count = newcount;

            System.arraycopy(buf, i + 1, buf, i + 2, end - i - 1);
            buf[i] = '\\';
            buf[++i] = replaceChars[(int) ch];
            end++;
        }
    }

    buf[count - 2] = '\'';
    buf[count - 1] = ':';
}
项目:AndroidNio    文件:SerializeWriter.java   
private void writeKeyWithSingleQuote(String text) {
    final boolean[] specicalFlags_singleQuotes = CharTypes.specicalFlags_singleQuotes;

    int len = text.length();
    int newcount = count + len + 3;
    if (newcount > buf.length) {
        expandCapacity(newcount);
    }

    int start = count + 1;
    int end = start + len;

    buf[count] = '\'';
    text.getChars(0, len, buf, start);
    count = newcount;

    for (int i = start; i < end; ++i) {
        char ch = buf[i];
        if (ch < specicalFlags_singleQuotes.length
            && specicalFlags_singleQuotes[ch] //
            || (ch == '\t' && isEnabled(SerializerFeature.WriteTabAsSpecial))
            || (ch == '/' && isEnabled(SerializerFeature.WriteSlashAsSpecial))) {
            newcount++;
            if (newcount > buf.length) {
                expandCapacity(newcount);
            }
            count = newcount;

            System.arraycopy(buf, i + 1, buf, i + 2, end - i - 1);
            buf[i] = '\\';
            buf[++i] = replaceChars[(int) ch];
            end++;
        }
    }

    buf[count - 2] = '\'';
    buf[count - 1] = ':';
}
项目:android_http_demo    文件:SerializeWriter.java   
public void writeKeyWithDoubleQuote(String text, boolean checkSpecial) {
    final boolean[] specicalFlags_doubleQuotes = CharTypes.specicalFlags_doubleQuotes;

    int len = text.length();
    int newcount = count + len + 3;
    if (newcount > buf.length) {
        expandCapacity(newcount);
    }

    int start = count + 1;
    int end = start + len;

    buf[count] = '\"';
    text.getChars(0, len, buf, start);

    count = newcount;

    if (checkSpecial) {
        for (int i = start; i < end; ++i) {
            char ch = buf[i];
            if (ch < specicalFlags_doubleQuotes.length
                && specicalFlags_doubleQuotes[ch] //
                || (ch == '\t' && isEnabled(SerializerFeature.WriteTabAsSpecial))
                || (ch == '/' && isEnabled(SerializerFeature.WriteSlashAsSpecial))) {
                newcount++;
                if (newcount > buf.length) {
                    expandCapacity(newcount);
                }
                count = newcount;

                System.arraycopy(buf, i + 1, buf, i + 2, end - i - 1);
                buf[i] = '\\';
                buf[++i] = replaceChars[(int) ch];
                end++;
            }
        }
    }

    buf[count - 2] = '\"';
    buf[count - 1] = ':';
}
项目:android_http_demo    文件:SerializeWriter.java   
private void writeKeyWithDoubleQuoteIfHasSpecial(String text) {
    final boolean[] specicalFlags_doubleQuotes = CharTypes.specicalFlags_doubleQuotes;

    int len = text.length();
    int newcount = count + len + 1;
    if (newcount > buf.length) {
        expandCapacity(newcount);
    }

    int start = count;
    int end = start + len;

    text.getChars(0, len, buf, start);
    count = newcount;

    boolean hasSpecial = false;

    for (int i = start; i < end; ++i) {
        char ch = buf[i];
        if (ch < specicalFlags_doubleQuotes.length && specicalFlags_doubleQuotes[ch]) {
            if (!hasSpecial) {
                newcount += 3;
                if (newcount > buf.length) {
                    expandCapacity(newcount);
                }
                count = newcount;

                System.arraycopy(buf, i + 1, buf, i + 3, end - i - 1);
                System.arraycopy(buf, 0, buf, 1, i);
                buf[start] = '"';
                buf[++i] = '\\';
                buf[++i] = replaceChars[(int) ch];
                end += 2;
                buf[count - 2] = '"';

                hasSpecial = true;
            } else {
                newcount++;
                if (newcount > buf.length) {
                    expandCapacity(newcount);
                }
                count = newcount;

                System.arraycopy(buf, i + 1, buf, i + 2, end - i);
                buf[i] = '\\';
                buf[++i] = replaceChars[(int) ch];
                end++;
            }
        }
    }

    buf[count - 1] = ':';
}
项目:android_http_demo    文件:SerializeWriter.java   
private void writeKeyWithSingleQuoteIfHasSpecial(String text) {
    final boolean[] specicalFlags_singleQuotes = CharTypes.specicalFlags_singleQuotes;

    int len = text.length();
    int newcount = count + len + 1;
    if (newcount > buf.length) {
        expandCapacity(newcount);
    }

    int start = count;
    int end = start + len;

    text.getChars(0, len, buf, start);
    count = newcount;

    boolean hasSpecial = false;

    for (int i = start; i < end; ++i) {
        char ch = buf[i];
        if (ch < specicalFlags_singleQuotes.length && specicalFlags_singleQuotes[ch]) {
            if (!hasSpecial) {
                newcount += 3;
                if (newcount > buf.length) {
                    expandCapacity(newcount);
                }
                count = newcount;

                System.arraycopy(buf, i + 1, buf, i + 3, end - i - 1);
                System.arraycopy(buf, 0, buf, 1, i);
                buf[start] = '\'';
                buf[++i] = '\\';
                buf[++i] = replaceChars[(int) ch];
                end += 2;
                buf[count - 2] = '\'';

                hasSpecial = true;
            } else {
                newcount++;
                if (newcount > buf.length) {
                    expandCapacity(newcount);
                }
                count = newcount;

                System.arraycopy(buf, i + 1, buf, i + 2, end - i);
                buf[i] = '\\';
                buf[++i] = replaceChars[(int) ch];
                end++;
            }
        }
    }

    buf[newcount - 1] = ':';
}
项目:AndroidNio    文件:SerializeWriter.java   
public void writeKeyWithDoubleQuote(String text, boolean checkSpecial) {
    final boolean[] specicalFlags_doubleQuotes = CharTypes.specicalFlags_doubleQuotes;

    int len = text.length();
    int newcount = count + len + 3;
    if (newcount > buf.length) {
        expandCapacity(newcount);
    }

    int start = count + 1;
    int end = start + len;

    buf[count] = '\"';
    text.getChars(0, len, buf, start);

    count = newcount;

    if (checkSpecial) {
        for (int i = start; i < end; ++i) {
            char ch = buf[i];
            if (ch < specicalFlags_doubleQuotes.length
                && specicalFlags_doubleQuotes[ch] //
                || (ch == '\t' && isEnabled(SerializerFeature.WriteTabAsSpecial))
                || (ch == '/' && isEnabled(SerializerFeature.WriteSlashAsSpecial))) {
                newcount++;
                if (newcount > buf.length) {
                    expandCapacity(newcount);
                }
                count = newcount;

                System.arraycopy(buf, i + 1, buf, i + 2, end - i - 1);
                buf[i] = '\\';
                buf[++i] = replaceChars[(int) ch];
                end++;
            }
        }
    }

    buf[count - 2] = '\"';
    buf[count - 1] = ':';
}
项目:AndroidNio    文件:SerializeWriter.java   
private void writeKeyWithDoubleQuoteIfHasSpecial(String text) {
    final boolean[] specicalFlags_doubleQuotes = CharTypes.specicalFlags_doubleQuotes;

    int len = text.length();
    int newcount = count + len + 1;
    if (newcount > buf.length) {
        expandCapacity(newcount);
    }

    int start = count;
    int end = start + len;

    text.getChars(0, len, buf, start);
    count = newcount;

    boolean hasSpecial = false;

    for (int i = start; i < end; ++i) {
        char ch = buf[i];
        if (ch < specicalFlags_doubleQuotes.length && specicalFlags_doubleQuotes[ch]) {
            if (!hasSpecial) {
                newcount += 3;
                if (newcount > buf.length) {
                    expandCapacity(newcount);
                }
                count = newcount;

                System.arraycopy(buf, i + 1, buf, i + 3, end - i - 1);
                System.arraycopy(buf, 0, buf, 1, i);
                buf[start] = '"';
                buf[++i] = '\\';
                buf[++i] = replaceChars[(int) ch];
                end += 2;
                buf[count - 2] = '"';

                hasSpecial = true;
            } else {
                newcount++;
                if (newcount > buf.length) {
                    expandCapacity(newcount);
                }
                count = newcount;

                System.arraycopy(buf, i + 1, buf, i + 2, end - i);
                buf[i] = '\\';
                buf[++i] = replaceChars[(int) ch];
                end++;
            }
        }
    }

    buf[count - 1] = ':';
}
项目:AndroidNio    文件:SerializeWriter.java   
private void writeKeyWithSingleQuoteIfHasSpecial(String text) {
    final boolean[] specicalFlags_singleQuotes = CharTypes.specicalFlags_singleQuotes;

    int len = text.length();
    int newcount = count + len + 1;
    if (newcount > buf.length) {
        expandCapacity(newcount);
    }

    int start = count;
    int end = start + len;

    text.getChars(0, len, buf, start);
    count = newcount;

    boolean hasSpecial = false;

    for (int i = start; i < end; ++i) {
        char ch = buf[i];
        if (ch < specicalFlags_singleQuotes.length && specicalFlags_singleQuotes[ch]) {
            if (!hasSpecial) {
                newcount += 3;
                if (newcount > buf.length) {
                    expandCapacity(newcount);
                }
                count = newcount;

                System.arraycopy(buf, i + 1, buf, i + 3, end - i - 1);
                System.arraycopy(buf, 0, buf, 1, i);
                buf[start] = '\'';
                buf[++i] = '\\';
                buf[++i] = replaceChars[(int) ch];
                end += 2;
                buf[count - 2] = '\'';

                hasSpecial = true;
            } else {
                newcount++;
                if (newcount > buf.length) {
                    expandCapacity(newcount);
                }
                count = newcount;

                System.arraycopy(buf, i + 1, buf, i + 2, end - i);
                buf[i] = '\\';
                buf[++i] = replaceChars[(int) ch];
                end++;
            }
        }
    }

    buf[newcount - 1] = ':';
}