Init
This commit is contained in:
commit
950e7b7e2d
350 files changed
+38599
No files matched your search
Executable
+70
@@ -0,0 +1,70 @@
|
||||
#include "PreprocessInputStream.h"
|
||||
|
||||
#include <string>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace bts {
|
||||
namespace config {
|
||||
|
||||
void replace_all(string& line, const string& before, const string& after) {
|
||||
|
||||
string::const_iterator end = line.end();
|
||||
string::const_iterator current = line.begin();
|
||||
string::const_iterator next = search(current, end, before.begin(), before.end());
|
||||
|
||||
if (next != end) {
|
||||
std::string result;
|
||||
while(next != end) {
|
||||
result.append(current, next);
|
||||
result.append(after);
|
||||
current = next + before.size();
|
||||
next = search(current, end, before.begin(), before.end());
|
||||
}
|
||||
result.append(current, next);
|
||||
line = result;
|
||||
}
|
||||
}
|
||||
|
||||
PreprocessInputStream::PreprocessInputStream(std::istream& input, map<string, string> replacements) :
|
||||
_buffer(),
|
||||
_stream()
|
||||
{
|
||||
char temp[4096];
|
||||
while(input.read(temp, sizeof(temp))) {
|
||||
_buffer.append(temp, sizeof(temp));
|
||||
}
|
||||
_buffer.append(temp, input.gcount());
|
||||
|
||||
for (map<string, string>::iterator iter = replacements.begin(); iter != replacements.end(); iter++) {
|
||||
const string& key = iter->first;
|
||||
const string& value = iter->second;
|
||||
replace_all(_buffer, key, value);
|
||||
}
|
||||
|
||||
_stream.reset(new proto::io::ArrayInputStream(_buffer.c_str(), _buffer.size()));
|
||||
}
|
||||
|
||||
PreprocessInputStream::~PreprocessInputStream()
|
||||
{
|
||||
}
|
||||
|
||||
bool PreprocessInputStream::Next(const void** data, int* size) {
|
||||
return _stream->Next(data, size);
|
||||
}
|
||||
|
||||
void PreprocessInputStream::BackUp(int count) {
|
||||
_stream->BackUp(count);
|
||||
}
|
||||
|
||||
bool PreprocessInputStream::Skip(int count) {
|
||||
return _stream->Skip(count);
|
||||
}
|
||||
|
||||
proto::int64 PreprocessInputStream::ByteCount() const {
|
||||
return _stream->ByteCount();
|
||||
}
|
||||
|
||||
}}//namespace
|
||||
|
||||
Reference in new issue
Block a user