Ejemplo n.º 1
0
static int jsmin_next(jsmin_parser *parser) {
    unsigned char c = jsmin_get(parser);
    if  (c == '/') {
        switch (jsmin_peek(parser)) {
        case '/':
            for (;;) {
                c = jsmin_get(parser);
                if (c <= '\n') {
                    break;
                }
            }
            break;
        case '*':
            jsmin_get(parser);
            while (c != ' ') {
                switch (jsmin_get(parser)) {
                case '*':
                    if (jsmin_peek(parser) == '/') {
                        jsmin_get(parser);
                        c = ' ';
                    }
                    break;
                case '\0':
                    jsmin_error(parser, SL("Unterminated comment."));
                    return FAILURE;
                }
            }
            break;
        }
    }
    parser->theY = parser->theX;
    parser->theX = c;
    return c;
}
Ejemplo n.º 2
0
			return c;
		}
	}
	if (c == '\r') {
		return '\n';
	}
	return ' ';
}


/* next -- get the next character, excluding comments. peek() is used to see
		if a '/' is followed by a '/' or '*'.
*/

static int jsmin_next(jsmin_parser *parser TSRMLS_DC) {
	unsigned char c = jsmin_get(parser);
	if  (c == '/') {
		switch (jsmin_peek(parser)) {
			case '/':
				for (;;) {
					c = jsmin_get(parser);
					if (c <= '\n') {
						break;
					}
				}
				break;
		case '*':
			jsmin_get(parser);
			while (c != ' ') {
				switch (jsmin_get(parser)) {
					case '*':
Ejemplo n.º 3
0
static int jsmin_action(jsmin_parser *parser, unsigned char d) {
    switch (d) {
    case JSMIN_ACTION_OUTPUT_NEXT:
        smart_str_appendc(parser->minified, parser->theA);
        if (
            (parser->theY == '\n' || parser->theY == ' ') &&
            (parser->theA == '+' || parser->theA == '-' || parser->theA == '*' || parser->theA == '/') &&
            (parser->theB == '+' || parser->theB == '-' || parser->theB == '*' || parser->theB == '/')
        ) {
            smart_str_appendc(parser->minified, parser->theY);
        }
    /* no break */
    case JSMIN_ACTION_NEXT_DELETE:
        parser->theA = parser->theB;
        if (parser->theA == '\'' || parser->theA == '"' || parser->theA == '`') {
            parser->inside_string = 1;
            for (;;) {
                smart_str_appendc(parser->minified, parser->theA);
                parser->theA = jsmin_get(parser);
                if (parser->theA == parser->theB) {
                    break;
                }
                if (parser->theA == '\\') {
                    smart_str_appendc(parser->minified, parser->theA);
                    parser->theA = jsmin_get(parser);
                }
                if (parser->theA == '\0') {
                    jsmin_error(parser, SL("Unterminated string literal."));
                    return FAILURE;
                }
            }
            parser->inside_string = 0;
        }
    /* no break */
    case JSMIN_ACTION_NEXT:
        parser->theB = jsmin_next(parser);
        if (parser->error != NULL) {
            return FAILURE;
        }
        if (parser->theB == '/' && (
                    parser->theA == '(' || parser->theA == ',' || parser->theA == '=' || parser->theA == ':' ||
                    parser->theA == '[' || parser->theA == '!' || parser->theA == '&' || parser->theA == '|' ||
                    parser->theA == '?' || parser->theA == '+' || parser->theA == '-' || parser->theA == '~' ||
                    parser->theA == '*' || parser->theA == '/' || parser->theA == '{' || parser->theA == '\n'
                )) {
            smart_str_appendc(parser->minified, parser->theA);
            if (parser->theA == '/' || parser->theA == '*') {
                smart_str_appendc(parser->minified, ' ');
            }
            smart_str_appendc(parser->minified, parser->theB);
            for (;;) {
                parser->theA = jsmin_get(parser);
                if (parser->theA == '[') {
                    for (;;) {
                        smart_str_appendc(parser->minified, parser->theA);
                        parser->theA = jsmin_get(parser);
                        if (parser->theA == ']') {
                            break;
                        }
                        if (parser->theA == '\\') {
                            smart_str_appendc(parser->minified, parser->theA);
                            parser->theA = jsmin_get(parser);
                        }
                        if (parser->theA == '\0') {
                            jsmin_error(parser, SL("Unterminated set in Regular Expression literal."));
                            return FAILURE;
                        }
                    }
                } else {
                    if (parser->theA == '/') {
                        switch (jsmin_peek(parser)) {
                        case '/':
                        case '*':
                            jsmin_error(parser, SL("Unterminated set in Regular Expression literal."));
                            return FAILURE;
                        }
                        break;
                    } else {
                        if (parser->theA == '\\') {
                            smart_str_appendc(parser->minified, parser->theA);
                            parser->theA = jsmin_get(parser);
                        }
                    }
                }
                if (parser->theA == '\0') {
                    jsmin_error(parser, SL("Unterminated Regular Expression literal."));
                    return FAILURE;
                }
                smart_str_appendc(parser->minified, parser->theA);
            }
            parser->theB = jsmin_next(parser);
            if (parser->error != NULL) {
                return FAILURE;
            }
        }
    }

    return SUCCESS;
}