void Parser_XML::number_list(std::string& chaine, std::string& number) { const char current_token = read_current_token(chaine); if(ASCII_NUM(current_token)) { destroy_current_token(chaine, current_token); number.push_back(current_token); number_list(chaine, number); } else if(current_token == '<') { } else if(current_token == '.') { destroy_current_token(chaine, current_token); number.push_back(current_token); number_float(chaine, number); } else { std::cerr << "Error when reading a number." << std::endl; } }
bool HashMap::set( const std::string& key, const std::string& value) { uint32_t id = m_symtab.getOrCreate( key); if (!m_symtab.isNew()) throw strus::runtime_error(_TXT("duplicate definition of symbol '%s'"), key.c_str()); if (id != m_value_refs.size()+1) throw std::runtime_error( _TXT("internal: inconsistency in data")); m_value_strings.push_back('\0'); m_value_refs.push_back( m_value_strings.size()); m_value_strings.append( value); return true; }
void readString(std::string& utf8) { uint32_t i = readUInt32BE(); utf8.clear(); utf8.reserve(i); while (i--) { utf8.push_back(readUInt8BE()); } align(4); }
void setResourcePath(const std::string& path) { TGUI_ResourcePath = path; if (!TGUI_ResourcePath.empty()) { if (TGUI_ResourcePath[TGUI_ResourcePath.length()-1] != '/') TGUI_ResourcePath.push_back('/'); } }
CgroupManager() { std::mt19937 rd{std::random_device{}()}; std::uniform_int_distribution<int> dist{0, 61}; groupName.reserve(31); groupName.push_back('/'); for(int i = 0; i < 30; ++ i) { int r = dist(rd); // Only ASCII and UTF-8 Support if(r < 26) { groupName.push_back('a' + r); }else if(r < 52) { groupName.push_back('A' + r - 26); }else { groupName.push_back('0' + r - 52); } } }
inline void clear() { St.clear(); s.clear(); last=1; n=0; St.push_back(0); St.push_back(-1); St[0].sufflink=1; s.push_back(-1); }
static inline void getGifMask(std::string &mask, const std::string &front) { mask = front; //Make mask filename size_t dotPos = mask.find_last_of('.'); if(dotPos == std::string::npos) mask.push_back('m'); else mask.insert(mask.begin() + dotPos, 'm'); }
void serialize(std::string& out) const { if (Action == ACT_BAN) out.push_back('*'); else if (Action == ACT_BLOCK) out.push_back('~'); out.append(ConvToStr(Lines)).push_back(':'); out.append(ConvToStr(Seconds)); if (Diff) { out.push_back(':'); out.append(ConvToStr(Diff)); if (Backlog) { out.push_back(':'); out.append(ConvToStr(Backlog)); } } }
void WideStrToUTF8(std::string& dest, wstring& src) { wchar_t w; dest.clear(); for (size_t i = 0; i < src.size(); i++) { w = src[i]; if (w <= 0x7f) { dest.push_back((char)w); } else if (w <= 0x7ff) { dest.push_back(0xc0 | ((w >> 6)& 0x1f)); dest.push_back(0x80| (w & 0x3f)); } else if (w <= 0xffff)
/* all words with prefix recursive helper method */ void Trie::awwhelper(std::string word, Node* cur, std::vector<std::string>* wl){ for(int i=0; i<26; i++){ if(cur->galpha()[i]){ word.push_back((char)(i + 97)); if(cur->galpha()[i]->isend()) wl->push_back(word); this->awwhelper(word, cur->galpha()[i], wl); word.pop_back(); } } }
void StdinReader::operator()() { while(std::cin) { char c; std::cin.get(c); std::lock_guard<std::mutex> lock(m_mutex); if(std::cin) m_data.push_back(c); } }
// Finds all occurrences of a circular pattern. std::set<int> Multv::cmatch(std::string &pattern) { assert(st_ != NULL); std::set<char> pattern_alpha = alphabet(pattern); assert(pattern_alpha.find('$') == pattern_alpha.end() && pattern_alpha.find('#') == pattern_alpha.end()); pattern += pattern; // form PP pattern.push_back('#'); // add termination character st_->insertPattern(pattern, false); std::set<int> matches(st_->getMatches()); st_->removePattern(); return matches; }
std::string escape_username(std::string username) { if (username.find('@') == username.npos && !config_file.defdomain.empty()) { username.push_back('@'); username += config_file.defdomain; } return escape(username); }
bool istream_t::getline(std::string& line) { /// \todo not very efficient: should buffer larger chunks (1K ?!) and check for endline there! char c; while (read(&c, 1) && isendl(c)) {} line.clear(); while (read(&c, 1) && !isendl(c)) { line.push_back(c); } return m_status != io_status::error && !line.empty(); }
void Cliente::getDireccionYPuerto(char const * dir_puerto, \ std::string& direccion,\ t_puerto& puerto){ std::stringstream puerto_str; char c; while ((c=*(dir_puerto++)) && c!=':') direccion.push_back(c); while ((c=*(dir_puerto++)) && c!='\0') puerto_str << c; puerto_str >> puerto; }
void AIStateMachine::StateTimer::TimeData::DumpTimer(std::ostringstream& msg, std::string prefix) { F64 const tfactor = 1000 / calc_clock_frequency(); msg << prefix << mName << " " << (mEnd - mStart)*tfactor << "ms" << std::endl; prefix.push_back(' '); std::vector<TimeData>::iterator it; for (it = mChildren.begin(); it != mChildren.end(); ++it) { it->DumpTimer(msg, prefix); } }
static void preprocessFile(std::string& source, const std::string& fname, std::vector<std::string>& file_list) { static const std::string shader_path("data/shaders/"); std::ifstream f(shader_path + fname); if (!f) { source.append("#error File not found: "); source.append(fname); source.append(".\n"); } unsigned int file_n = file_list.size(); file_list.push_back(fname); if (file_n > 0) { source.append("#line 1 "); source.append(std::to_string((unsigned long long)file_n)); source.push_back('\n'); } std::string line; unsigned int line_n = 1; while (std::getline(f, line)) { line_n += 1; if (line.substr(0, 8) == "#include") { std::smatch results; if (std::regex_match(line, results, include_re)) { preprocessFile(source, results[1].str(), file_list); source.append("#line "); source.append(std::to_string((unsigned long long)line_n)); source.push_back(' '); source.append(std::to_string((unsigned long long)file_n)); source.push_back('\n'); } else { source.append("#error Malformed include directive.\n"); } } else { source.append(line); source.push_back('\n'); } } }
bool AParser::read_until(std::string& in, const std::string& delim) { unsigned int i = 0; while (!eof() && !peek(delim)) { in.push_back(getChar()); i++; _index++; } if (i > 0) return true; return false; }
bool AParser::read_some(std::string& in, unsigned int size) { if (_index + size < _buffer.size()) { unsigned int i = 0; while (i < size) { in.push_back(getChar()); _index++; i++; } return true; } return false; }
bool AParser::read_until_func(std::string& in, const boost::function< bool() >& delim) { unsigned int i = 0; while (!eof() && !delim()) { in.push_back(getChar()); i++; _index++; } if (i > 0) return true; return false; }
void dfs(char u) { m_seen[u] = true; // traverse neightbor if (m_G.count(u)) { for (char v : m_G[u]) { if (m_seen[v] == false) dfs(v); } } m_order.push_back(u); }
void parseVecStr2Str(const std::vector<std::string>& vec_str, std::string& str,char div) { str.clear(); for(size_t i=0;i<vec_str.size();++i) { if(!str.empty()) { str.push_back(div); } str+=vec_str[i]; } }
virtual int_type underflow() { while (m_curr == m_high) { char * line = readline(""); if (!line) { // EOF received return traits_type::eof(); } else if (strlen(line) == 0) { // ignore blank line m_buffer.push_back('\n'); free(line); } else { add_history(line); m_buffer += line; m_buffer.push_back('\n'); free(line); m_high = m_buffer.size(); } } return traits_type::to_int_type(m_buffer[m_curr]); }
void nextword(std::string& rv) { int ch = next(); while (isspace(ch)) ch = next(); while (isalnum(ch) || ch == '_'|| ch == '-') { rv.push_back(ch); ch = next(); } unget(ch); }
bool InputReader::read_quoted_string(std::string& str) { //input_stream_ >> str; // not sure if this works char curr_c; input_stream_.get(curr_c); if(!input_stream_.good()) return false; // premature end of file reached while(curr_c != '"') { str.push_back(curr_c); input_stream_.get(curr_c); } // while // not ungetting because last read character is '"' return true; } // InputReader::read_quoted_string()
void File::readString(std::string& str, size_t maxChar, bool seekToEnd) { size_t temp = cursor; str.clear(); char c; size_t count = 1; read(c); while (c && count < maxChar && !eof()) { str.push_back(c); read(c); count++; } if (c) str.push_back(c); if (seekToEnd) { seek(temp+maxChar); } }
int multiply(const std::string strMultiplierA, const std::string strMultiplierB, std::string &strRst) { /* 在这里实现功能 */ if (strMultiplierA.length() == 0 || strMultiplierB.length() == 0) return -1; vector<int> multiA, multiB, result; for (int i = strMultiplierA.length() - 1; i >= 0; --i) multiA.push_back(strMultiplierA[i] - '0'); for (int i = strMultiplierB.length() - 1; i >= 0; --i) multiB.push_back(strMultiplierB[i] - '0'); for (int i = 0; i < multiB.size(); ++i) { vector<int> tempMulti; for (int k = 0; k < i; ++k) tempMulti.push_back(0); int carry = 0; for (int j = 0; j < multiA.size(); ++j) { int temp = multiB[i] * multiA[j] + carry; tempMulti.push_back(temp % 10); carry = temp / 10; } if (carry) tempMulti.push_back(carry); vector<int> tempResult = result; result = ArrayAdd(tempMulti, tempResult); } int pos = -1; for (int i = result.size() - 1; i >= 0; --i) { if (result[i] != 0) { pos = i; break; } } if (pos == -1) strRst = "0"; for (int i = pos; i >= 0; --i) strRst.push_back(result[i] + '0'); return 0; }
void PATH_INFO::init_base_path(std::string path) { if (!path.empty()) { char ch = path.at(path.length() - 1); if (ch != '/' && ch != '\\') { path.push_back('/'); } } //FILENAMES.insert(std::pair<std::string,std::string>("base_path", path)); FILENAMES["base_path"] = path; }
ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string& privs, const std::string& keygiven) { /* The user may have the +H umode on himself, but +H does not necessarily correspond * to the +H of m_hideoper. * However we only add the modewatcher when m_hideoper is loaded, so these * conditions (mw_added and the user being +H) together mean the user is a hidden oper. */ if (IS_OPER(user) && (!mw_added || !user->IsModeSet('H'))) privs.push_back('y'); return MOD_RES_PASSTHRU; }
void print_dictionary(std::ostream& os, const bnode<symbol>* root, std::string& s) { //std::cout << "traversing root " << root->value.count <<std::endl; if ((root->left == 0) && (root->right == 0)) { os << root->value.value << " " << s << std::endl; return; } else if ((root->left == 0) || (root->right == 0)) { std::cout << "incorrect tree" << std::endl; throw std::runtime_error("incorrect tree"); } // visit left '0' path s.push_back('0'); print_dictionary(os, root->left, s); s.resize(s.size() - 1); // visit right '1' path s.push_back('1'); print_dictionary(os, root->right, s); s.resize(s.size() - 1); } // print_dictionary