[475] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[3] | 3 | #include "common.h"
|
---|
| 4 |
|
---|
[475] | 5 | using namespace ActiveBasic::IDE;
|
---|
| 6 |
|
---|
[3] | 7 | CRegExp obj_RegExp;
|
---|
| 8 |
|
---|
[475] | 9 | CRegExp::CRegExp()
|
---|
| 10 | {
|
---|
| 11 | const std::string bregexpDllPath = Program::GetApplicationSystemDirPath() + "\\system\\BREGEXP.dll";
|
---|
| 12 | hLib = LoadLibrary( bregexpDllPath.c_str() );
|
---|
[3] | 13 |
|
---|
| 14 | BMatch=(PFUNC_BMatch)GetProcAddress(hLib,"BMatch");
|
---|
| 15 | BSubst=(PFUNC_BSubst)GetProcAddress(hLib,"BSubst");
|
---|
| 16 | BTrans=(PFUNC_BTrans)GetProcAddress(hLib,"BTrans");
|
---|
| 17 | BSplit=(PFUNC_BSplit)GetProcAddress(hLib,"BSplit");
|
---|
| 18 | BRegfree=(PFUNC_BRegfree)GetProcAddress(hLib,"BRegfree");
|
---|
| 19 | BRegexpVersion=(PFUNC_BRegexpVersion)GetProcAddress(hLib,"BRegexpVersion");
|
---|
| 20 | }
|
---|
| 21 | CRegExp::~CRegExp(){
|
---|
| 22 | FreeLibrary(hLib);
|
---|
| 23 | }
|
---|
| 24 |
|
---|
[80] | 25 | char *CRegExp::compare(HWND hFindDlg,char *buffer,char *exp,BOOL IsBigSmall, bool isWordUnit ,int *pLength){
|
---|
[3] | 26 | BREGEXP *rxp=0;
|
---|
| 27 | char msg[255];
|
---|
| 28 |
|
---|
| 29 | char *pTemp;
|
---|
| 30 | pTemp=(char *)HeapAlloc(hHeap,0,lstrlen(exp)+255);
|
---|
| 31 | if(strstr(exp,"/")){
|
---|
| 32 | if(strstr(exp,"#")){
|
---|
| 33 | sprintf(pTemp,"m@(%s)@",exp);
|
---|
| 34 | }
|
---|
| 35 | else sprintf(pTemp,"m#(%s)#",exp);
|
---|
| 36 | }
|
---|
| 37 | else sprintf(pTemp,"m/(%s)/",exp);
|
---|
| 38 |
|
---|
[475] | 39 | //Shift-JISナ表
|
---|
[3] | 40 | lstrcat(pTemp,"k");
|
---|
| 41 |
|
---|
[475] | 42 | //蝠カE
|
---|
[3] | 43 | if(!IsBigSmall) lstrcat(pTemp,"i");
|
---|
| 44 |
|
---|
| 45 | int result;
|
---|
| 46 | result=BMatch(pTemp,buffer,buffer+lstrlen(buffer),&rxp,msg);
|
---|
| 47 |
|
---|
| 48 | HeapDefaultFree(pTemp);
|
---|
| 49 |
|
---|
| 50 | if(!result){
|
---|
| 51 | if(rxp) BRegfree(rxp);
|
---|
| 52 | return 0;
|
---|
| 53 | }
|
---|
| 54 | else if(result==-1){
|
---|
| 55 | if(rxp) BRegfree(rxp);
|
---|
| 56 | MessageBox(hFindDlg,msg,APPLICATION_NAME,MB_OK|MB_ICONEXCLAMATION);
|
---|
| 57 | return (char *)-1;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | *pLength=(rxp->outendp) - (rxp->outp);
|
---|
| 61 | if((*pLength)==0) return 0;
|
---|
| 62 |
|
---|
[80] | 63 | pTemp=ComparisonString(buffer,(char *)rxp->outp,false, isWordUnit);
|
---|
[3] | 64 |
|
---|
| 65 | if(rxp) BRegfree(rxp);
|
---|
| 66 |
|
---|
| 67 | return pTemp;
|
---|
| 68 | }
|
---|
| 69 | char *CRegExp::GetPermuStr(HWND hFindDlg,char *buffer,char *exp,char *szPermu,BOOL IsBigSmall){
|
---|
| 70 | BREGEXP *rxp=0;
|
---|
| 71 | char msg[255];
|
---|
| 72 |
|
---|
| 73 | char *pTemp;
|
---|
| 74 | pTemp=(char *)HeapAlloc(hHeap,0,lstrlen(exp)+255);
|
---|
| 75 | if(strstr(exp,"/")||strstr(szPermu,"/")){
|
---|
| 76 | if(strstr(exp,"#")||strstr(szPermu,"#")){
|
---|
| 77 | sprintf(pTemp,"s@%s@%s@",exp,szPermu);
|
---|
| 78 | }
|
---|
| 79 | else sprintf(pTemp,"s#%s#%s#",exp,szPermu);
|
---|
| 80 | }
|
---|
| 81 | else sprintf(pTemp,"s/%s/%s/",exp,szPermu);
|
---|
| 82 |
|
---|
[475] | 83 | //Shift-JISナ表
|
---|
[3] | 84 | lstrcat(pTemp,"k");
|
---|
| 85 |
|
---|
[475] | 86 | //蝠カE
|
---|
[3] | 87 | if(!IsBigSmall) lstrcat(pTemp,"i");
|
---|
| 88 |
|
---|
| 89 | int result;
|
---|
| 90 | result=BSubst(pTemp,buffer,buffer+lstrlen(buffer),&rxp,msg);
|
---|
| 91 |
|
---|
| 92 | HeapDefaultFree(pTemp);
|
---|
| 93 |
|
---|
| 94 | if(!result){
|
---|
| 95 | if(rxp) BRegfree(rxp);
|
---|
| 96 | return 0;
|
---|
| 97 | }
|
---|
| 98 | else if(result==-1){
|
---|
| 99 | if(rxp) BRegfree(rxp);
|
---|
| 100 | MessageBox(hFindDlg,msg,APPLICATION_NAME,MB_OK|MB_ICONEXCLAMATION);
|
---|
| 101 | return (char *)-1;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | int length;
|
---|
| 105 | length=(rxp->outendp) - (rxp->outp);
|
---|
| 106 |
|
---|
| 107 | pTemp=(char *)HeapAlloc(hHeap,0,length+1);
|
---|
| 108 | memcpy(pTemp,rxp->outp,length);
|
---|
| 109 | pTemp[length]=0;
|
---|
| 110 |
|
---|
| 111 | if(rxp) BRegfree(rxp);
|
---|
| 112 |
|
---|
| 113 | return pTemp;
|
---|
| 114 | }
|
---|