Cleanup: Pass by const reference in fpdftext.
authorLei Zhang <thestig@google.com>
Thu, 18 Dec 2014 00:54:04 +0000 (16:54 -0800)
committerLei Zhang <thestig@google.com>
Thu, 18 Dec 2014 00:54:04 +0000 (16:54 -0800)
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/790213005

core/include/fpdftext/fpdf_text.h
core/src/fpdftext/fpdf_text_int.cpp
core/src/fpdftext/text_int.h

index 2a5e4ac..3900806 100644 (file)
@@ -105,9 +105,9 @@ public:
 
     virtual    int                             GetOrderByDirection(int index, int direction) const = 0;
 
-    virtual CFX_WideString     GetTextByRect(CFX_FloatRect rect) const = 0;
+    virtual CFX_WideString     GetTextByRect(const CFX_FloatRect& rect) const = 0;
 
-    virtual void                       GetRectsArrayByRect(CFX_FloatRect rect, CFX_RectArray& resRectArray) const = 0;
+    virtual void                       GetRectsArrayByRect(const CFX_FloatRect& rect, CFX_RectArray& resRectArray) const = 0;
 
 
     virtual int                                CountRects(int start, int nCount) = 0;
@@ -116,7 +116,7 @@ public:
 
     virtual FX_BOOL                    GetBaselineRotate(int rectIndex, int& Rotate) = 0;
 
-    virtual FX_BOOL                    GetBaselineRotate(CFX_FloatRect rect, int& Rotate) = 0;
+    virtual FX_BOOL                    GetBaselineRotate(const CFX_FloatRect& rect, int& Rotate) = 0;
 
     virtual    int                             CountBoundedSegments(FX_FLOAT left, FX_FLOAT top, FX_FLOAT right, FX_FLOAT bottom, FX_BOOL bContains = FALSE) = 0;
 
@@ -139,7 +139,7 @@ public:
     static     IPDF_TextPageFind*      CreatePageFind(const IPDF_TextPage* pTextPage);
 public:
 
-    virtual    FX_BOOL                         FindFirst(CFX_WideString findwhat, int flags, int startPos = 0) = 0;
+    virtual    FX_BOOL                         FindFirst(const CFX_WideString& findwhat, int flags, int startPos = 0) = 0;
 
     virtual    FX_BOOL                         FindNext() = 0;
 
index 7526abc..dea5722 100644 (file)
@@ -348,7 +348,7 @@ int CPDF_TextPage::GetIndexAtPos(CPDF_Point point , FX_FLOAT xTorelance, FX_FLOA
     }
     return pos;
 }
-CFX_WideString CPDF_TextPage::GetTextByRect(CFX_FloatRect rect) const
+CFX_WideString CPDF_TextPage::GetTextByRect(const CFX_FloatRect& rect) const
 {
     CFX_WideString strText;
     if(m_ParseOptions.m_bGetCharCodeOnly || !m_IsParsered) {
@@ -386,7 +386,7 @@ CFX_WideString CPDF_TextPage::GetTextByRect(CFX_FloatRect rect) const
     }
     return strText;
 }
-void CPDF_TextPage::GetRectsArrayByRect(CFX_FloatRect rect, CFX_RectArray& resRectArray) const
+void CPDF_TextPage::GetRectsArrayByRect(const CFX_FloatRect& rect, CFX_RectArray& resRectArray) const
 {
     if(m_ParseOptions.m_bGetCharCodeOnly) {
         return;
@@ -759,7 +759,7 @@ FX_BOOL CPDF_TextPage::GetBaselineRotate(int start, int end, int& Rotate)
     }
     return TRUE;
 }
