static std::vector<std::string> innerTypesOf(const std::string &t) { std::vector<std::string> rc; std::string::size_type pos = t.find('<'); if (pos == std::string::npos) return rc; // exclude special values like "<Value unavailable error>" if (pos == 0) return rc; // exclude untyped member in the form of class::<untyped> if (pos >= 2 && t.at(pos - 1) == ':' && t.at(pos - 2) == ':') return rc; rc.reserve(5); const std::string::size_type size = t.size(); // Record all elements of level 1 to work correctly for // 'std::map<std::basic_string< .. > >' unsigned level = 0; std::string::size_type start = 0; for ( ; pos < size ; pos++) { const char c = t.at(pos); switch (c) { case '<': if (++level == 1) start = pos + 1; break; case '>': if (--level == 0) { // last element std::string innerType = t.substr(start, pos - start); trimFront(innerType); trimBack(innerType); rc.push_back(innerType); return rc; } break; case ',': if (level == 1) { // std::map<a, b>: start anew at ','. std::string innerType = t.substr(start, pos - start); trimFront(innerType); trimBack(innerType); rc.push_back(innerType); start = pos + 1; } break; } } return rc; }
PyType PyType::lookupType(const std::string &typeNameIn, ULONG64 module) { if (debuggingTypeEnabled()) DebugPrint() << "lookup type '" << typeNameIn << "'"; std::string typeName = typeNameIn; trimBack(typeName); trimFront(typeName); if (isPointerType(typeName) || isArrayType(typeName)) return PyType(0, 0, typeName); if (typeName.find("enum ") == 0) typeName.erase(0, 5); if (endsWith(typeName, " const")) typeName.erase(typeName.length() - 6); if (typeName == "__int64" || typeName == "unsigned __int64") typeName.erase(typeName.find("__"), 2); const static std::regex typeNameRE("^[a-zA-Z_][a-zA-Z0-9_]*!?[a-zA-Z0-9_<>:, \\*\\&\\[\\]]*$"); if (!std::regex_match(typeName, typeNameRE)) return PyType(); CIDebugSymbols *symbols = ExtensionCommandContext::instance()->symbols(); ULONG typeId; HRESULT result = S_FALSE; if (module != 0 && !isIntegralType(typeName) && !isFloatType(typeName)) result = symbols->GetTypeId(module, typeName.c_str(), &typeId); if (FAILED(result) || result == S_FALSE) result = symbols->GetSymbolTypeId(typeName.c_str(), &typeId, &module); if (FAILED(result)) return createUnresolvedType(typeName); return PyType(module, typeId, typeName); }
bool SemiExp::get(bool clear) { if(clear) toks.clear(); std::string tok; do { if(pToker->isFileEnd()) { if(length() > 0) return true; return false; } tok = pToker->getTok(); if(Verbose) { if(tok != "\n") std::cout << "\n--tok=" << tok << std::endl; else std::cout << "\n--tok=newline\n"; } if(tok != "\n" || doReturnNewLines) toks.push_back(tok); } while(!isTerminator(tok)); trimFront(); return true; }
void simplify(std::string &s) { trimFront(s); trimBack(s); if (s.empty()) return; // 1) All blanks const std::string::size_type size1 = s.size(); std::string::size_type pos = 0; for ( ; pos < size1; pos++) if (std::isspace(s.at(pos))) s[pos] = ' '; // 2) Simplify for (pos = 0; pos < s.size(); ) { std::string::size_type blankpos = s.find(' ', pos); if (blankpos == std::string::npos) break; std::string::size_type tokenpos = blankpos + 1; while (tokenpos < s.size() && s.at(tokenpos) == ' ') tokenpos++; if (tokenpos - blankpos > 1) s.erase(blankpos, tokenpos - blankpos - 1); pos = blankpos + 1; } }
MemTrieNode* TrieInfixNode::insert(bytesConstRef _key, std::string const& _value) { assert(_value.size()); mark(); if (contains(_key)) { m_next = m_next->insert(_key.cropped(m_ext.size()), _value); return this; } else { unsigned prefix = commonPrefix(_key, m_ext); if (prefix) { // one infix becomes two infixes, then insert into the second // instead of pop_front()... trimFront(m_ext, prefix); return new TrieInfixNode(_key.cropped(0, prefix), insert(_key.cropped(prefix), _value)); } else { // split here. auto f = m_ext[0]; trimFront(m_ext, 1); MemTrieNode* n = m_ext.empty() ? m_next : this; if (n != this) { m_next = nullptr; delete this; } TrieBranchNode* ret = new TrieBranchNode(f, n); ret->insert(_key, _value); return ret; } } }
// Simplify: replace tabs, find all occurrences // of 2 blanks, check further up for blanks and remove that bit. QByteArray simplify(const QByteArray &inIn) { if (inIn.isEmpty()) return inIn; QByteArray in = trimFront(trimBack(inIn)); in.replace('\t', ' '); in.replace('\n', ' '); in.replace('\r', ' '); const QByteArray twoBlanks = " "; while (true) { const int pos = in.indexOf(twoBlanks); if (pos != -1) { const int size = in.size(); int endPos = pos + twoBlanks.size(); for ( ; endPos < size && in.at(endPos) == ' '; endPos++) ; in.remove(pos + 1, endPos - pos - 1); } else { break; } } return in; }
string Parser::trim(string str){ return trimEnd(trimFront(str)); }