source: dev/trunk/ab5.0/abdev/abdev/reg_exp.cpp

Last change on this file was 829, checked in by イグトランス (egtra), 11 years ago

svn:eol-styleとsvn:mime-type(文字コード指定含む)の設定

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/plain; charset=Shift_JIS
File size: 2.6 KB
Line 
1#include "stdafx.h"
2
3#include "common.h"
4
5using namespace ActiveBasic::IDE;
6
7CRegExp obj_RegExp;
8
9CRegExp::CRegExp()
10{
11    const std::string bregexpDllPath = ActiveBasic::Common::Environment::GetAbdevSystemDirPath() + "\\BREGEXP.dll";
12    hLib = LoadLibrary( bregexpDllPath.c_str() );
13    if( !hLib )
14    {
15        MessageBox( NULL, "BREGEXP.dll が見つかりません。", "エラー", MB_OK | MB_ICONEXCLAMATION );
16    }
17
18    BMatch=(PFUNC_BMatch)GetProcAddress(hLib,"BMatch");
19    BSubst=(PFUNC_BSubst)GetProcAddress(hLib,"BSubst");
20    BTrans=(PFUNC_BTrans)GetProcAddress(hLib,"BTrans");
21    BSplit=(PFUNC_BSplit)GetProcAddress(hLib,"BSplit");
22    BRegfree=(PFUNC_BRegfree)GetProcAddress(hLib,"BRegfree");
23    BRegexpVersion=(PFUNC_BRegexpVersion)GetProcAddress(hLib,"BRegexpVersion");
24}
25CRegExp::~CRegExp(){
26    FreeLibrary(hLib);
27}
28
29char *CRegExp::compare(HWND hFindDlg,char *buffer,char *exp,BOOL IsBigSmall, bool isWordUnit ,int *pLength){
30    BREGEXP *rxp=0;
31    char msg[255];
32
33    char *pTemp;
34    pTemp=(char *)HeapAlloc(hHeap,0,lstrlen(exp)+255);
35    if(strstr(exp,"/")){
36        if(strstr(exp,"#")){
37            sprintf(pTemp,"m@(%s)@",exp);
38        }
39        else sprintf(pTemp,"m#(%s)#",exp);
40    }
41    else sprintf(pTemp,"m/(%s)/",exp);
42
43    //Shift-JIS?
44    lstrcat(pTemp,"k");
45
46    //?E
47    if(!IsBigSmall) lstrcat(pTemp,"i");
48
49    int result;
50    result=BMatch(pTemp,buffer,buffer+lstrlen(buffer),&rxp,msg);
51
52    HeapDefaultFree(pTemp);
53
54    if(!result){
55        if(rxp) BRegfree(rxp);
56        return 0;
57    }
58    else if(result==-1){
59        if(rxp) BRegfree(rxp);
60        MessageBox(hFindDlg,msg,APPLICATION_NAME,MB_OK|MB_ICONEXCLAMATION);
61        return (char *)-1;
62    }
63
64    *pLength=(rxp->outendp) - (rxp->outp);
65    if((*pLength)==0) return 0;
66
67    pTemp=ComparisonString(buffer,(char *)rxp->outp,false, isWordUnit);
68
69    if(rxp) BRegfree(rxp);
70
71    return pTemp;
72}
73char *CRegExp::GetPermuStr(HWND hFindDlg,char *buffer,char *exp,char *szPermu,BOOL IsBigSmall){
74    BREGEXP *rxp=0;
75    char msg[255];
76
77    char *pTemp;
78    pTemp=(char *)HeapAlloc(hHeap,0,lstrlen(exp)+255);
79    if(strstr(exp,"/")||strstr(szPermu,"/")){
80        if(strstr(exp,"#")||strstr(szPermu,"#")){
81            sprintf(pTemp,"s@%s@%s@",exp,szPermu);
82        }
83        else sprintf(pTemp,"s#%s#%s#",exp,szPermu);
84    }
85    else sprintf(pTemp,"s/%s/%s/",exp,szPermu);
86
87    //Shift-JIS?
88    lstrcat(pTemp,"k");
89
90    //?E
91    if(!IsBigSmall) lstrcat(pTemp,"i");
92
93    int result;
94    result=BSubst(pTemp,buffer,buffer+lstrlen(buffer),&rxp,msg);
95
96    HeapDefaultFree(pTemp);
97
98    if(!result){
99        if(rxp) BRegfree(rxp);
100        return 0;
101    }
102    else if(result==-1){
103        if(rxp) BRegfree(rxp);
104        MessageBox(hFindDlg,msg,APPLICATION_NAME,MB_OK|MB_ICONEXCLAMATION);
105        return (char *)-1;
106    }
107
108    int length;
109    length=(rxp->outendp) - (rxp->outp);
110
111    pTemp=(char *)HeapAlloc(hHeap,0,length+1);
112    memcpy(pTemp,rxp->outp,length);
113    pTemp[length]=0;
114
115    if(rxp) BRegfree(rxp);
116
117    return pTemp;
118}
Note: See TracBrowser for help on using the repository browser.