Exemple #1
0
static void
jsmin()
{
    if (peek() == 0xEF) {
        get();
        get();
        get();
    }
    theA = '\n';
    action(3);
    while (theA != EOF) {
        switch (theA) {
        case ' ':
            action(isAlphanum(theB) ? 1 : 2);
            break;
        case '\n':
            switch (theB) {
            case '{':
            case '[':
            case '(':
            case '+':
            case '-':
            case '!':
            case '~':
                action(1);
                break;
            case ' ':
                action(3);
                break;
            default:
                action(isAlphanum(theB) ? 1 : 2);
            }
            break;
        default:
            switch (theB) {
            case ' ':
                action(isAlphanum(theA) ? 1 : 3);
                break;
            case '\n':
                switch (theA) {
                case '}':
                case ']':
                case ')':
                case '+':
                case '-':
                case '"':
                case '\'':
                case '`':
                    action(1);
                    break;
                default:
                    action(isAlphanum(theA) ? 1 : 3);
                }
                break;
            default:
                action(1);
                break;
            }
        }
    }
}
Exemple #2
0
/*-----------------------------------------------------------------------------
 jsmin -- Copy the input to the output, deleting the characters which are
        insignificant to JavaScript. Comments will be removed. Tabs will be
        replaced with spaces. Carriage returns will be replaced with linefeeds.
        Most spaces and linefeeds will be removed.
-----------------------------------------------------------------------------*/
void JSMin::Run()
{
    theA = '\n';
    action(3);
    while (ret && theA != EOF) {
        switch (theA) {
        case ' ':
            if (isAlphanum(theB)) {
                action(1);
            } else {
                action(2);
            }
            break;
        case '\n':
            switch (theB) {
            case '{':
            case '[':
            case '(':
            case '+':
            case '-':
                action(1);
                break;
            case ' ':
                action(3);
                break;
            default:
                if (isAlphanum(theB)) {
                    action(1);
                } else {
                    action(2);
                }
            }
            break;
        default:
            switch (theB) {
            case ' ':
                if (isAlphanum(theA)) {
                    action(1);
                    break;
                }
                action(3);
                break;
            case '\n':
                switch (theA) {
                case '}':
                case ']':
                case ')':
                case '+':
                case '-':
                case '"':
                case '\'':
                    action(1);
                    break;
                default:
                    if (isAlphanum(theA)) {
                        action(1);
                    } else {
                        action(3);
                    }
                }
                break;
            default:
                action(1);
                break;
            }
        }
    }
}
void jsmin(ngx_buf_t *in,ngx_buf_t *out)
{
    if (peek(in) == 0xEF) {
        get(in);
        get(in);
        get(in);
    }

    theA = '\n';
    action(3,in,out);
    while (theA != EOF) {
        switch (theA) {

        case ' ':
            action(isAlphanum(theB) ? 1 : 2,in,out);
            break;

        case '\n':
            switch (theB) {

            case '{':
            case '[':
            case '(':
            case '+':
            case '-':
            case '!':
            case '~':
                action(1,in,out);
                break;

            case ' ':
                action(3,in,out);
                break;

            default:
                action(isAlphanum(theB) ? 1 : 2,in,out);
            }
            break;

        default:
            switch (theB) {

            case ' ':
                action(isAlphanum(theA) ? 1 : 3,in,out);
                break;

            case '\n':
                switch (theA) {

                case '}':
                case ']':
                case ')':
                case '+':
                case '-':
                case '"':
                case '\'':
                case '`':
                    action(1,in,out);
                    break;

                default:
                    action(isAlphanum(theA) ? 1 : 3,in,out);
                }
                break;

            default:
                action(1,in,out);
                break;
            }
        }
    }

    out->end = out->pos;
    out->last = out->pos;
    out->pos = out->start;
}
Exemple #4
0
static void
jsmin(jsmin_struct *s)
{
    if (peek(s) == 0xEF) {
        get(s);
        get(s);
        get(s);
    }
    s->theA = '\n';

    action(s, 3);
    while (s->theA != '\0') {
        switch (s->theA) {
        case ' ':
            action(s, isAlphanum(s->theB) ? 1 : 2);
            break;
        case '\n':
            switch (s->theB) {
            case '{':
            case '[':
            case '(':
            case '+':
            case '-':
            case '!':
            case '~':
                action(s, 1);
                break;
            case ' ':
                action(s, 3);
                break;
            default:
                action(s, isAlphanum(s->theB) ? 1 : 2);
            }
            break;
        default:
            switch (s->theB) {
            case ' ':
                action(s, isAlphanum(s->theA) ? 1 : 3);
                break;
            case '\n':
                switch (s->theA) {
                case '}':
                case ']':
                case ')':
                case '+':
                case '-':
                case '"':
                case '\'':
                case '`':
                    action(s, 1);
                    break;
                default:
                    action(s, isAlphanum(s->theA) ? 1 : 3);
                }
                break;
            default:
                action(s, 1);
                break;
            }
        }
    }
    write_char(s, '\0');
}
Exemple #5
0
static void
jsmin(jsmin_struct *s)
{
    s->theA = '\n';
    s->theLookahead = '\0';

    action(s, 3);
    while (s->theA != '\0') {
        switch (s->theA) {
        case ' ':
            if (isAlphanum(s->theB)) {
                action(s, 1);
            } else {
                action(s, 2);
            }
            break;
        case '\n':
            switch (s->theB) {
            case '{':
            case '[':
            case '(':
            case '+':
            case '-':
                action(s, 1);
                break;
            case ' ':
                action(s, 3);
                break;
            default:
                if (isAlphanum(s->theB)) {
                    action(s, 1);
                } else {
                    action(s, 2);
                }
            }
            break;
        default:
            switch (s->theB) {
            case ' ':
                if (isAlphanum(s->theA)) {
                    action(s, 1);
                    break;
                }
                action(s, 3);
                break;
            case '\n':
                switch (s->theA) {
                case '}':
                case ']':
                case ')':
                case '+':
                case '-':
                case '"':
                case '\'':
                case '`':
                    action(s, 1);
                    break;
                default:
                    if (isAlphanum(s->theA)) {
                        action(s, 1);
                    } else {
                        action(s, 3);
                    }
                }
                break;
            default:
                action(s, 1);
                break;
            }
        }
    }
    write_char(s, '\0');
}
Exemple #6
0
int
jsmin(jsminCtx *ctx)
{
	int res = JSMIN_OK;

	ctx->theLookahead = EOF;
	ctx->theX = EOF;
	ctx->theY = EOF;

    if (peek(ctx) == 0xEF) {
        get(ctx);
        get(ctx);
        get(ctx);
    }
    ctx->theA = '\n';
    res = action(ctx,3);
	if (res != JSMIN_OK) return res;
    while (ctx->theA != EOF) {
        switch (ctx->theA) {
        case ' ':
            res = action(ctx, isAlphanum(ctx->theB) ? 1 : 2);
			if (res != JSMIN_OK) return res;
            break;
        case '\n':
            switch (ctx->theB) {
            case '{':
            case '[':
            case '(':
            case '+':
            case '-':
            case '!':
            case '~':
                res = action(ctx, 1);
				if (res != JSMIN_OK) return res;
                break;
            case ' ':
                res = action(ctx, 3);
				if (res != JSMIN_OK) return res;
                break;
            default:
                res = action(ctx, isAlphanum(ctx->theB) ? 1 : 2);
				if (res != JSMIN_OK) return res;
            }
            break;
        default:
            switch (ctx->theB) {
            case ' ':
                res = action(ctx, isAlphanum(ctx->theA) ? 1 : 3);
				if (res != JSMIN_OK) return res;
                break;
            case '\n':
                switch (ctx->theA) {
                case '}':
                case ']':
                case ')':
                case '+':
                case '-':
                case '"':
                case '\'':
                case '`':
                    res = action(ctx, 1);
					if (res != JSMIN_OK) return res;
                    break;
                default:
                    res = action(ctx, isAlphanum(ctx->theA) ? 1 : 3);
					if (res != JSMIN_OK) return res;
                }
                break;
            default:
                res = action(ctx, 1);
				if (res != JSMIN_OK) return res;
                break;
            }
        }
    }
	return res;
}