当前位置: 首页>>代码示例>>Java>>正文


Java ScriptRuntime.indexFromString方法代码示例

本文整理汇总了Java中org.mozilla.javascript.ScriptRuntime.indexFromString方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptRuntime.indexFromString方法的具体用法?Java ScriptRuntime.indexFromString怎么用?Java ScriptRuntime.indexFromString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.mozilla.javascript.ScriptRuntime的用法示例。


在下文中一共展示了ScriptRuntime.indexFromString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readObject

import org.mozilla.javascript.ScriptRuntime; //导入方法依赖的package包/类
private Object readObject() throws ParseException {
    consumeWhitespace();
    Scriptable object = cx.newObject(scope);
    // handle empty object literal case early
    if (pos < length && src.charAt(pos) == '}') {
        pos += 1;
        return object;
    }
    String id;
    Object value;
    boolean needsComma = false;
    while (pos < length) {
        char c = src.charAt(pos++);
        switch(c) {
            case '}':
                if (!needsComma) {
                    throw new ParseException("Unexpected comma in object literal");
                }
                return object;
            case ',':
                if (!needsComma) {
                    throw new ParseException("Unexpected comma in object literal");
                }
                needsComma = false;
                break;
            case '"':
                if (needsComma) {
                    throw new ParseException("Missing comma in object literal");
                }
                id = readString();
                consume(':');
                value = readValue();

                long index = ScriptRuntime.indexFromString(id);
                if (index < 0) {
                  object.put(id, object, value);
                } else {
                  object.put((int)index, object, value);
                }

                needsComma = true;
                break;
            default:
                throw new ParseException("Unexpected token in object literal");
        }
        consumeWhitespace();
    }
    throw new ParseException("Unterminated object literal");
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:50,代码来源:JsonParser.java

示例2: readObject

import org.mozilla.javascript.ScriptRuntime; //导入方法依赖的package包/类
private Object readObject() throws ParseException {
    Scriptable object = cx.newObject(scope);
    String id;
    Object value;
    boolean needsComma = false;
    consumeWhitespace();
    while (pos < length) {
        char c = src.charAt(pos++);
        switch(c) {
            case '}':
                return object;
            case ',':
                if (!needsComma) {
                    throw new ParseException("Unexpected comma in object literal");
                }
                needsComma = false;
                break;
            case '"':
                if (needsComma) {
                    throw new ParseException("Missing comma in object literal");
                }
                id = readString();
                consume(':');
                value = readValue();

                long index = ScriptRuntime.indexFromString(id);
                if (index < 0) {
                  object.put(id, object, value);
                } else {
                  object.put((int)index, object, value);
                }

                needsComma = true;
                break;
            default:
                throw new ParseException("Unexpected token in object literal");
        }
        consumeWhitespace();
    }
    throw new ParseException("Unterminated object literal");
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:42,代码来源:JsonParser.java


注:本文中的org.mozilla.javascript.ScriptRuntime.indexFromString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。