void addBac(struct lineFile *lf, char *acc, char *clo) /* Add bacEnds to pair list. */ { struct hashEl *hel; struct pair *pair; static char *sp6End = " SP6 end"; static char *t7End = " T7 end"; if (acc[0] == 0 || clo[0] == 0 ) { // warn("Incomplete BAC line %d of %s\n", lf->lineIx, lf->fileName); return; } trimEnd(clo, sp6End); trimEnd(clo, t7End); if ((hel = hashLookup(cloneHash, clo)) == NULL) { pair = newPair(); hel = hashAdd(cloneHash, clo, pair); slAddHead(&pairList, pair); pair->a = lCloneString(acc); pair->clone = hel->name; } else { pair = hel->val; pair->b = lCloneString(acc); } }
void loop_player(struct player * me) { char cmd_buffer[80]; char cmd_param[80]; while(1) { printf(PROMPT); memset(&cmd_buffer, '\0', sizeof(char)*80); memset(&cmd_param, '\0', sizeof(char)*80); if(fgets(cmd_buffer, 80, stdin)) { trimEnd(&cmd_buffer, '\n'); int parsed = parse_parameter(&cmd_buffer, &cmd_param); struct commandResult result = execute_command(me, (char*)&cmd_buffer, cmd_param); if(result.moved) { memset(&cmd_param, '\0', sizeof(char)*80); result = execute_command(me, (char*)&"look", cmd_param); } if(result.exit) { break; } }else { break; } } printf("OK... Bye.\n"); }
std::string demo::TestReqCom::toString() const { std::string result; result += ("syn:" + __toString(syn) + " "); result += ("com1:" + __toString(com1) + " "); return trimEnd(result); }
std::string demo::S1::toString() const { std::string result; result += ("id:" + __toString(id) + " "); result += ("name:" + __toString(name) + " "); return trimEnd(result); }
std::string demo::TestReqDict::toString() const { std::string result; result += ("syn:" + __toString(syn) + " "); result += ("dict1:" + __toString(dict1) + " "); return trimEnd(result); }
std::string demo::TestReq::toString() const { std::string result; result += ("syn:" + __toString(syn) + " "); result += ("reqs1:" + __toString(reqs1) + " "); return trimEnd(result); }
std::string trim( const char * buffer, int len ) { const char * begin( trimStart( buffer, len ) ); const char * end( trimEnd( buffer + len, len ) ); if ( begin < end ) return std::string( begin, end ); return emptyString; }
void trimInplace( std::string & str ) { int len( str.length() ); const char * b( str.c_str() ); const char * begin( trimStart( b, len ) ); const char * end( trimEnd( b + len, len ) ); if ( begin < end ) str.assign( begin, end ); else str.clear(); }
std::string demo::__toString(const Com& arg) { std::string result = "{"; for(Com::const_iterator it = arg.begin(); it != arg.end(); ++it) { result += __toString(*it); result += " "; } trimEnd(result); result += "}"; return result; }
std::string demo::__toString(const Dicta& arg) { std::string result = "{"; for(Dicta::const_iterator it = arg.begin(); it != arg.end(); ++it) { result += "<"; result += __toString(it->first); result += ","; result += __toString(it->second); result += ">"; result += " "; } trimEnd(result); result += "}"; return result; }
void removeBlanks(char s[]) { trimEnd(s); bool inBlank = false; for (int i = 0; s[i] != '\0'; ++i) { if (s[i] == '\t' || s[i] == ' ') { if (inBlank) { for (int j = i; s[j] != '\0'; ++j) { s[j] = s[j+1]; } --i; } else { s[i] = ' '; inBlank = true; } } else { inBlank = false; } } trimStart(s); }
/* load material file */ void OBJLoader::loadMTL(const FileName &fileName) { std::ifstream cin; cin.open(fileName.c_str()); if (!cin.is_open()) { std::cerr << "cannot open " << fileName.str() << std::endl; return; } char line[10000]; memset(line, 0, sizeof(line)); OBJMaterial* cur = nullptr; while (cin.peek() != -1) { /* load next multiline */ char* pline = line; while (true) { cin.getline(pline, sizeof(line) - (pline - line) - 16, '\n'); ssize_t last = strlen(pline) - 1; if (last < 0 || pline[last] != '\\') break; pline += last; *pline++ = ' '; } const char* token = trimEnd(line + strspn(line, " \t")); if (token[0] == 0 ) continue; // ignore empty lines if (token[0] == '#') continue; // ignore comments if (!strncmp(token, "newmtl", 6)) { parseSep(token+=6); std::string name(token); Material objmtl; new (&objmtl) OBJMaterial; Ref<SceneGraph::MaterialNode> mtl = new SceneGraph::MaterialNode(objmtl); material[name] = mtl; cur = (OBJMaterial*) &mtl->material; continue; } if (!cur) THROW_RUNTIME_ERROR("invalid material file: newmtl expected first"); if (!strncmp(token, "illum", 5)) { parseSep(token += 5); continue; } if (!strncmp(token, "d", 1)) { parseSep(token += 1); cur->d = getFloat(token); continue; } if (!strncmp(token, "Ns", 2)) { parseSep(token += 2); cur->Ns = getFloat(token); continue; } if (!strncmp(token, "Ni", 2)) { parseSep(token += 2); cur->Ni = getFloat(token); continue; } if (!strncmp(token, "Ka_map", 6)) { continue; } if (!strncmp(token, "Kd_map", 6) || !strncmp(token, "map_Kd", 6)) { parseSep(token += 6); cur->map_Kd = loadTexture(path + FileName(token)); continue; } if (!strncmp(token, "Ks_map", 6)) { continue; } if (!strncmp(token, "Tf_map", 6)) { continue; } if (!strncmp(token, "Displ_map", 9) || !strncmp(token, "map_Displ", 9)) { parseSep(token += 9); cur->map_Displ = loadTexture(path + FileName(token)); continue; } if (!strncmp(token, "Ka", 2)) { parseSep(token += 2); cur->Ka = getVec3f(token); continue; } if (!strncmp(token, "Kd", 2)) { parseSep(token += 2); cur->Kd = getVec3f(token); continue; } if (!strncmp(token, "Ks", 2)) { parseSep(token += 2); cur->Ks = getVec3f(token); continue; } if (!strncmp(token, "Tf", 2)) { parseSep(token += 2); cur->Kt = getVec3f(token); continue; } } cin.close(); }
inline std::string& trim(std::string &string, const char* chars = " \t") { return trimStart(trimEnd(string, chars), chars); }
void trimEndInplace( std::string & str ) { int len( str.length() ); const char * b( str.c_str() ); str.assign( b, trimEnd( b + len, len ) ); }
void trim(char* command) { trimEnd(command); trimStart(command); }
OBJLoader::OBJLoader(const FileName &fileName, const bool subdivMode) : path(fileName.path()), group(new SceneGraph::GroupNode), subdivMode(subdivMode) { /* open file */ std::ifstream cin; cin.open(fileName.c_str()); if (!cin.is_open()) { THROW_RUNTIME_ERROR("cannot open " + fileName.str()); return; } /* generate default material */ Material objmtl; new (&objmtl) OBJMaterial; Ref<SceneGraph::MaterialNode> defaultMaterial = new SceneGraph::MaterialNode(objmtl); curMaterial = defaultMaterial; char line[10000]; memset(line, 0, sizeof(line)); while (cin.peek() != -1) { /* load next multiline */ char* pline = line; while (true) { cin.getline(pline, sizeof(line) - (pline - line) - 16, '\n'); ssize_t last = strlen(pline) - 1; if (last < 0 || pline[last] != '\\') break; pline += last; *pline++ = ' '; } const char* token = trimEnd(line + strspn(line, " \t")); if (token[0] == 0) continue; /*! parse position */ if (token[0] == 'v' && isSep(token[1])) { v.push_back(getVec3f(token += 2)); continue; } /* parse normal */ if (token[0] == 'v' && token[1] == 'n' && isSep(token[2])) { vn.push_back(getVec3f(token += 3)); continue; } /* parse texcoord */ if (token[0] == 'v' && token[1] == 't' && isSep(token[2])) { vt.push_back(getVec2f(token += 3)); continue; } /*! parse face */ if (token[0] == 'f' && isSep(token[1])) { parseSep(token += 1); std::vector<Vertex> face; while (token[0]) { Vertex vtx = getInt3(token); face.push_back(vtx); parseSepOpt(token); } curGroup.push_back(face); continue; } /*! parse edge crease */ if (token[0] == 'e' && token[1] == 'c' && isSep(token[2])) { parseSep(token += 2); float w = getFloat(token); parseSepOpt(token); int a = fix_v(getInt(token)); parseSepOpt(token); int b = fix_v(getInt(token)); parseSepOpt(token); ec.push_back(Crease(w, a, b)); continue; } /*! use material */ if (!strncmp(token, "usemtl", 6) && isSep(token[6])) { flushFaceGroup(); std::string name(parseSep(token += 6)); if (material.find(name) == material.end()) curMaterial = defaultMaterial; else curMaterial = material[name]; continue; } /* load material library */ if (!strncmp(token, "mtllib", 6) && isSep(token[6])) { loadMTL(path + std::string(parseSep(token += 6))); continue; } // ignore unknown stuff } flushFaceGroup(); cin.close(); }
string Parser::trim(string str){ return trimEnd(trimFront(str)); }
/* * Removes blanks (spaces, tabs, CR, LF) at the both ends of the given string * The string is modified and returned */ char* trim(char* str) { return trimEnd(trimStart(str)); }
std::string& trim(std::string& inputString) { trimEnd(inputString); trimBeginning(inputString); return inputString; }