1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00
denoland-deno/libdeno/file_util.cc
2018-08-19 11:27:47 -04:00

31 lines
728 B
C++

// Copyright 2018 the Deno authors. All rights reserved. MIT license.
#include <inttypes.h>
#include <stdio.h>
#include <fstream>
#include <iterator>
#include <string>
#include "file_util.h"
namespace deno {
bool ReadFileToString(const char* fn, std::string* contents) {
std::ifstream file(fn, std::ios::binary);
if (file.fail()) {
return false;
}
contents->assign(std::istreambuf_iterator<char>{file}, {});
return !file.fail();
}
std::string Basename(std::string const& filename) {
for (auto it = filename.rbegin(); it != filename.rend(); ++it) {
char ch = *it;
if (ch == '\\' || ch == '/') {
return std::string(it.base(), filename.end());
}
}
return filename;
}
} // namespace deno