Index: source/classes/sbxmod.cxx =================================================================== RCS file: /cvs/script/basic/source/classes/sbxmod.cxx,v retrieving revision 1.36 diff -u -r1.36 sbxmod.cxx --- source/classes/sbxmod.cxx 3 Nov 2006 15:10:25 -0000 1.36 +++ source/classes/sbxmod.cxx 31 Jan 2007 12:46:18 -0000 @@ -166,7 +166,8 @@ "integer", "is", "let", - "lib" + "lib", + "like", "line", "line input", "local", Index: source/comp/exprnode.cxx =================================================================== RCS file: /cvs/script/basic/source/comp/exprnode.cxx,v retrieving revision 1.16 diff -u -r1.16 exprnode.cxx --- source/comp/exprnode.cxx 12 Oct 2006 14:34:58 -0000 1.16 +++ source/comp/exprnode.cxx 31 Jan 2007 12:46:19 -0000 @@ -244,7 +244,7 @@ void SbiExprNode::FoldConstants() { - if( IsOperand() ) return; + if( IsOperand() || eTok == LIKE ) return; pLeft->FoldConstants(); if( pRight ) { Index: source/comp/token.cxx =================================================================== RCS file: /cvs/script/basic/source/comp/token.cxx,v retrieving revision 1.21 diff -u -r1.21 token.cxx --- source/comp/token.cxx 12 Oct 2006 14:28:11 -0000 1.21 +++ source/comp/token.cxx 31 Jan 2007 12:46:20 -0000 @@ -130,6 +130,7 @@ { IS, "Is" }, { LET, "Let" }, { LIB, "Lib" }, + { LIKE, "Like" }, { LINE, "Line" }, { LINEINPUT,"Line Input" }, { LOCAL, "Local" }, Index: source/runtime/step0.cxx =================================================================== RCS file: /cvs/script/basic/source/runtime/step0.cxx,v retrieving revision 1.27 diff -u -r1.27 step0.cxx --- source/runtime/step0.cxx 3 Nov 2006 07:03:10 -0000 1.27 +++ source/runtime/step0.cxx 31 Jan 2007 12:46:26 -0000 @@ -49,7 +49,11 @@ #include #include #include "sbunoobj.hxx" +#include "image.hxx" #include +#include +#include +#include #include @@ -166,9 +170,113 @@ void SbiRuntime::StepLE() { StepCompare( SbxLE ); } void SbiRuntime::StepGE() { StepCompare( SbxGE ); } +namespace +{ + bool NeedEsc(sal_Unicode cCode) + { + String sEsc(RTL_CONSTASCII_USTRINGPARAM(".^$+\\|{}()")); + return (STRING_NOTFOUND != sEsc.Search(cCode)); + } + + String VBALikeToRegexp(const String &rIn) + { + String sResult; + const sal_Unicode *start = rIn.GetBuffer(); + const sal_Unicode *end = start + rIn.Len(); + + int seenright = 0; + + sResult.Append('^'); + + while (start < end) + { + switch (*start) + { + case '?': + sResult.Append('.'); + start++; + break; + case '*': + sResult.Append(String(RTL_CONSTASCII_USTRINGPARAM(".*"))); + start++; + break; + case '#': + sResult.Append(String(RTL_CONSTASCII_USTRINGPARAM("[0-9]"))); + start++; + break; + case ']': + sResult.Append('\\'); + sResult.Append(*start++); + break; + case '[': + sResult.Append(*start++); + seenright = 0; + while (start < end && !seenright) + { + switch (*start) + { + case '[': + case '?': + case '*': + sResult.Append('\\'); + sResult.Append(*start); + break; + case ']': + sResult.Append(*start); + seenright = 1; + break; + default: + if (NeedEsc(*start)) + sResult.Append('\\'); + sResult.Append(*start); + break; + } + start++; + } + break; + default: + if (NeedEsc(*start)) + sResult.Append('\\'); + sResult.Append(*start++); + } + } + + sResult.Append('$'); + + return sResult; + } +} + void SbiRuntime::StepLIKE() { - StarBASIC::FatalError( SbERR_NOT_IMPLEMENTED ); + SbxVariableRef refVar1 = PopVar(); + SbxVariableRef refVar2 = PopVar(); + + String pattern = VBALikeToRegexp(refVar1->GetString()); + String value = refVar2->GetString(); + + com::sun::star::util::SearchOptions aSearchOpt; + + aSearchOpt.algorithmType = com::sun::star::util::SearchAlgorithms_REGEXP; + + aSearchOpt.Locale = Application::GetSettings().GetLocale(); + aSearchOpt.searchString = pattern; + + int bTextMode(1); + bool bCompatibility = ( pINST && pINST->IsCompatibility() ); + if( bCompatibility ) + bTextMode = GetImageFlag( SBIMG_COMPARETEXT ); + + if( bTextMode ) + aSearchOpt.transliterateFlags |= com::sun::star::i18n::TransliterationModules_IGNORE_CASE; + + SbxVariable* pRes = new SbxVariable; + utl::TextSearch aSearch(aSearchOpt); + xub_StrLen nStart=0, nEnd=value.Len(); + int bRes = aSearch.SearchFrwrd(value, &nStart, &nEnd); + pRes->PutBool( bRes ); + + PushVar( pRes ); } // TOS und TOS-1 sind beides Objektvariable und enthalten den selben Pointer