388 for ( TInt i( KThirdIndex ); i < len; i++ ) |
388 for ( TInt i( KThirdIndex ); i < len; i++ ) |
389 { |
389 { |
390 aText[i + aDocPos] = CSmileyManager::KPlaceHolder; |
390 aText[i + aDocPos] = CSmileyManager::KPlaceHolder; |
391 } |
391 } |
392 } |
392 } |
|
393 |
|
394 |
|
395 ///////////////////////////////////////////////////////////////////////////////////////// |
|
396 |
|
397 const char KStartSymbol[] = {'(', '<', '[', '{'}; |
|
398 const char KEndSymbol[] = {')', '>', ']', '}'}; |
|
399 |
|
400 TInt IndexFrom(const char* const aPtr, TInt aLength, TInt aChar) |
|
401 { |
|
402 for(TInt i=0; i<aLength; i++) |
|
403 { |
|
404 if(aPtr[i] == aChar) return i; |
|
405 } |
|
406 |
|
407 return KErrNotFound; |
|
408 } |
|
409 |
|
410 TBool HavePairedSymbol(const TDesC& aText, TInt aSmileyLength) |
|
411 { |
|
412 char stack[5]; |
|
413 TInt pos = 0; |
|
414 |
|
415 TInt i = aText.Length() - 1; |
|
416 const TInt smileyPos = aText.Length() - aSmileyLength; |
|
417 |
|
418 for(TInt i=aText.Length()-1; i>=0; i--) |
|
419 { |
|
420 TInt index = IndexFrom(KEndSymbol, sizeof(KEndSymbol), aText[i]); // detect end symbol |
|
421 if(KErrNotFound != index) // push |
|
422 { |
|
423 stack[pos++] = KStartSymbol[index]; |
|
424 } |
|
425 else if(pos) // detect start symbol |
|
426 { |
|
427 if(stack[pos-1] == aText[i]) // meet a start symbol |
|
428 { |
|
429 pos--; |
|
430 if(!pos) return (smileyPos > i); |
|
431 } |
|
432 } |
|
433 |
|
434 if(smileyPos == i) // smiley combination finished |
|
435 { |
|
436 if(!pos) return EFalse; |
|
437 } |
|
438 } |
|
439 |
|
440 return EFalse; |
|
441 } |
|
442 |
|
443 TBool IsPartOfUrl(const TDesC& aText) |
|
444 { |
|
445 const TInt end = aText.Length() - 1; |
|
446 TInt pos = end; |
|
447 while(pos > 0) |
|
448 { |
|
449 const TUint16 word = aText[--pos]; |
|
450 if(word == ' ' || word == 0x2029) |
|
451 { |
|
452 break; |
|
453 } |
|
454 } |
|
455 |
|
456 TInt length = end - pos; |
|
457 if(length > 5) |
|
458 { |
|
459 TPtrC field(aText.Mid(pos,length)); |
|
460 pos = field.Find(_L(":\\\\")); |
|
461 if(KErrNotFound == pos) pos = field.Find(_L("://")); |
|
462 if(KErrNotFound != pos) |
|
463 { |
|
464 return ETrue; |
|
465 } |
|
466 } |
|
467 |
|
468 return EFalse; |
|
469 } |
|
470 |
|
471 TBool CSmileyModel::IsSmileyBySemanticAnalysis(const TDesC& aText, TInt aSmileyLength) |
|
472 { |
|
473 if(HavePairedSymbol(aText, aSmileyLength)) return EFalse; |
|
474 |
|
475 if(IsPartOfUrl(aText)) return EFalse; |
|
476 |
|
477 return ETrue; |
|
478 } |