OLD | NEW |
1 // Copyright 2015 PDFium Authors. All rights reserved. | 1 // Copyright 2015 PDFium 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 "testing/test_support.h" | 5 #include "testing/test_support.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 ++characters; | 111 ++characters; |
112 | 112 |
113 std::wstring platform_string(characters, L'\0'); | 113 std::wstring platform_string(characters, L'\0'); |
114 for (size_t i = 0; i < characters + 1; ++i) { | 114 for (size_t i = 0; i < characters + 1; ++i) { |
115 const unsigned char* ptr = reinterpret_cast<const unsigned char*>(&wstr[i]); | 115 const unsigned char* ptr = reinterpret_cast<const unsigned char*>(&wstr[i]); |
116 platform_string[i] = ptr[0] + 256 * ptr[1]; | 116 platform_string[i] = ptr[0] + 256 * ptr[1]; |
117 } | 117 } |
118 return platform_string; | 118 return platform_string; |
119 } | 119 } |
120 | 120 |
| 121 std::vector<std::string> StringSplit(const std::string& str, char delimiter) { |
| 122 std::vector<std::string> result; |
| 123 size_t pos = 0; |
| 124 while (1) { |
| 125 size_t found = str.find(delimiter, pos); |
| 126 if (found == std::string::npos) |
| 127 break; |
| 128 |
| 129 result.push_back(str.substr(pos, found - pos)); |
| 130 pos = found + 1; |
| 131 } |
| 132 result.push_back(str.substr(pos)); |
| 133 return result; |
| 134 } |
| 135 |
121 std::unique_ptr<unsigned short, pdfium::FreeDeleter> GetFPDFWideString( | 136 std::unique_ptr<unsigned short, pdfium::FreeDeleter> GetFPDFWideString( |
122 const std::wstring& wstr) { | 137 const std::wstring& wstr) { |
123 size_t length = sizeof(uint16_t) * (wstr.length() + 1); | 138 size_t length = sizeof(uint16_t) * (wstr.length() + 1); |
124 std::unique_ptr<unsigned short, pdfium::FreeDeleter> result( | 139 std::unique_ptr<unsigned short, pdfium::FreeDeleter> result( |
125 static_cast<unsigned short*>(malloc(length))); | 140 static_cast<unsigned short*>(malloc(length))); |
126 char* ptr = reinterpret_cast<char*>(result.get()); | 141 char* ptr = reinterpret_cast<char*>(result.get()); |
127 size_t i = 0; | 142 size_t i = 0; |
128 for (wchar_t w : wstr) { | 143 for (wchar_t w : wstr) { |
129 ptr[i++] = w & 0xff; | 144 ptr[i++] = w & 0xff; |
130 ptr[i++] = (w >> 8) & 0xff; | 145 ptr[i++] = (w >> 8) & 0xff; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 } | 200 } |
186 | 201 |
187 // static | 202 // static |
188 int TestSaver::WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, | 203 int TestSaver::WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, |
189 const void* data, | 204 const void* data, |
190 unsigned long size) { | 205 unsigned long size) { |
191 TestSaver* pThis = static_cast<TestSaver*>(pFileWrite); | 206 TestSaver* pThis = static_cast<TestSaver*>(pFileWrite); |
192 pThis->m_String.append(static_cast<const char*>(data), size); | 207 pThis->m_String.append(static_cast<const char*>(data), size); |
193 return 1; | 208 return 1; |
194 } | 209 } |
OLD | NEW |