OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "pdf/pdfium/pdfium_api_string_buffer_adapter.h" | 5 #include "pdf/pdfium/pdfium_api_string_buffer_adapter.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/numerics/safe_math.h" | 10 #include "base/numerics/safe_math.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 DCHECK_EQ(expected_size_, actual_size); | 51 DCHECK_EQ(expected_size_, actual_size); |
52 | 52 |
53 if (actual_size > 0) { | 53 if (actual_size > 0) { |
54 DCHECK((*str_)[actual_size - 1] == 0); | 54 DCHECK((*str_)[actual_size - 1] == 0); |
55 str_->resize(actual_size - 1); | 55 str_->resize(actual_size - 1); |
56 } else { | 56 } else { |
57 str_->clear(); | 57 str_->clear(); |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
| 61 template <class StringType> |
| 62 PDFiumAPIStringBufferSizeInBytesAdapter<StringType>:: |
| 63 PDFiumAPIStringBufferSizeInBytesAdapter(StringType* str, |
| 64 size_t expected_size, |
| 65 bool check_expected_size) |
| 66 : adapter_(str, |
| 67 expected_size / sizeof(typename StringType::value_type), |
| 68 check_expected_size) { |
| 69 DCHECK(expected_size % sizeof(typename StringType::value_type) == 0); |
| 70 } |
| 71 |
| 72 template <class StringType> |
| 73 PDFiumAPIStringBufferSizeInBytesAdapter< |
| 74 StringType>::~PDFiumAPIStringBufferSizeInBytesAdapter() = default; |
| 75 |
| 76 template <class StringType> |
| 77 void* PDFiumAPIStringBufferSizeInBytesAdapter<StringType>::GetData() { |
| 78 return adapter_.GetData(); |
| 79 } |
| 80 |
| 81 template <class StringType> |
| 82 void PDFiumAPIStringBufferSizeInBytesAdapter<StringType>::Close( |
| 83 int actual_size) { |
| 84 DCHECK(actual_size % sizeof(typename StringType::value_type) == 0); |
| 85 adapter_.Close(actual_size / sizeof(typename StringType::value_type)); |
| 86 } |
| 87 |
| 88 template <class StringType> |
| 89 void PDFiumAPIStringBufferSizeInBytesAdapter<StringType>::Close( |
| 90 size_t actual_size) { |
| 91 DCHECK(actual_size % sizeof(typename StringType::value_type) == 0); |
| 92 adapter_.Close(actual_size / sizeof(typename StringType::value_type)); |
| 93 } |
| 94 |
61 // explicit instantiations | 95 // explicit instantiations |
62 template class PDFiumAPIStringBufferAdapter<std::string>; | 96 template class PDFiumAPIStringBufferAdapter<std::string>; |
63 template class PDFiumAPIStringBufferAdapter<base::string16>; | 97 template class PDFiumAPIStringBufferAdapter<base::string16>; |
| 98 template class PDFiumAPIStringBufferSizeInBytesAdapter<base::string16>; |
64 | 99 |
65 } // namespace chrome_pdf | 100 } // namespace chrome_pdf |
OLD | NEW |