-FX_BOOL        CPDF_TextPage::GetBaselineRotate(CFX_FloatRect rect , int& Rotate)
+FX_BOOL        CPDF_TextPage::GetBaselineRotate(const CFX_FloatRect& rect , int& Rotate)
 {
     if(m_ParseOptions.m_bGetCharCodeOnly) {
         return FALSE;
@@ -1049,7 +1049,7 @@ void CPDF_TextPage::ProcessObject()
     m_LineObj.RemoveAll();
     CloseTempLine();
 }
-void CPDF_TextPage::ProcessFormObject(CPDF_FormObject* pFormObj, CFX_AffineMatrix formMatrix)
+void CPDF_TextPage::ProcessFormObject(CPDF_FormObject* pFormObj, const CFX_AffineMatrix& formMatrix)
 {
     CPDF_PageObject*   pPageObj = NULL;
     FX_POSITION        pos;
@@ -1325,7 +1325,7 @@ void CPDF_TextPage::CloseTempLine()
     m_TempTextBuf.Delete(0, m_TempTextBuf.GetLength());
     BidiChar->Release();
 }
-void CPDF_TextPage::ProcessTextObject(CPDF_TextObject* pTextObj, CFX_AffineMatrix formMatrix, FX_POSITION ObjPos)
+void CPDF_TextPage::ProcessTextObject(CPDF_TextObject* pTextObj, const CFX_AffineMatrix& formMatrix, FX_POSITION ObjPos)
 {
     CFX_FloatRect re(pTextObj->m_Left, pTextObj->m_Bottom, pTextObj->m_Right, pTextObj->m_Top);
     if(FXSYS_fabs(pTextObj->m_Right - pTextObj->m_Left) < 0.01f ) {
@@ -1952,7 +1952,7 @@ FX_BOOL CPDF_TextPage::IsHyphen(FX_WCHAR curChar)
     }
     return FALSE;
 }
-int CPDF_TextPage::ProcessInsertObject(const CPDF_TextObject* pObj, CFX_AffineMatrix formMatrix)
+int CPDF_TextPage::ProcessInsertObject(const CPDF_TextObject* pObj, const CFX_AffineMatrix& formMatrix)
 {
     FindPreviousTextObject();
     FX_BOOL bNewline = FALSE;
@@ -2198,13 +2198,11 @@ FX_BOOL CPDF_TextPage::GenerateCharInfo(FX_WCHAR unicode, PAGECHAR_INFO& info)
     info.m_CharBox = CFX_FloatRect(info.m_OriginX, info.m_OriginY, info.m_OriginX, info.m_OriginY);
     return TRUE;
 }
-FX_BOOL CPDF_TextPage::IsRectIntersect(CFX_FloatRect rect1, CFX_FloatRect rect2)
+FX_BOOL CPDF_TextPage::IsRectIntersect(const CFX_FloatRect& rect1, const CFX_FloatRect& rect2)
 {
-    rect1.Intersect(rect2);
-    if(rect1.IsEmpty()) {
-        return FALSE;
-    }
-    return TRUE;
+    CFX_FloatRect rect = rect1;
+    rect.Intersect(rect2);
+    return !rect.IsEmpty();
 }
 FX_BOOL        CPDF_TextPage::IsLetter(FX_WCHAR unicode)
 {
@@ -2276,7 +2274,7 @@ int CPDF_TextPageFind::GetCharIndex(int index) const
     }
     return -1;
 }
