Merge to XFA: Make CFX_WideString::LockBuffer() completely unused.
[pdfium.git] / core / src / fpdfdoc / doc_bookmark.cpp
index a3a1943..6ba98e6 100644 (file)
@@ -4,7 +4,11 @@
  
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
+#include <vector>
+
+#include "../../../third_party/base/nonstd_unique_ptr.h"
 #include "../../include/fpdfdoc/fpdf_doc.h"
+
 CPDF_Bookmark CPDF_BookmarkTree::GetFirstChild(const CPDF_Bookmark& parent) const
 {
     if (!parent.m_pDict) {
@@ -55,33 +59,37 @@ CFX_WideString CPDF_Bookmark::GetTitle() const
         return CFX_WideString();
     }
     CFX_WideString title = pString->GetUnicodeText();
-    FX_LPWSTR buf = title.LockBuffer();
     int len = title.GetLength();
+    if (!len) {
+        return CFX_WideString();
+    }
+    nonstd::unique_ptr<std::vector<FX_WCHAR> > vec;
+    vec.reset(new std::vector<FX_WCHAR>(len));
+    FX_WCHAR* buf = &vec->front();
     for (int i = 0; i < len; i++) {
-        if (buf[i] < 0x20) {
-            buf[i] = 0x20;
-        }
+        FX_WCHAR w = title[i];
+        buf[i] = w > 0x20 ? w : 0x20;
     }
-    title.ReleaseBuffer(len);
-    return title;
+    return CFX_WideString(buf, len);
 }
 CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const
 {
     if (!m_pDict) {
-        return NULL;
+        return CPDF_Dest();
     }
     CPDF_Object* pDest = m_pDict->GetElementValue("Dest");
     if (!pDest) {
-        return NULL;
+        return CPDF_Dest();
     }
     if (pDest->GetType() == PDFOBJ_STRING || pDest->GetType() == PDFOBJ_NAME) {
         CPDF_NameTree name_tree(pDocument, FX_BSTRC("Dests"));
         CFX_ByteStringC name = pDest->GetString();
-        return name_tree.LookupNamedDest(pDocument, name);
-    } else if (pDest->GetType() == PDFOBJ_ARRAY) {
-        return (CPDF_Array*)pDest;
+        return CPDF_Dest(name_tree.LookupNamedDest(pDocument, name));
+    }
+    if (pDest->GetType() == PDFOBJ_ARRAY) {
+        return CPDF_Dest((CPDF_Array*)pDest);
     }
-    return NULL;
+    return CPDF_Dest();
 }
 CPDF_Action CPDF_Bookmark::GetAction() const
 {