httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevac Marko" <mke...@gmail.com>
Subject Regular expression matching for multi line strings...
Date Mon, 22 Dec 2008 13:46:21 GMT
Hello.

ap_regexec() do not match multi line strings without AP_REG_NEWLINE
flag, but it should.

For example i have string:

SELECT\r\n    state.SECNAME,\r\n    state.SHORTNAME,\r\n
state.LATNAME,\r\n    state.DECIMALS,\r\n    state.PREVPRICE,\r\n
realtime.BOARDID as BOARDID,\r\n    realtime.SECID as SECID,\r\n
realtime.STATUS as STATUS,\r\n    realtime.BID as BID,\r\n
realtime.BIDDEPTH as BIDDEPTH,\r\n    realtime.BIDDEPTHT as
BIDDEPTHT,\r\n    realtime.NUMBIDS as NUMBIDS,\r\n    realtime.OFFER
as OFFER,\r\n    realtime.OFFERDEPTH as OFFERDEPTH,\r\n
realtime.OFFERDEPTHT as OFFERDEPTHT,\r\n    realtime.NUMOFFERS as
NUMOFFERS,\r\n    realtime.OPEN as OPEN,\r\n    realtime.HIGH as
HIGH,\r\n    realtime.LOW as LOW,\r\n    realtime.LAST as LAST,\r\n
realtime.`CHANGE` as `CHANGE`,\r\n
ROUND(realtime.LASTCHANGEPRCNT,state.DECIMALS) AS LASTCHANGEPRCNT,
\r\n    realtime.LASTCNGTOLASTWAPRICE as LASTCNGTOLASTWAPRICE,\r\n
realtime.QTY as QTY,\r\n    realtime.TIME as TIME,\r\n
realtime.VOLTODAY as VOLTODAY,\r\n    realtime.VALTODAY as
VALTODAY,\r\n    realtime.VALTODAY_USD as VALTODAY_USD,\r\n
realtime.TRADINGSTATUS as TRADINGSTATUS,\r\n    realtime.VALUE as
VALUE,\r\n    realtime.VALUE_USD as VALUE_USD,\r\n    realtime.WAPRICE
as WAPRICE,\r\n    realtime.WAPTOPREVWAPRICEPRCNT as
WAPTOPREVWAPRICEPRCNT,\r\n    realtime.WAPTOPREVWAPRICE as
WAPTOPREVWAPRICE,\r\n    realtime.HIGHBID as HIGHBID,\r\n
realtime.LOWOFFER as LOWOFFER,\r\n    realtime.NUMTRADES as
NUMTRADES,\r\n    realtime.PRICEMINUSPREVWAPRICE as
PRICEMINUSPREVWAPRICE,\r\n    realtime.CLOSEPRICE as CLOSEPRICE,\r\n
 realtime.LASTBID as LASTBID,\r\n    realtime.LASTOFFER as
LASTOFFER,\r\n    realtime.MARKETPRICE as MARKETPRICE,\r\n
realtime.MARKETPRICETODAY as MARKETPRICETODAY,\r\n
realtime.LOPENPRICE as LOPENPRICE,\r\n    realtime.LCURRENTPRICE as
LCURRENTPRICE,\r\n    realtime.LCLOSEPRICE as LCLOSEPRICE,\r\n
realtime.MARKETPRICE2 as MARKETPRICE2,\r\n    realtime.ADMITTEDQUOTE
as ADMITTEDQUOTE,\r\n    realtime.OPENPERIODPRICE as
OPENPERIODPRICE,\r\n    realtime.UPDATETIME as UPDATETIME,\r\n
realtime.SEQNUM as SEQNUM,\r\n    realtime.SPREAD as SPREAD,\r\n
realtime.LASTCHANGE as LASTCHANGE,\r\n    realtime.LASTTOPREVPRICE as
LASTTOPREVPRICE,\r\n    realtime.SYSTIME as SYSTIME,\r\n
'%table_type%' as TABLE_TYPE\r\n\r\nFROM \r\n\r\n
online.stock_shares_stat_info state, \r\n
online.stock_shares_%table_type% realtime, \r\n
root_db_dev.securities securities,\r\n
root_db_dev.securities_to_security_collections sectocollection,\r\n
root_db_dev.security_collections collections,\r\n   root_db_dev.boards
boards\r\n\r\nWHERE (\r\n   state.BOARDID=realtime.BOARDID\r\n   AND
\r\n   state.SECID=realtime.SECID \r\n   AND \r\n
securities.SECID=state.SECID \r\n   AND \r\n
sectocollection.SECURITY_ID=securities.ID \r\n   AND \r\n
sectocollection.SECURITY_COLLECTION_ID=collections.ID \r\n   AND\r\n
boards.BOARDID=state.BOARDID\r\n   AND \r\n
boards.board_group_id=?\r\n   AND\r\n   collections.ID=?\r\n   AND\r\n
  realtime.SEQNUM>?\r\n   AND\r\n   realtime.NUMTRADES>=?\r\n)
\r\n\r\norder by %sort_order% %sort_order_desc%\r\n\r\nLIMIT ?,?

And i want to change every %% to something else.

So i wrote small function:

char *utilSubstringSubstitute(apr_pool_t *pool, char *string, char
delimiter, char *substitute, char *value)
{
    ap_regex_t *regex_compiled;
    ap_regmatch_t regex_match[AP_MAX_REG_MATCH];
    int rv;

    char *regex = apr_psprintf(pool, "(.*)%c%s%c(.*)", delimiter,
substitute, delimiter);

    regex_compiled = ap_pregcomp(pool, regex, 0);
    if (!regex_compiled) {
        return NULL;
    }

    rv = ap_regexec(regex_compiled, string, AP_MAX_REG_MATCH, regex_match, 0);
    if (0 != rv) {
        return NULL;
    }

    return ap_pregsub(pool, apr_psprintf(pool, "$1%s$2", value),
string, AP_MAX_REG_MATCH, regex_match);
}

But it gives me
 '    'marko' as TABLE_TYPE\r'

(marko is value argument)

What i am doing wrong?
Thanks.

-- 
С уважением, Кевац Марко
Sincerely yours, Kevac Marko
Mime
View raw message