Changeset 28bccd2 in tol


Ignore:
Timestamp:
May 5, 2011, 10:57:08 AM (15 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
e2cfb5f
Parents:
d6b52ea
Message:

Fixes #297
TextMatch calls to TextMatch _tcl if available and else sows a warning and use old BText::Match

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@3495 be4846ae-f051-483a-831f-b64e7d08527f

Location:
tol
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tol/btol/real_type/datgrav.cpp

    rd6b52ea r28bccd2  
    2525
    2626#include <tol/tol_bdatgra.h>
     27#include <tol/tol_init.h>
    2728#include <tol/tol_bout.h>
    2829#include <tol/tol_bdir.h>
    … …  
    20332034  DeclareContensClass(BDat, BDatTemporary, BDatMatchText);
    20342035  DefExtOpr(1, BDatMatchText, "TextMatch", 2, 3, "Text Text Real",
    2035   I2("(Text chain, Text pattern [, Real case = 0 ])",
     2036  I2("(Text string, Text pattern [, Real case = 0 ])",
    20362037     "(Text cadena, Text modelo [, Real modo = 0 ])"),
    20372038  I2(
    … …  
    20722073//--------------------------------------------------------------------
    20732074{
     2075  BText& string  = Text(Arg(1));
     2076  BText& pattern = Text(Arg(2));
    20742077  BInt mode = 0;
    20752078  if(Arg(3)) { mode = (BInt)Real(Arg(3)); }
    2076   contens_ = (BReal)(Text(Arg(1)).Match(Text(Arg(2)), mode));
     2079  if(TolTclIsEnabled())
     2080  {
     2081    BText expr = BText("TextMatch_Tcl(\"")+string+"\",\""+pattern+"\","+mode+")";
     2082    BSyntaxObject* uMatch = GraReal()->EvaluateExpr(expr);
     2083    if(uMatch)
     2084    {
     2085      contens_ = Real(uMatch)!=0;
     2086      DESTROY(uMatch);
     2087    }
     2088  }
     2089  else
     2090  {
     2091    Warning("Using internal version of TextMatch could cause invalid results. "
     2092    "Please use a TCL version of TOL like tolsh or tolbase.");
     2093    contens_ = (BReal)(string.Match(pattern, mode));
     2094  }
    20772095}
    20782096
  • tol/stdlib/general/grammars/_text.tol

    rd6b52ea r28bccd2  
    12481248  WriteFile(filePath, Replace(contens, old, new))
    12491249};
     1250
     1251//////////////////////////////////////////////////////////////////////////////
     1252Real TextMatch_Tcl(Text text, Text pattern, Real case)
     1253//////////////////////////////////////////////////////////////////////////////
     1254{
     1255  Text text.tcl = "{"<<Replace(Replace(Replace(text, "\\", "\\\\"),
     1256    "{",  "\\{"), "}",  "\\}") << "}";
     1257  Text pattern.tcl = "{"<<Replace(Replace(Replace(pattern, "\\", "\\\\"),
     1258    "{",  "\\{"), "}",  "\\}") << "}";
     1259  Text caseText = If(case, "", "-nocase ");
     1260  Eval(Tcl_Eval("string match "<<caseText<<pattern.tcl<<" "<<text.tcl)[1])
     1261};
Note: See TracChangeset for help on using the changeset viewer.