Exemple #1
0
 /**
  * Fills token type and boundaries.
  */
 private void jsmn_fill_token(ref jsmntok_t token, jsmntype_t type, int start, int end)
 {
     token.type  = type;
     token.start = start;
     token.end   = end;
     token.size  = 0;
 }
Exemple #2
0
        /**
         * Allocates a fresh unused token from the token pull.
         */
        private jsmntok_t jsmn_alloc_token(ref jsmn_parser parser, ref jsmntok_t[] tokens, uint num_tokens)
        {
            jsmntok_t tok = new jsmntok_t();;

            if (parser.toknext >= num_tokens)
            {
                return(null);
            }
            //tok = tokens[parser.toknext++];
            tok.start = tok.end = -1;
            tok.size  = 0;
            tokens[parser.toknext++] = tok;
            return(tok);
        }
Exemple #3
0
        /**
         * Fills next available token with JSON primitive.
         */
        private int jsmn_parse_primitive(ref jsmn_parser parser, char[] js, uint len, jsmntok_t[] tokens, uint num_tokens)
        {
            jsmntok_t token = new jsmntok_t();
            int       start;

            start = parser.pos;

            for (; parser.pos < len && js[parser.pos] != '\0'; parser.pos++)
            {
                switch (js[parser.pos])
                {
                case '\t':
                case '\r':
                case '\n':
                case ' ':
                case ',':
                case ']':
                case '}':
                    goto found;
                }
                if (js[parser.pos] < 32 || js[parser.pos] >= 127)
                {
                    parser.pos = start;
                    return((int)jsmnerr_t.JSMN_ERROR_INVAL);
                }
            }


found:
            if (tokens == null)
            {
                parser.pos--;
                return(0);
            }
            token = jsmn_alloc_token(ref parser, ref tokens, num_tokens);
            if (token == null)
            {
                parser.pos = start;
                return((int)jsmnerr_t.JSMN_ERROR_NOMEM);
            }
            jsmn_fill_token(ref token, jsmntype_t.JSMN_PRIMITIVE, start, parser.pos);

            parser.pos--;
            return(0);
        }