-FX_BOOL        CPDF_TextPageFind::FindFirst(CFX_WideString findwhat, int flags, int startPos)
+FX_BOOL        CPDF_TextPageFind::FindFirst(const CFX_WideString& findwhat, int flags, int startPos)
 {
     if (!m_pTextPage) {
         return FALSE;
@@ -2284,16 +2282,17 @@ FX_BOOL CPDF_TextPageFind::FindFirst(CFX_WideString findwhat, int flags, int sta
     if (m_strText.IsEmpty() || m_bMatchCase != (flags & FPDFTEXT_MATCHCASE)) {
         m_strText = m_pTextPage->GetPageText();
     }
-    m_findWhat = findwhat;
+    CFX_WideString findwhatStr = findwhat;
+    m_findWhat = findwhatStr;
     m_flags = flags;
     m_bMatchCase = flags & FPDFTEXT_MATCHCASE;
     if (m_strText.IsEmpty()) {
         m_IsFind = FALSE;
         return TRUE;
     }
-    FX_STRSIZE len = findwhat.GetLength();
+    FX_STRSIZE len = findwhatStr.GetLength();
     if (!m_bMatchCase) {
-        findwhat.MakeLower();
+        findwhatStr.MakeLower();
         m_strText.MakeLower();
     }
     m_bMatchWholeWord = flags & FPDFTEXT_MATCHWHOLEWORD;
@@ -2306,15 +2305,15 @@ FX_BOOL CPDF_TextPageFind::FindFirst(CFX_WideString findwhat, int flags, int sta
     m_csFindWhatArray.RemoveAll();
     int i = 0;
     while(i < len) {
-        if(findwhat.GetAt(i) != ' ') {
+        if(findwhatStr.GetAt(i) != ' ') {
             break;
         }
         i++;
     }
     if(i < len) {
-        ExtractFindWhat(findwhat);
+        ExtractFindWhat(findwhatStr);
     } else {
-        m_csFindWhatArray.Add(findwhat);
+        m_csFindWhatArray.Add(findwhatStr);
     }
     if(m_csFindWhatArray.GetSize() <= 0) {
         return FALSE;
@@ -2472,7 +2471,7 @@ FX_BOOL CPDF_TextPageFind::FindPrev()
     }
     return m_IsFind;
 }
-void CPDF_TextPageFind::ExtractFindWhat(CFX_WideString findwhat)
+void CPDF_TextPageFind::ExtractFindWhat(const CFX_WideString& findwhat)
 {
     if(findwhat.IsEmpty()) {
         return ;
@@ -2525,7 +2524,7 @@ void CPDF_TextPageFind::ExtractFindWhat(CFX_WideString findwhat)
     }
     return;
 }
-FX_BOOL CPDF_TextPageFind::IsMatchWholeWord(CFX_WideString csPageText, int startPos, int endPos)
+FX_BOOL CPDF_TextPageFind::IsMatchWholeWord(const CFX_WideString& csPageText, int startPos, int endPos)
 {
     int char_left = 0;
     int char_right = 0;
@@ -2585,7 +2584,7 @@ FX_BOOL CPDF_TextPageFind::ExtractSubString(CFX_WideString& rString, FX_LPCWSTR
     rString.ReleaseBuffer();
     return TRUE;
 }
-CFX_WideString CPDF_TextPageFind::MakeReverse(const CFX_WideString str)
+CFX_WideString CPDF_TextPageFind::MakeReverse(const CFX_WideString& str)
 {
     CFX_WideString str2;
     str2.Empty();
@@ -2788,7 +2787,7 @@ FX_BOOL CPDF_LinkExtract::CheckMailLink(CFX_WideString& str)
     }
     return TRUE;
 }
-FX_BOOL CPDF_LinkExtract::AppendToLinkList(int start, int count, CFX_WideString strUrl)
+FX_BOOL CPDF_LinkExtract::AppendToLinkList(int start, int count, const CFX_WideString& strUrl)
 {
     CPDF_LinkExt* linkInfo = NULL;
     linkInfo = FX_NEW CPDF_LinkExt;
index 39dc721..65ffdde 100644 (file)
@@ -71,8 +71,8 @@ public:
     virtual int                                                GetIndexAtPos(CPDF_Point point, FX_FLOAT xTorelance, FX_FLOAT yTorelance) const;
     virtual int                                                GetIndexAtPos(FX_FLOAT x, FX_FLOAT y, FX_FLOAT xTorelance,
             FX_FLOAT yTorelance) const;
-    virtual CFX_WideString                     GetTextByRect(CFX_FloatRect rect) const;
-    virtual void                                       GetRectsArrayByRect(CFX_FloatRect rect, CFX_RectArray& resRectArray) const;
+    virtual CFX_WideString                     GetTextByRect(const CFX_FloatRect& rect) const;
+    virtual void                                       GetRectsArrayByRect(const CFX_FloatRect& rect, CFX_RectArray& resRectArray) const;
     virtual    int                                             GetOrderByDirection(int order, int direction) const;
     virtual    CFX_WideString                  GetPageText(int start = 0, int nCount = -1) const;
 
@@ -80,7 +80,7 @@ public:
     virtual    void                                    GetRect(int rectIndex, FX_FLOAT& left, FX_FLOAT& top
                                             , FX_FLOAT& right, FX_FLOAT &bottom) const;
     virtual FX_BOOL                                    GetBaselineRotate(int rectIndex, int& Rotate);
-    virtual FX_BOOL                                    GetBaselineRotate(CFX_FloatRect rect, int& Rotate);
+    virtual FX_BOOL                                    GetBaselineRotate(const CFX_FloatRect& rect, int& Rotate);
     virtual    int                                             CountBoundedSegments(FX_FLOAT left, FX_FLOAT top,
             FX_FLOAT right, FX_FLOAT bottom, FX_BOOL bContains = FALSE);
     virtual    void                                    GetBoundedSegment(int index, int& start, int& count) const;
@@ -90,17 +90,17 @@ public:
     {
         return &m_charList;
     }
-    static     FX_BOOL                                 IsRectIntersect(CFX_FloatRect rect1, CFX_FloatRect rect2);
+    static     FX_BOOL                                 IsRectIntersect(const CFX_FloatRect& rect1, const CFX_FloatRect& rect2);
     static     FX_BOOL                                 IsLetter(FX_WCHAR unicode);
 private:
     FX_BOOL                                                    IsHyphen(FX_WCHAR curChar);
     FX_BOOL                                                    IsControlChar(PAGECHAR_INFO* pCharInfo);
     FX_BOOL                                                    GetBaselineRotate(int start, int end, int& Rotate);
     void                                                       ProcessObject();
-    void                                                       ProcessFormObject(CPDF_FormObject*      pFormObj, CFX_AffineMatrix formMatrix);
+    void                                                       ProcessFormObject(CPDF_FormObject*      pFormObj, const CFX_AffineMatrix& formMatrix);
     void                                                       ProcessTextObject(PDFTEXT_Obj pObj);
-    void                                                       ProcessTextObject(CPDF_TextObject*      pTextObj, CFX_AffineMatrix formMatrix, FX_POSITION ObjPos);
-    int                                                                ProcessInsertObject(const CPDF_TextObject* pObj, CFX_AffineMatrix formMatrix);
+    void                                                       ProcessTextObject(CPDF_TextObject*      pTextObj, const CFX_AffineMatrix& formMatrix, FX_POSITION ObjPos);
+    int                                                                ProcessInsertObject(const CPDF_TextObject* pObj, const CFX_AffineMatrix& formMatrix);
     FX_BOOL                                                    GenerateCharInfo(FX_WCHAR unicode, PAGECHAR_INFO& info);
     FX_BOOL                                                    IsSameAsPreTextObject(CPDF_TextObject* pTextObj, FX_POSITION ObjPos);
     FX_BOOL                                                    IsSameTextObject(CPDF_TextObject* pTextObj1, CPDF_TextObject* pTextObj2);
@@ -141,7 +141,7 @@ public:
     CPDF_TextPageFind(const IPDF_TextPage* pTextPage);
     virtual                                                    ~CPDF_TextPageFind() {};
 public:
-    virtual    FX_BOOL                                 FindFirst(CFX_WideString findwhat, int flags, int startPos = 0);
+    virtual    FX_BOOL                                 FindFirst(const CFX_WideString& findwhat, int flags, int startPos = 0);
     virtual    FX_BOOL                                 FindNext();
     virtual    FX_BOOL                                 FindPrev();
 
@@ -149,12 +149,12 @@ public:
     virtual int                                                GetCurOrder() const;
     virtual int                                                GetMatchedCount()const;
 protected:
-    void                                                       ExtractFindWhat(CFX_WideString findwhat);
-    FX_BOOL                                                    IsMatchWholeWord(CFX_WideString csPageText, int startPos, int endPos);
+    void                                                       ExtractFindWhat(const CFX_WideString& findwhat);
+    FX_BOOL                                                    IsMatchWholeWord(const CFX_WideString& csPageText, int startPos, int endPos);
     FX_BOOL                                                    ExtractSubString(CFX_WideString& rString, FX_LPCWSTR lpszFullString,
             int iSubString, FX_WCHAR chSep);
-    CFX_WideString                                     MakeReverse(const CFX_WideString str);
-    int                                                                ReverseFind(CFX_WideString csPageText, CFX_WideString csWord, int nStartPos, int& WordLength);
+    CFX_WideString                                     MakeReverse(const CFX_WideString& str);
+    int                                                                ReverseFind(const CFX_WideString& csPageText, const CFX_WideString& csWord, int nStartPos, int& WordLength);
     int                                                                GetCharIndex(int index) const;
 private:
     CFX_WordArray                                      m_CharIndex;
@@ -202,7 +202,7 @@ protected:
     void                                                       DeleteLinkList();
     FX_BOOL                                                    CheckWebLink(CFX_WideString& strBeCheck);
     FX_BOOL                                                    CheckMailLink(CFX_WideString& str);
-    FX_BOOL                                                    AppendToLinkList(int start, int count, CFX_WideString strUrl);
+    FX_BOOL                                                    AppendToLinkList(int start, int count, const CFX_WideString& strUrl);
 private:
     LINK_InfoArray                                     m_LinkList;
     const CPDF_TextPage*                       m_pTextPage;