uifw/EikStd/coctlsrc/smileymodel.cpp
branchRCL_3
changeset 38 c52421ed5f07
parent 0 2f259fa3e83a
child 51 fcdfafb36fe7
--- a/uifw/EikStd/coctlsrc/smileymodel.cpp	Wed Jun 09 09:58:37 2010 +0300
+++ b/uifw/EikStd/coctlsrc/smileymodel.cpp	Mon Jun 21 15:57:43 2010 +0300
@@ -390,3 +390,89 @@
         aText[i + aDocPos] = CSmileyManager::KPlaceHolder;
         }
     }
+
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+const char KStartSymbol[] = {'(', '<', '[', '{'};
+const char KEndSymbol[] = {')', '>', ']', '}'};
+
+TInt IndexFrom(const char* const aPtr, TInt aLength, TInt aChar)
+    {
+    for(TInt i=0; i<aLength; i++)
+        {
+        if(aPtr[i] == aChar) return i;
+        }
+
+    return KErrNotFound;
+    }
+
+TBool HavePairedSymbol(const TDesC& aText, TInt aSmileyLength)
+    {
+    char stack[5];
+    TInt pos = 0;
+    
+    TInt i = aText.Length() - 1;
+    const TInt smileyPos = aText.Length() - aSmileyLength;
+
+    for(TInt i=aText.Length()-1; i>=0; i--)
+        {
+        TInt index = IndexFrom(KEndSymbol, sizeof(KEndSymbol), aText[i]); // detect end symbol
+        if(KErrNotFound != index) // push
+            {
+            stack[pos++] = KStartSymbol[index];
+            }
+        else if(pos) // detect start symbol
+            {
+            if(stack[pos-1] == aText[i]) // meet a start symbol
+                {
+                pos--;
+                if(!pos) return (smileyPos > i);
+                }
+            }
+
+        if(smileyPos == i) // smiley combination finished
+            {
+            if(!pos) return EFalse;
+            }
+        }
+
+    return EFalse;
+    }
+
+TBool IsPartOfUrl(const TDesC& aText)
+    {
+    const TInt end = aText.Length() - 1;
+    TInt pos = end;
+    while(pos > 0)
+        {
+        const TUint16 word = aText[--pos];
+        if(word == ' ' || word == 0x2029)
+            {
+            break;
+            }
+        }
+    
+    TInt length = end - pos;
+    if(length > 5)
+        {
+        TPtrC field(aText.Mid(pos,length));
+        pos = field.Find(_L(":\\\\"));
+        if(KErrNotFound == pos) pos = field.Find(_L("://"));
+        if(KErrNotFound != pos)
+            {
+            return ETrue;
+            }    
+        }
+    
+    return EFalse;
+    }
+
+TBool CSmileyModel::IsSmileyBySemanticAnalysis(const TDesC& aText, TInt aSmileyLength)
+    {
+    if(HavePairedSymbol(aText, aSmileyLength)) return EFalse;
+
+    if(IsPartOfUrl(aText)) return EFalse;
+
+    return ETrue;
+    }