add patch
[framework/osp/uifw.git] / src / graphics / text / FGrp_TextTextCutLinkParser.cpp
index 3c3792a..a4b8ebb 100644 (file)
@@ -121,6 +121,7 @@ IsUrlAddress(const String& text, int index, int& linkLength)
        int linkOffset = 0;
        int totalLength = text.GetLength();
        int length = 0;
+       const wchar_t* pText = text.GetPointer();
 
        String prefix(L"");
        String subString(L"");
@@ -140,21 +141,20 @@ IsUrlAddress(const String& text, int index, int& linkLength)
                        }
 
                        r = text.SubString(index, length, subString);
-                       SysTryReturn(
-                               NID_GRP, r == E_SUCCESS, false, E_OUT_OF_RANGE,
+                       SysTryReturn(NID_GRP, r == E_SUCCESS, false, E_OUT_OF_RANGE,
                                "[E_OUT_OF_RANGE] SubString offset(%d) must greater than 0 and length(%d) must be less than total string length(%d).",
                                index, prefix.GetLength(), totalLength);
                        if (prefix.CompareTo(subString) == 0)
                        {
                                linkOffset = index;
-                               while (index < totalLength && IsGenericCharacter(text[index]))
+                               while (index < totalLength && IsGenericCharacter(pText[index]))
                                {
-                                       if (dotFound == false && text[index] == '.')
+                                       if (dotFound == false && pText[index] == '.')
                                        {
                                                dotFound = true;
                                        }
 
-                                       if (validTextAfterDot == false && dotFound == true && text[index] != '.')
+                                       if (validTextAfterDot == false && dotFound == true && pText[index] != '.')
                                        {
                                                validTextAfterDot = true;
                                        }
@@ -169,7 +169,7 @@ IsUrlAddress(const String& text, int index, int& linkLength)
 
                                if (dotFound == true)
                                {
-                                       while (text[index - 1] == L'.' || text[index - 1] == L',')
+                                       while (pText[index - 1] == L'.' || pText[index - 1] == L',')
                                        {
                                                index--;
                                        }
@@ -194,26 +194,33 @@ GetUrlLink(const String& text, int index, int lastLinkEndIndex, int domainLength
        bool dotFound = false;
        bool validTextBeforeDot = false;
        int linkOffset = index;
+       const wchar_t* pText = text.GetPointer();
 
        while (lastLinkEndIndex <= linkOffset)
        {
-               if (!IsGenericCharacter(text[linkOffset]) || text[linkOffset] == L'(' || text[linkOffset] == L'[')
+               if (!IsGenericCharacter(pText[linkOffset]) || pText[linkOffset] == L'(' || pText[linkOffset] == L'[')
                {
                        linkOffset++;
                        break;
                }
 
-               if (dotFound == false && text[linkOffset] == L'.')
+               if (dotFound == false && pText[linkOffset] == L'.')
                {
                        dotFound = true;
                }
 
-               if (validTextBeforeDot == false && dotFound == true && text[linkOffset] != L'.')
+               if (validTextBeforeDot == false && dotFound == true && pText[linkOffset] != L'.')
                {
                        validTextBeforeDot = true;
                }
 
                linkOffset--;
+
+               if (lastLinkEndIndex > linkOffset)
+               {
+                       linkOffset++;
+                       break;
+               }
        }
 
        if (dotFound == true && validTextBeforeDot != true)
@@ -223,18 +230,18 @@ GetUrlLink(const String& text, int index, int lastLinkEndIndex, int domainLength
 
        if (dotFound == true)
        {
-               while (text[linkOffset] == L'.' || text[linkOffset] == L',')
+               while (pText[linkOffset] == L'.' || pText[linkOffset] == L',')
                {
                        linkOffset++;
                }
        }
 
        index += domainLength;
-       if (text[index] == L'/')
+       if (pText[index] == L'/')
        {
                while (index > 0)
                {
-                       if (!IsGenericCharacter(text[index]) && text[index] != L')' && text[index] != L']')
+                       if (!IsGenericCharacter(pText[index]) && pText[index] != L')' && pText[index] != L']')
                        {
                                break;
                        }
@@ -242,9 +249,9 @@ GetUrlLink(const String& text, int index, int lastLinkEndIndex, int domainLength
                        index++;
                }
        }
-       else if (text[index] != null && text[index] != L' ' && text[index] != TEXT_JAPANESE_SPACE &&
-                       text[index] != L')' && text[index] != L']' && text[index] != 0xFFFC &&
-                       text[index] != 0x000A && text[index] != 0x000D)
+       else if (pText[index] != null && pText[index] != L' ' && pText[index] != TEXT_JAPANESE_SPACE &&
+                       pText[index] != L')' && pText[index] != L']' && pText[index] != 0xFFFC &&
+                       pText[index] != 0x000A && pText[index] != 0x000D)
        {
                return false;
        }
@@ -315,8 +322,9 @@ IsEmailAddress(const String& text, int index, int lastLinkEndIndex, int& linkSta
        int atIndex = 0;
        int totalLength = text.GetLength();
        int linkOffset = index;
+       const wchar_t* pText = text.GetPointer();
 
-       if (text[index + 1] == L'@')
+       if (pText[index + 1] == L'@')
        {
                return false;
        }
@@ -325,7 +333,7 @@ IsEmailAddress(const String& text, int index, int lastLinkEndIndex, int& linkSta
 
        if (index > lastLinkEndIndex)
        {
-               while (IsEmailCharacter(text[linkOffset]) && lastLinkEndIndex <= linkOffset)
+               while (IsEmailCharacter(pText[linkOffset]) && lastLinkEndIndex <= linkOffset)
                {
                        linkOffset--;
                }
@@ -339,16 +347,16 @@ IsEmailAddress(const String& text, int index, int lastLinkEndIndex, int& linkSta
 
                atIndex = index;
                index++;
-               while (IsEmailCharacter(text[index]) && index < totalLength)
+               while (IsEmailCharacter(pText[index]) && index < totalLength)
                {
                        if (validTextAfterAt == false)
                        {
                                validTextAfterAt = true;
                        }
 
-                       if (text[index] == '.')
+                       if (pText[index] == '.')
                        {
-                               if (text[index + 1] == '.')
+                               if (pText[index + 1] == '.')
                                {
                                        break;
                                }
@@ -367,7 +375,7 @@ IsEmailAddress(const String& text, int index, int lastLinkEndIndex, int& linkSta
                        return false;
                }
 
-               while (text[index - 1] == L'.')
+               while (pText[index - 1] == L'.')
                {
                        index--;
                }
@@ -392,12 +400,13 @@ IsPhoneNumber(const String& text, int index, int& linkLength)
        int oneDot = false;
        int linkOffset = 0;
        int blankCount = 0;
-
+       const wchar_t* pText = text.GetPointer();
        int totalLength = text.GetLength();
-       if (text[index] == L'+')
+
+       if (pText[index] == L'+')
        {
                k = 0;
-               if (!Character::IsDigit(text[index + 1]))
+               if (!Character::IsDigit(pText[index + 1]))
                {
                        return false;
                }
@@ -405,21 +414,21 @@ IsPhoneNumber(const String& text, int index, int& linkLength)
 
        while (k < _MIN_PHONE_NUMBER_LENGTH)
        {
-               if (Character::IsDigit(text[index + j]) || text[index + j] == L'*' || text[index + j] == L'#')
+               if (Character::IsDigit(pText[index + j]) || pText[index + j] == L'*' || pText[index + j] == L'#')
                {
                        k++;
                        oneHyphen = false;
                        oneDot = false;
                }
-               else if (oneHyphen == false && text[index + j] == L'-')
+               else if (oneHyphen == false && pText[index + j] == L'-')
                {
                        oneHyphen = true;
                }
-               else if (oneDot == false && text[index + j] == L'.')
+               else if (oneDot == false && pText[index + j] == L'.')
                {
                        oneDot = true;
                }
-               else if (text[index + j] == L' ' || text[index + j] == TEXT_JAPANESE_SPACE || text[index + j] == L'(' || text[index + j] == L')')
+               else if (pText[index + j] == L' ' || pText[index + j] == TEXT_JAPANESE_SPACE || pText[index + j] == L'(' || pText[index + j] == L')')
                {
                        // empty statement
                }
@@ -437,37 +446,37 @@ IsPhoneNumber(const String& text, int index, int& linkLength)
                linkOffset = index;
 
                while (index < totalLength &&
-                          (Character::IsDigit(text[index]) || (text[index] == L'*') ||
-                               (text[index] == L'#') || (text[index] == L'-') ||
-                               (text[index] == L' ') || (text[index] == TEXT_JAPANESE_SPACE) || (text[index] == L'+') ||
-                               (text[index] == L'.') || (text[index] == L'(') ||
-                               (text[index] == L')') || (index == linkOffset && (text[linkOffset] == L'+'))))
+                          (Character::IsDigit(pText[index]) || (pText[index] == L'*') ||
+                               (pText[index] == L'#') || (pText[index] == L'-') ||
+                               (pText[index] == L' ') || (pText[index] == TEXT_JAPANESE_SPACE) || (pText[index] == L'+') ||
+                               (pText[index] == L'.') || (pText[index] == L'(') ||
+                               (pText[index] == L')') || (index == linkOffset && (pText[linkOffset] == L'+'))))
                {
                        index++;
 
-                       if (blankCount == 0 && (text[index] == L' ' || text[index] == TEXT_JAPANESE_SPACE))
+                       if (blankCount == 0 && (pText[index] == L' ' || pText[index] == TEXT_JAPANESE_SPACE))
                        {
                                blankCount++;
                        }
-                       else if (blankCount == 1 && (text[index] == L' ' || text[index] == TEXT_JAPANESE_SPACE))
+                       else if (blankCount == 1 && (pText[index] == L' ' || pText[index] == TEXT_JAPANESE_SPACE))
                        {
                                blankCount++;
                                break;
                        }
-                       else if (Character::IsDigit(text[index]) || text[index] == L'*' || text[index] == L'#')
+                       else if (Character::IsDigit(pText[index]) || pText[index] == L'*' || pText[index] == L'#')
                        {
                                blankCount = 0;
                        }
-                       else if (text[index] == L'-' && text[index + 1] == L'-')
+                       else if (pText[index] == L'-' && pText[index + 1] == L'-')
                        {
                                break;
                        }
-                       else if (text[index] == L'(' || text[index] == L')')
+                       else if (pText[index] == L'(' || pText[index] == L')')
                        {
                                break;
                        }
-                       else if ((text[index] == L'.' &&
-                                         text[index + 1] == L'.') || (text[index] == L'.' && !Character::IsDigit(text[index + 1])))
+                       else if ((pText[index] == L'.' &&
+                                         pText[index + 1] == L'.') || (pText[index] == L'.' && !Character::IsDigit(pText[index + 1])))
                        {
                                break;
                        }
@@ -477,10 +486,10 @@ IsPhoneNumber(const String& text, int index, int& linkLength)
                        }
                }
 
-               if (text[index - 1] == L' ' || text[index - 1] == TEXT_JAPANESE_SPACE)
+               if (pText[index - 1] == L' ' || pText[index - 1] == TEXT_JAPANESE_SPACE)
                {
                        index -= 1;
-                       while (text[index] == L' ' || text[index] == TEXT_JAPANESE_SPACE)
+                       while (pText[index] == L' ' || pText[index] == TEXT_JAPANESE_SPACE)
                        {
                                index--;
                        }
@@ -505,13 +514,9 @@ TextCutLinkParser::TextCutLinkParser(void)
        if (!gpUrlPrefixes)
        {
                gpUrlPrefixes = new (std::nothrow) ArrayListT <String>;
-               SysTryCatch(NID_GRP
-                               , gpUrlPrefixes != null
-                               , r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+               SysTryCatch(NID_GRP, gpUrlPrefixes != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
                r = gpUrlPrefixes->Construct();
-               SysTryCatch(NID_GRP
-                               , r == E_SUCCESS
-                               , , r, "[%s] Propagated.", GetErrorMessage(r));
+               SysTryCatch(NID_GRP, r == E_SUCCESS, , r, "[%s] Propagated.", GetErrorMessage(r));
 
                gpUrlPrefixes->Add(L"www.");
                gpUrlPrefixes->Add(L"http://");
@@ -523,14 +528,10 @@ TextCutLinkParser::TextCutLinkParser(void)
        if (!gpDomainNames)
        {
                gpDomainNames = new (std::nothrow) ArrayListT <Tizen::Base::String>;
-               SysTryCatch(NID_GRP
-                               , gpDomainNames != null
-                               , r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+               SysTryCatch(NID_GRP, gpDomainNames != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
                r = gpDomainNames->Construct();
-               SysTryCatch(NID_GRP
-                               , r == E_SUCCESS
-                               , , r, "[%s] Propagated.", GetErrorMessage(r));
+               SysTryCatch(NID_GRP, r == E_SUCCESS, , r, "[%s] Propagated.", GetErrorMessage(r));
 
                gpDomainNames->Add(L".com");
                gpDomainNames->Add(L".net");
@@ -669,9 +670,7 @@ TextCutLinkParser::Parse(const wchar_t* pText, int textLength, int startPosition
        }
 
        pTextLink = CreateTextLinkInfo(0, 0, LINK_TYPE_NONE);
-       SysTryCatch(NID_GRP
-                       , pTextLink != null
-                       , , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+       SysTryCatch(NID_GRP, pTextLink != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
        pTextLink->index = -1;
 
@@ -729,9 +728,7 @@ TextCutLinkParser::Parse(const wchar_t* pText, int textLength, int startPosition
                        else
                        {
                                TextLinkInfo* pNextLink = CreateTextLinkInfo(linkStartIndex, linkLength, linkType);
-                               SysTryCatch(NID_GRP
-                                               , pNextLink != null,
-                                               r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient");
+                               SysTryCatch(NID_GRP, pNextLink != null,r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient");
                                AppendTextLinkInfo(pTextLink, pNextLink);
                        }
 
@@ -767,8 +764,7 @@ CATCH:
 result
 TextCutLinkParser::SetCutLinkMask(int mask)
 {
-       SysTryReturn(NID_GRP
-                       , LINK_TYPE_NONE <= mask && mask < LINK_TYPE_MAX
+       SysTryReturn(NID_GRP, LINK_TYPE_NONE <= mask && mask < LINK_TYPE_MAX
                        , E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument is invalid.");
 
        __linkMask = mask;
@@ -806,9 +802,7 @@ TextLinkInfo*
 TextCutLinkParser::CreateTextLinkInfo(int offset, int length, LinkType linkType)
 {
        TextLinkInfo* pTextLinkInfo = new (std::nothrow) TextLinkInfo;
-       SysTryReturn(NID_GRP
-                       , pTextLinkInfo != null
-                       , null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient");
+       SysTryReturn(NID_GRP, pTextLinkInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient");
 
        pTextLinkInfo->index = 0;
        pTextLinkInfo->srcOffset = offset;