[mapserver-commits] r10918 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Thu Jan 27 11:47:24 EST 2011


Author: assefa
Date: 2011-01-27 08:47:24 -0800 (Thu, 27 Jan 2011)
New Revision: 10918

Modified:
   trunk/mapserver/mapogcfiltercommon.c
Log:
Fix setting for case senitive PropertyIsLike (#3613)

Modified: trunk/mapserver/mapogcfiltercommon.c
===================================================================
--- trunk/mapserver/mapogcfiltercommon.c	2011-01-26 19:30:24 UTC (rev 10917)
+++ trunk/mapserver/mapogcfiltercommon.c	2011-01-27 16:47:24 UTC (rev 10918)
@@ -91,6 +91,111 @@
     return nStatus;
 }
 
+char *FLTGetIsLikeComparisonCommonExpression(FilterEncodingNode *psFilterNode)
+{
+    const size_t bufferSize = 1024;
+    char szBuffer[1024];
+    char szTmp[256];
+    char *pszValue = NULL;
+    
+    char *pszWild = NULL;
+    char *pszSingle = NULL;
+    char *pszEscape = NULL;
+    int  bCaseInsensitive = 0;
+
+    int nLength=0, i=0, iTmp=0;
+
+
+    if (!psFilterNode || !psFilterNode->pOther || !psFilterNode->psLeftNode ||
+        !psFilterNode->psRightNode || !psFilterNode->psRightNode->pszValue)
+      return NULL;
+
+    pszWild = ((FEPropertyIsLike *)psFilterNode->pOther)->pszWildCard;
+    pszSingle = ((FEPropertyIsLike *)psFilterNode->pOther)->pszSingleChar;
+    pszEscape = ((FEPropertyIsLike *)psFilterNode->pOther)->pszEscapeChar;
+    bCaseInsensitive = ((FEPropertyIsLike *)psFilterNode->pOther)->bCaseInsensitive;
+
+    if (!pszWild || strlen(pszWild) == 0 ||
+        !pszSingle || strlen(pszSingle) == 0 || 
+        !pszEscape || strlen(pszEscape) == 0)
+      return NULL;
+
+ 
+/* -------------------------------------------------------------------- */
+/*      Use operand with regular expressions.                           */
+/* -------------------------------------------------------------------- */
+    szBuffer[0] = '\0';
+    sprintf(szTmp, "%s", " (\"[");
+    szTmp[4] = '\0';
+
+    strlcat(szBuffer, szTmp, bufferSize);
+
+    /* attribute */
+    strlcat(szBuffer, psFilterNode->psLeftNode->pszValue, bufferSize);
+    szBuffer[strlen(szBuffer)] = '\0';
+
+    /*#3521 */
+    if(bCaseInsensitive == 1)
+      sprintf(szTmp, "%s", "]\" ~* \"");
+    else
+      sprintf(szTmp, "%s", "]\" ~ \"");
+    szTmp[7] = '\0';
+    strlcat(szBuffer, szTmp, bufferSize);
+    szBuffer[strlen(szBuffer)] = '\0';
+
+
+    pszValue = psFilterNode->psRightNode->pszValue;
+    nLength = strlen(pszValue);
+    
+    iTmp =0;
+    if (nLength > 0 && pszValue[0] != pszWild[0] && 
+        pszValue[0] != pszSingle[0] &&
+        pszValue[0] != pszEscape[0])
+    {
+      szTmp[iTmp]= '^';
+      iTmp++;
+    }
+    for (i=0; i<nLength; i++)
+    {
+        if (pszValue[i] != pszWild[0] && 
+            pszValue[i] != pszSingle[0] &&
+            pszValue[i] != pszEscape[0])
+        {
+            szTmp[iTmp] = pszValue[i];
+            iTmp++;
+            szTmp[iTmp] = '\0';
+        }
+        else if  (pszValue[i] == pszSingle[0])
+        {
+             szTmp[iTmp] = '.';
+             iTmp++;
+             szTmp[iTmp] = '\0';
+        }
+        else if  (pszValue[i] == pszEscape[0])
+        {
+            szTmp[iTmp] = '\\';
+            iTmp++;
+            szTmp[iTmp] = '\0';
+
+        }
+        else if (pszValue[i] == pszWild[0])
+        {
+            /* strcat(szBuffer, "[0-9,a-z,A-Z,\\s]*"); */
+            /* iBuffer+=17; */
+            szTmp[iTmp++] = '.';
+            szTmp[iTmp++] = '*';
+            szTmp[iTmp] = '\0';
+        }
+    }   
+    szTmp[iTmp] = '"';
+    szTmp[++iTmp] = '\0';
+    
+    strlcat(szBuffer, szTmp, bufferSize);
+    strlcat(szBuffer, ")", bufferSize);     
+    return msStrdup(szBuffer);
+}
+
+
 char *FLTGetIsBetweenComparisonCommonExpresssion(FilterEncodingNode *psFilterNode,
                                                  layerObj *lp)
 {
@@ -270,10 +375,10 @@
         if (psFilterNode->psRightNode->pOther && 
             (*(int *)psFilterNode->psRightNode->pOther) == 1)
         {
-          sprintf(szTmp,  "%s", "=="); /*TODO what should this be ??*/
+          sprintf(szTmp,  "%s", "=*"); 
         }
         else
-          sprintf(szTmp,  "%s", "==");
+          sprintf(szTmp,  "%s", "=");
     
     }
     else if (strcasecmp(psFilterNode->pszValue, 
@@ -293,7 +398,7 @@
       sprintf(szTmp,  "%s", " >= ");
     else if (strcasecmp(psFilterNode->pszValue, 
                         "PropertyIsLike") == 0)
-      sprintf(szTmp,  "%s", " ~* ");
+      sprintf(szTmp,  "%s", " ~ ");
     
     pszExpression = msStringConcatenate(pszExpression, szTmp);
 
@@ -575,9 +680,11 @@
     {
         if ( psFilterNode->psLeftNode && psFilterNode->psRightNode)
         {
-            if (FLTIsBinaryComparisonFilterType(psFilterNode->pszValue) ||
-                strcasecmp(psFilterNode->pszValue, "PropertyIsLike") == 0)
+            if (FLTIsBinaryComparisonFilterType(psFilterNode->pszValue))               
               pszExpression = FLTGetBinaryComparisonCommonExpression(psFilterNode, lp);
+            
+            else if (strcasecmp(psFilterNode->pszValue, "PropertyIsLike") == 0)
+              pszExpression = FLTGetIsLikeComparisonCommonExpression(psFilterNode, lp);
 
             else if (strcasecmp(psFilterNode->pszValue, "PropertyIsBetween") == 0)
               pszExpression = FLTGetIsBetweenComparisonCommonExpresssion(psFilterNode, lp);



More information about the mapserver-commits mailing list