| 227 | } |
| 228 | |
| 229 | std::vector<std::string> Explorer::ReadFileLines(const std::string &path, const u32 line_offset, const u32 line_count) { |
| 230 | std::vector<std::string> data; |
| 231 | const auto full_path = this->MakeFull(path); |
| 232 | const auto file_size = this->GetFileSize(full_path); |
| 233 | if(file_size == 0) { |
| 234 | return data; |
| 235 | } |
| 236 | std::string tmp_line; |
| 237 | u32 tmp_line_offset = 0; |
| 238 | auto rem_size = file_size; |
| 239 | u64 offset = 0; |
| 240 | auto work_buf = AllocateWorkBuffer(); |
| 241 | auto end = false; |
| 242 | while(rem_size && !end) { |
| 243 | const auto read_size = this->ReadFile(full_path, offset, std::min(DefaultWorkBufferSize, rem_size), work_buf); |
| 244 | if(read_size == 0) { |
| 245 | return data; |
| 246 | } |
| 247 | rem_size -= read_size; |
| 248 | offset += read_size; |
| 249 | for(u32 i = 0; i < read_size; i++) { |
| 250 | const auto ch = static_cast<char>(work_buf[i]); |
| 251 | if(ch == '\n') { |
| 252 | const auto prev_tmp_line_offset = tmp_line_offset; |
| 253 | tmp_line_offset++; |
| 254 | if(prev_tmp_line_offset < line_offset) { |
| 255 | tmp_line = ""; |
| 256 | continue; |
| 257 | } |
| 258 | std::string tab = "\t"; |
| 259 | while(true) { |
| 260 | const auto find_pos = tmp_line.find(tab); |
| 261 | if(find_pos == std::string::npos) { |
| 262 | break; |
| 263 | } |
| 264 | tmp_line.replace(find_pos, tab.length(), " "); |
| 265 | } |
| 266 | data.push_back(tmp_line); |
| 267 | if(data.size() >= line_count) { |
| 268 | end = true; |
| 269 | break; |
| 270 | } |
| 271 | tmp_line = ""; |
| 272 | } |
| 273 | else if(tmp_line_offset >= line_offset) { |
| 274 | tmp_line += ch; |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | DeleteWorkBuffer(work_buf); |
| 279 | if(!tmp_line.empty()) { |
| 280 | data.push_back(tmp_line); |
| 281 | tmp_line = ""; |
| 282 | } |
| 283 | return data; |
| 284 | } |
| 285 | |
| 286 | std::vector<std::string> Explorer::ReadFileFormatHex(const std::string &path, const u32 line_offset, const u32 line_count) { |
no test coverage detected