forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_util.cc
31 lines (26 loc) · 728 Bytes
/
file_util.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// 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