本文整理汇总了C++中boost::trim_copy方法的典型用法代码示例。如果您正苦于以下问题:C++ boost::trim_copy方法的具体用法?C++ boost::trim_copy怎么用?C++ boost::trim_copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost
的用法示例。
在下文中一共展示了boost::trim_copy方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CmdParam
/** Player selection.
This command is compatible with the GoGui analyze command type "param".
Parameters:
@arg @c player Player id as in FuegoTestEngine::SetPlayer */
void FuegoTestEngine::CmdParam(GtpCommand& cmd)
{
cmd.CheckNuArgLessEqual(2);
if (cmd.NuArg() == 0)
{
cmd <<
"[list/<none>/average/capture/dumbtactic/greedy/influence/"
"ladder/liberty/maxeye/minlib/no-search/random/safe] player "
<< (m_playerId == "" ? "<none>" : m_playerId) << '\n';
}
else if (cmd.NuArg() >= 1 && cmd.NuArg() <= 2)
{
string name = cmd.Arg(0);
if (name == "player")
{
try
{
string id = trim_copy(cmd.RemainingLine(0));
if (id == "<none>")
id = "";
SetPlayer(id);
}
catch (const SgException& e)
{
throw GtpFailure(e.what());
}
}
else
throw GtpFailure() << "unknown parameter: " << name;
}
else
throw GtpFailure() << "need 0 or 2 arguments";
}
示例2: isNextEmpty
bool NastranTokenizer::isNextEmpty() {
if (nextSymbolType != NastranTokenizer::SYMBOL_FIELD) {
return false;
}
string curField = trim_copy(currentLineVector[currentField]);
return curField.empty();
}
示例3: nextDouble
double NastranTokenizer::nextDouble(bool returnDefaultIfNotFoundOrBlank, double defaultValue) {
double result;
if (returnDefaultIfNotFoundOrBlank && this->nextSymbolType != SYMBOL_FIELD) {
return defaultValue;
}
string value = trim_copy(nextSymbolString());
if (returnDefaultIfNotFoundOrBlank && value.empty()) {
return defaultValue;
}
boost::replace_all(value, "d", "e");
boost::replace_all(value, "D", "E");
boost::algorithm::erase_all(value, " ");
size_t position = value.find_first_of("+-", 1);
if (position != string::npos and position != value.find_first_of("eE", 1) + 1) {
value.insert(position, "E");
}
try {
result = lexical_cast<double>(value);
} catch (boost::bad_lexical_cast &e) {
string currentFieldstr =
currentField == 0 ? string("LAST") : (lexical_cast<string>(currentField - 1));
string message = "Value: [" + value + "]can't be converted to double. Field Num: "
+ currentFieldstr + " " + e.what();
throw vega::ParsingException(message, fileName, lineNumber);
}
return result;
}
示例4: isNextInt
bool NastranTokenizer::isNextInt() {
if (nextSymbolType != NastranTokenizer::SYMBOL_FIELD) {
return false;
}
string curField = trim_copy(currentLineVector[currentField]);
return !curField.empty() && (strspn(curField.c_str(), "-0123456789") == curField.size());
}
示例5: splitFreeFormat
void NastranTokenizer::splitFreeFormat(string line, bool firstLine) {
if (firstLine) {
split(currentLineVector, line, boost::is_any_of(","));
} else {
//skip first field;
string lineNoContinuation = line.substr(line.find(',') + 1);
vector<string> otherLine;
split(otherLine, lineNoContinuation, boost::is_any_of(","));
currentLineVector.insert(currentLineVector.end(), otherLine.begin(), otherLine.end());
}
bool explicitContinuation = false;
for (size_t fieldIndex = 1; fieldIndex < currentLineVector.size(); fieldIndex += 8) {
string field = trim_copy(currentLineVector[fieldIndex]);
if (field[0] == '+') {
explicitContinuation = true;
currentLineVector.erase(currentLineVector.begin() + fieldIndex);
}
}
char c = static_cast<char>(this->instrream.peek());
string line2;
if (explicitContinuation || c == ',' || c == '+' || c == '*') {
readLineSkipComment(line2);
splitFreeFormat(line2, false);
}
}
示例6: isNextDouble
bool NastranTokenizer::isNextDouble() {
if (nextSymbolType != NastranTokenizer::SYMBOL_FIELD) {
return false;
}
string curField = trim_copy(currentLineVector[currentField]);
boost::algorithm::erase_all(curField, " ");
return !curField.empty() && (strspn(curField.c_str(), "-+0123456789.eEdD") == curField.size());
}
示例7: nextString
string NastranTokenizer::nextString(bool returnDefaultIfNotFoundOrBlank, string defaultValue) {
string result;
if (returnDefaultIfNotFoundOrBlank && (this->nextSymbolType != SYMBOL_FIELD)) {
return defaultValue;
}
string value = nextSymbolString();
if (returnDefaultIfNotFoundOrBlank && !defaultValue.empty() && trim_copy(value).empty()) {
value = defaultValue;
}
return value;
}
示例8: isEmptyUntilNextKeyword
bool NastranTokenizer::isEmptyUntilNextKeyword() {
if (nextSymbolType == NastranTokenizer::SYMBOL_KEYWORD) {
return true;
} else if (nextSymbolType == NastranTokenizer::SYMBOL_EOF) {
return true;
}
bool result = true;
for (size_t i = currentField; i < this->currentLineVector.size() && result; i++) {
string curField = trim_copy(currentLineVector[i]);
result &= curField.empty();
}
return result;
}
示例9: nextInt
int NastranTokenizer::nextInt(bool returnDefaultIfNotFoundOrBlank, int defaultValue) {
int result;
if (returnDefaultIfNotFoundOrBlank && this->nextSymbolType != SYMBOL_FIELD) {
return defaultValue;
}
string value = trim_copy(nextSymbolString());
if (returnDefaultIfNotFoundOrBlank && value.empty()) {
return defaultValue;
}
try {
result = lexical_cast<int>(value);
} catch (boost::bad_lexical_cast &) {
string currentFieldstr =
currentField == 0 ? string("LAST") : (lexical_cast<string>(currentField - 1));
string message = "Value: [" + value + "] can't be converted to int. Field Num:"
+ currentFieldstr;
throw vega::ParsingException(message, fileName, lineNumber);
}
return result;
}
示例10: next
//.........这里部分代码省略.........
int num_attrs = ctx_->size() + 1;
for (; pos < num_attrs; ++pos)
{
std::string name = rs_->getFieldName(pos);
if (rs_->isNull(pos))
{
feature->put(name, mapnik::value_null());
}
else
{
const char* buf = rs_->getValue(pos);
const int oid = rs_->getTypeOID(pos);
switch (oid)
{
case 16: //bool
{
feature->put(name, (buf[0] != 0));
break;
}
case 23: //int4
{
int val = int4net(buf);
feature->put(name, val);
break;
}
case 21: //int2
{
int val = int2net(buf);
feature->put(name, val);
break;
}
case 20: //int8/BigInt
{
int val = int8net(buf);
feature->put(name, val);
break;
}
case 700: //float4
{
float val;
float4net(val, buf);
feature->put(name, val);
break;
}
case 701: //float8
{
double val;
float8net(val, buf);
feature->put(name, val);
break;
}
case 25: //text
case 1043: //varchar
{
feature->put(name, tr_->transcode(buf));
break;
}
case 1042: //bpchar
{
feature->put(name, tr_->transcode(trim_copy(std::string(buf)).c_str()));
break;
}
case 1700: //numeric
{
double val;
std::string str = mapnik::sql_utils::numeric2string(buf);
if (mapnik::util::string2double(str, val))
{
feature->put(name, val);
}
break;
}
default:
{
#ifdef MAPNIK_DEBUG
std::clog << "Postgis Plugin: uknown OID = " << oid << std::endl;
#endif
break;
}
}
}
}
return feature;
}
else
{
rs_->close();
return feature_ptr();
}
}
示例11: next
feature_ptr postgis_featureset::next()
{
if (rs_->next())
{
// new feature
feature_ptr feature;
unsigned pos = 1;
if (key_field_) {
// create feature with user driven id from attribute
int oid = rs_->getTypeOID(pos);
const char* buf = rs_->getValue(pos);
std::string name = rs_->getFieldName(pos);
// validation happens of this type at bind()
int val;
if (oid == 20)
{
val = int8net(buf);
}
else if (oid == 21)
{
val = int2net(buf);
}
else
{
val = int4net(buf);
}
feature = feature_factory::create(val);
// TODO - extend feature class to know
// that its id is also an attribute to avoid
// this duplication
boost::put(*feature,name,val);
++pos;
} else {
// fallback to auto-incrementing id
feature = feature_factory::create(feature_id_);
++feature_id_;
}
// parse geometry
int size = rs_->getFieldLength(0);
const char *data = rs_->getValue(0);
geometry_utils::from_wkb(feature->paths(),data,size,multiple_geometries_);
totalGeomSize_+=size;
for ( ;pos<num_attrs_+1;++pos)
{
std::string name = rs_->getFieldName(pos);
if (rs_->isNull(pos))
{
boost::put(*feature,name,mapnik::value_null());
}
else
{
const char* buf = rs_->getValue(pos);
int oid = rs_->getTypeOID(pos);
if (oid==16) //bool
{
boost::put(*feature,name,buf[0] != 0);
}
else if (oid==23) //int4
{
int val = int4net(buf);
boost::put(*feature,name,val);
}
else if (oid==21) //int2
{
int val = int2net(buf);
boost::put(*feature,name,val);
}
else if (oid==20) //int8/BigInt
{
int val = int8net(buf);
boost::put(*feature,name,val);
}
else if (oid == 700) // float4
{
float val;
float4net(val,buf);
boost::put(*feature,name,val);
}
else if (oid == 701) // float8
{
double val;
float8net(val,buf);
boost::put(*feature,name,val);
}
else if (oid==25 || oid==1043) // text or varchar
{
UnicodeString ustr = tr_->transcode(buf);
boost::put(*feature,name,ustr);
}
else if (oid==1042)
{
UnicodeString ustr = tr_->transcode(trim_copy(std::string(buf)).c_str()); // bpchar
boost::put(*feature,name,ustr);
}
//.........这里部分代码省略.........
示例12: assert
void mdb_shell::filter_metaprogram() {
assert(mp);
using boost::starts_with;
using boost::ends_with;
using boost::trim_copy;
using vertex_descriptor = metaprogram::vertex_descriptor;
using edge_descriptor = metaprogram::edge_descriptor;
using edge_property = metaprogram::edge_property;
using discovered_t = metaprogram::discovered_t;
static const std::string wrap_prefix = "metashell::impl::wrap<";
static const std::string wrap_suffix = ">";
// TODO this check could be made more strict,
// since we now whats inside wrap<...> (mp->get_evaluation_result)
auto is_wrap_type = [](const std::string& type) {
return starts_with(type, wrap_prefix) && ends_with(type, wrap_suffix);
};
std::string env_buffer = env.get();
int line_number = std::count(env_buffer.begin(), env_buffer.end(), '\n');
// First disable everything
for (edge_descriptor edge : mp->get_edges()) {
mp->get_edge_property(edge).enabled = false;
}
// We will traverse the interesting edges later
std::stack<edge_descriptor> edge_stack;
// Enable the interesting root edges
for (edge_descriptor edge : mp->get_out_edges(mp->get_root_vertex())) {
edge_property& property = mp->get_edge_property(edge);
const std::string& target_name =
mp->get_vertex_property(mp->get_target(edge)).name;
// Filter out edges, that is not instantiated by the entered type
if (property.point_of_instantiation.name == internal_file_name &&
property.point_of_instantiation.row == line_number + 2 &&
(property.kind == instantiation_kind::template_instantiation ||
property.kind == instantiation_kind::memoization) &&
(!is_wrap_type(target_name) ||
property.kind != instantiation_kind::memoization))
{
property.enabled = true;
edge_stack.push(edge);
}
}
discovered_t discovered(mp->get_num_vertices());
// Traverse the graph to enable all edges which are reachable from the
// edges enabled above
while (!edge_stack.empty()) {
edge_descriptor edge = edge_stack.top();
edge_stack.pop();
assert(mp->get_edge_property(edge).enabled);
vertex_descriptor vertex = mp->get_target(edge);
if (discovered[vertex]) {
continue;
}
for (edge_descriptor out_edge : mp->get_out_edges(vertex)) {
edge_property& property = mp->get_edge_property(out_edge);
if (property.kind == instantiation_kind::template_instantiation ||
property.kind == instantiation_kind::memoization)
{
property.enabled = true;
edge_stack.push(out_edge);
}
}
}
// Unwrap vertex names
for (metaprogram::vertex_descriptor vertex : mp->get_vertices()) {
std::string& name = mp->get_vertex_property(vertex).name;
if (is_wrap_type(name)) {
name = trim_copy(name.substr(
wrap_prefix.size(),
name.size() - wrap_prefix.size() - wrap_suffix.size()));
if (!is_template_type(name)) {
for (metaprogram::edge_descriptor in_edge : mp->get_in_edges(vertex)) {
mp->get_edge_property(in_edge).kind =
instantiation_kind::non_template_type;
}
}
}
}
// Clang sometimes produces equivalent instantiations events from the same
// point. Filter out all but one of each
for (metaprogram::vertex_descriptor vertex : mp->get_vertices()) {
typedef std::tuple<file_location, instantiation_kind, vertex_descriptor>
set_element_t;
std::set<set_element_t> similar_edges;
//.........这里部分代码省略.........
示例13: splitFixedFormat
void NastranTokenizer::splitFixedFormat(string& line, const bool longFormat, const bool firstLine) {
boost::offset_separator f;
int fieldMax;
if (longFormat) {
int offsets[] = { 8, 16, 16, 16, 16, 8 };
fieldMax = 5;
f = offset_separator(offsets, offsets + 6);
} else {
int offsets[] = { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 };
fieldMax = 9;
f = offset_separator(offsets, offsets + 10);
}
replaceTabs(line);
tokenizer<offset_separator> tok(line, f);
tokenizer<offset_separator>::iterator beg = tok.begin();
int count = 0;
if (!firstLine) {
//todo:check that explicit continuation tokens are the same
++beg;
count++;
}
bool explicitContinuation = false;
for (; beg != tok.end(); ++beg) {
string trimCopy = trim_copy(*beg);
//erase all the long format specifiers
if (count == 0) {
boost::erase_all(trimCopy, "*");
}
currentLineVector.push_back(trimCopy);
if (++count == fieldMax) {
explicitContinuation = (++beg != tok.end()) && !(trim_copy(*beg).empty());
if (explicitContinuation && this->logLevel >= vega::LogLevel::TRACE) {
cout << "explicitContinuation" << endl;
}
break;
}
}
string line2;
if (explicitContinuation) {
//todo:check that continuation tokens are the same
bool iseof = readLineSkipComment(line2);
if (!iseof) {
splitFixedFormat(line2, longFormat, false);
} else {
throw "Continuation Expected: Line N " + this->lineNumber;
}
} else {
//test for automatic continuation
char c = static_cast<char>(this->instrream.peek());
if (c == ' ' || c == '+' || c == '*') {
readLineSkipComment(line2);
//fill the current line with empty fields
for (; count < fieldMax; count++) {
currentLineVector.push_back("");
}
bool longFormat = (c == '*');
splitFixedFormat(line2, longFormat, false);
}
}
}