Does RegularExpression() work?

#1
I can't get a simple example to work. This code produces the result below it.
Code:
    LPBYTE pMatchStart, pMatchEnd;
    UINT uRegions = 0; // also tried 1 with the same result
    WCHAR szString[32] = L"Hello world";
    WCHAR pRegex[32] = L"ello";
    Printf(L"RegularExpression() = %d\r\n",
        RegularExpression(pRegex, (LPBYTE) szString, &pMatchStart, &pMatchEnd, &uRegions, 0, 1, 1));
    Printf(L"Data: %X %X %X %u\r\n", szString, pMatchStart, pMatchEnd, uRegions);
Code:
RegularExpression() = 0
Data: 1717C60 0 0 0
 
#5
Why are you trying to use this function instead of calling Oniguruma yourself (like you always have in the past)? The function format will definitely change from version to version.
In fact I am doing it myself (see below for my RegExp() which returns a pointer to a match and fills in a length parameter). But I had thought that you supplied RegularExpression() for the benefit of plugin authors.
Code:
#define INVALID_LPWSTR ((LPWSTR) (LONG_PTR) -1)
 
LPWSTR RegExp(LPWSTR pRegEx, LPWSTR pString, DWORD *pLen)
{
    OnigErrorInfo err_info;
 
    WCHAR *rv = NULL;
    OnigRegex regex;
    INT ec = onig_new(&regex, (UChar*) pRegEx, (UChar*) pRegEx + 2 * lstrlen(pRegEx),
        0, ONIG_ENCODING_UTF16_LE, g.pOnigSyntax, &err_info);
    if ( ec != ONIG_NORMAL )
    {
        OnigErrorMessage(ec);
        return INVALID_LPWSTR;
    }
 
    UChar *mstart = (UChar*) pString, *mend = (UChar*) pString + 2 * lstrlen(pString);
 
    OnigRegion *region = onig_region_new();
 
    if ( onig_search(regex, mstart, mend, mstart, mend, region, 0) >= 0 )
    {
        *pLen = (region->end[0] - region->beg[0]) / sizeof(WCHAR);
        rv = pString + region->beg[0] / sizeof(WCHAR);
    }
    onig_region_free(region, 1);
    onig_free(regex);
    return rv;
}
 

rconn

Administrator
Staff member
May 14, 2008
10,495
94
#6
In fact I am doing it myself (see below for my RegExp() which returns a pointer to a match and fills in a length parameter). But I had thought that you supplied RegularExpression() for the benefit of plugin authors.
Functions in takecmd.dll are there for the benefit of tcmd.exe and tcc.exe. A few might also be useful to plugin authors, but for 90% of them I won't promise that they'll keep the same arguments (or name). The only ones you can rely on are the internal commands and the variable parsing.