blob: 24aeb6fc11c6082600604710023a14723207f2c6 (
plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include "src/torque/ast.h"
#include "src/torque/utils.h"
namespace v8 {
namespace internal {
namespace torque {
std::string CurrentPositionAsString() {
return PositionAsString(CurrentSourcePosition::Get());
}
[[noreturn]] void ReportError(const std::string& error) {
std::cerr << CurrentPositionAsString() << ": Torque error: " << error << "\n";
throw(-1);
}
std::string CamelifyString(const std::string& underscore_string) {
std::string result;
bool word_beginning = true;
for (auto current : underscore_string) {
if (current == '_' || current == '-') {
word_beginning = true;
continue;
}
if (word_beginning) {
current = toupper(current);
}
result += current;
word_beginning = false;
}
return result;
}
std::string DashifyString(const std::string& underscore_string) {
std::string result = underscore_string;
std::replace(result.begin(), result.end(), '_', '-');
return result;
}
void ReplaceFileContentsIfDifferent(const std::string& file_path,
const std::string& contents) {
std::ifstream old_contents_stream(file_path.c_str());
std::string old_contents;
if (old_contents_stream.good()) {
std::istreambuf_iterator<char> eos;
old_contents =
std::string(std::istreambuf_iterator<char>(old_contents_stream), eos);
old_contents_stream.close();
}
if (old_contents.length() == 0 || old_contents != contents) {
std::ofstream new_contents_stream;
new_contents_stream.open(file_path.c_str());
new_contents_stream << contents;
new_contents_stream.close();
}
}
} // namespace torque
} // namespace internal
} // namespace v8
|