/// Read data and add terminating 0 void fsutil::read_file_data_ex(const char *filename, std::string& data, size_t align) { // Open stream std::ifstream stream(filename, std::ios::binary); if (!stream) throw std::runtime_error(std::string("cannot open file ") + filename); stream.unsetf(std::ios::skipws); // Determine stream size stream.seekg(0, std::ios::end); size_t size = stream.tellg(); stream.seekg(0); // Calc Padding size size_t padding_size = 0; if(align > 0) padding_size = align - size % align; // Load data data.resize(size + padding_size + 1); stream.read(&data.front(), static_cast<std::streamsize>(size)); // Padding data for(size_t offst = 0; offst < padding_size; ++offst) { *(&data.front() + size + offst) = padding_size; } // And add terminating data[size] = 0; }
long long toNum(std::string str, int type = 0) { int len = str.length(); long long ret = 0; if (len < 1) return 0; if (canBeNum(str) == false) return 0; std::stringstream ss; bool negative = false; if (str.front() == '-') { str.erase(0, 1); negative = true; len--; } else if (str.front() == '+') { str.erase(0, 1); len--; } switch (type) { case 0: if (len == 0) return 0; if (str.back() == 'h' || str.back() == 'H') { str.erase(len - 1, 1); ss << std::hex << str; ss >> ret; } else if (str.front() == '0' && len > 1)
std::string zusiPfadZuOsPfad(const std::string& zusiPfad, const std::string& osPfadUebergeordnet) { std::string result; if (zusiPfad.find('\\') == zusiPfad.npos && !osPfadUebergeordnet.empty()) { // Relativ zu uebergeordnetem Pfad if (zusiPfad.empty()) { return osPfadUebergeordnet; } result = osPfadUebergeordnet.substr(0, osPfadUebergeordnet.rfind('/')); } else { // Relativ zum Zusi-Datenverzeichnis result = getZusi3Datenpfad(); if (result.empty()) { return ""; } } if (result.back() == '\\' && zusiPfad.front() == '\\') { result.pop_back(); } else if (result.back() != '\\' && zusiPfad.front() != '\\') { result.push_back('\\'); } result += zusiPfad; return result; }
void ler_comando(std::string c, ABB &arv) { std::string aux; int x; while (!c.empty()){ if(c.front() == ' ') { c.erase(0,1); break; } else{ aux = aux + c.front(); c.erase(0,1); } } if (!c.empty()) { x = std::stoi (c, nullptr, 10); } if (aux == "ENESIMO") { std::cout << "O elemento na " << x << "ª posicao eh o: " << arv.enesimoElemento(x) << std::endl; } else if (aux == "POSICAO") { std::cout << "O elemento " << x << " esta na " << arv.posicao(x) << "ª posicao" << std::endl; } else if (aux == "MEDIANA") { std::cout << "A mediana da ABB eh o elemento: " << arv.mediana() << std::endl; } else if (aux == "CHEIA") { if (arv.ehCheia()) { std::cout << "A ABB eh cheia!" << std::endl; } else std::cout << "A ABB Nao eh cheia! " << std::endl; } else if (aux == "COMPLETA") { if (arv.ehCompleta()) { std::cout << "A ABB eh completa!" << std::endl; } else std::cout << "A ABB nao eh completa!" << std::endl; } else if (aux == "IMPRIMA") { std::cout << "Imprimindo ABB por nivel: " << arv.toString() << std::endl; } else if (aux == "REMOVA") { std::cout << "Removendo o elemento: " << x << " ..." << std::endl; arv.remocao(x); } }
/// Test if a name (parameter's or attribute's) belongs to m_source /// @param aName :: A name to test. bool FunctionGenerator::isSourceName(const std::string &aName) const { if (aName.empty()) { throw std::invalid_argument( "Parameter or attribute name cannot be empty string."); } return (aName.front() != 'f' || aName.find('.') == std::string::npos); }
URL::URL(const std::string& str) : query([&]() -> Segment { const auto hashPos = str.find('#'); const auto queryPos = str.find('?'); if (queryPos == std::string::npos || hashPos < queryPos) { return { hashPos != std::string::npos ? hashPos : str.size(), 0 }; } return { queryPos, (hashPos != std::string::npos ? hashPos : str.size()) - queryPos }; }()), scheme([&]() -> Segment { if (str.empty() || !isAlphaCharacter(str.front())) return { 0, 0 }; size_t schemeEnd = 0; while (schemeEnd < query.first && isSchemeCharacter(str[schemeEnd])) ++schemeEnd; return { 0, str[schemeEnd] == ':' ? schemeEnd : 0 }; }()), domain([&]() -> Segment { auto domainPos = scheme.first + scheme.second; while (domainPos < query.first && (str[domainPos] == ':' || str[domainPos] == '/')) { ++domainPos; } const bool isData = str.compare(scheme.first, scheme.second, "data") == 0; const auto endPos = str.find(isData ? ',' : '/', domainPos); return { domainPos, std::min(query.first, endPos) - domainPos }; }()), path([&]() -> Segment { auto pathPos = domain.first + domain.second; const bool isData = str.compare(scheme.first, scheme.second, "data") == 0; if (isData) { // Skip comma pathPos++; } return { pathPos, query.first - pathPos }; }()) { }
EdifyTokenString::EdifyTokenString(std::string str, Type type) : EdifyToken(EdifyTokenType::String), m_type(type) { switch (type) { case AlreadyQuoted: m_quoted = true; assert(str.size() >= 2); assert(str.front() == '"'); assert(str.back() == '"'); m_str = std::move(str); break; case NotQuoted: m_quoted = false; m_str = std::move(str); break; case MakeQuoted: m_quoted = true; std::string temp; escape(str, &temp); temp.insert(temp.begin(), '"'); temp.push_back('"'); m_str = std::move(str); break; } }
int countWays(std::string s) { if (s=="") return 1; if (memo.count(s)) return memo[s]; assert(s.front()=='('); int N=SZ(s), res=0, d=0; REP(i,N) { if (s[i]=='(') { ++d; continue; } --d; string t; if (i==N-1) { t = s.substr(1,i-1); } else { t = s.substr(1,i-1) + s.substr(min(N-1,i+1)); } res += countWays(t); if (d==0) break; } return memo[s] = res; }
static std::string repeat(std::string str, size_t n) { if(n == 0) { str.clear(); str.shrink_to_fit(); return str; } else if(n == 1 || str.empty()) { return str; } auto period = str.size(); if(period == 1) { str.append(n - 1, str.front()); return str; } str.reserve(period * n); size_t m = 2; for(; m < n; m *= 2) str += str; str.append(str.c_str(), (n - (m / 2)) * period); return str; }
Pothos::BlockRegistry::BlockRegistry(const std::string &path, const Callable &factory) { //check the path if (path.empty() or path.front() != '/') { poco_error_f1(Poco::Logger::get("Pothos.BlockRegistry"), "Invalid path: %s", path); return; } //parse the path PluginPath fullPath; try { fullPath = PluginPath("/blocks").join(path.substr(1)); } catch (const PluginPathError &) { poco_error_f1(Poco::Logger::get("Pothos.BlockRegistry"), "Invalid path: %s", path); return; } //check the factory if (factory.type(-1) == typeid(Block*) or factory.type(-1) == typeid(Topology*)) { //register PluginRegistry::add(fullPath, factory); } //otherwise report the error else { poco_error_f1(Poco::Logger::get("Pothos.BlockRegistry"), "Bad Factory, must return Block* or Topology*: %s", factory.toString()); } }
void ReadAttribute(char c) { if (buffer.empty()) { if (!IsWhitespace(c)) { if (c == '"' || c == '\'') Store(c); else { state = State::SkipTag; } } } else if (c == buffer.front()) { StoreLink(); ClearBuffer(); state = State::SkipTag; } else { Store(c); } }
std::string getOutputString(std::string numberString) { std::string lineString { }; if (numberString.size() && numberString.front() == '-') numberString.front() = digitOffset + 10; addSpace(numberString); for (unsigned int i = 0; i < allDigits[0].size(); i++) { for (char c : numberString) { lineString += allDigits[c - digitOffset][i] + " "; } lineString += "\n"; } return lineString; }
bool SaveToFile(const std::string& data, const std::wstring& path, bool take_backup) { if (data.empty()) return false; return SaveToFile((LPCVOID)&data.front(), data.size(), path, take_backup); }
void vfsHDD::ReadEntry(u64 block, std::string& name) { CHECK_ASSERTION(m_hdd_file.Seek(block * m_hdd_info.block_size + sizeof(vfsHDD_Entry)) != -1); name.resize(GetMaxNameLen()); m_hdd_file.Read(&name.front(), GetMaxNameLen()); }
void readInternal(std::string& value) { size_t size; visit(size); value.resize(size); mStore.read(&value.front(), size); }
irc_message_struct irc_message(std::string message) { if(!message.empty()) { irc_message_struct message_struct; auto space_pos = message.find(' ',0); if(message.front() == ':') { message_struct.prefix = message.substr(0, space_pos); message.erase(0,space_pos+1); } space_pos = message.find(' ',0); message_struct.command = message.substr(0, space_pos); message.erase(0,space_pos+1); message_struct.parameters = message; return message_struct; } return irc_message_struct(); }
void vfsHDD::ReadEntry(u64 block, vfsHDD_Entry& data, std::string& name) { m_hdd_file.Seek(block * m_hdd_info.block_size); m_hdd_file.Read(&data, sizeof(vfsHDD_Entry)); name.resize(GetMaxNameLen()); m_hdd_file.Read(&name.front(), GetMaxNameLen()); }
bool fortifiedString(const std::string & s) { if (isDigit(s)) return true ; linbox_check(!s.empty()); return s.front() == '\"' && s.back() == '\"' ; }
void snap::Excerpt::highlight_word(std::string w) { if (w.size() == 0 || w == "*" || w == "**") { return; } bool pre_wild_card = false; bool post_wild_card = false; if (w.front() == '*') { pre_wild_card = true; } if (w.back() == '*') { post_wild_card = true; } this -> search_strings.push_back(w); std::string w_trimmed = boost::algorithm::trim_copy_if(w, boost::algorithm::is_any_of("*")); std::transform(w_trimmed.begin(), w_trimmed.end(), w_trimmed.begin(), ::tolower); std::string lower_text(text); std::transform(lower_text.begin(), lower_text.end(), lower_text.begin(), ::tolower); int offset = 0; int left_shift = 24; int right_shift = 7; int current_pos = 0; while ((current_pos = lower_text.find(w_trimmed, current_pos)) != -1) { bool highlight = true; if (current_pos != 0 && !pre_wild_card && !(isspace(lower_text[current_pos-1]) || ispunct(lower_text[current_pos-1]))) { highlight = false; } if (current_pos + w_trimmed.length() != lower_text.length() && !post_wild_card && !(isspace(lower_text[current_pos + w_trimmed.length()]) || ispunct(lower_text[current_pos + w_trimmed.length()]))) { highlight = false; } if (highlight) { (this -> text).insert(current_pos + offset, "<span style=\"color:red\">"); offset += left_shift; (this -> text).insert(current_pos + w_trimmed.length() + offset, "</span>"); offset += right_shift; } current_pos += w_trimmed.size(); } }
// output string to console bool cmd_easteregg(BATB& batb, const std::string& input) { // ('input' is the whole command line typed) // if correct command typed, do easter egg // easter egg is PS1|reverse(PS1) if ( input.empty() ) return false; if ( input.front() != '|' ) return false; auto right = input.substr( 1 ); std::reverse( std::begin( right ), std::end( right ) ); for (auto i = std::begin( right ); i != std::end( right ); ++i) { if ( *i == '<' ) { *i = '>'; continue; } if ( *i == '>' ) { *i = '<'; continue; } if ( *i == '(' ) { *i = ')'; continue; } if ( *i == ')' ) { *i = '('; continue; } if ( *i == '[' ) { *i = ']'; continue; } if ( *i == ']' ) { *i = '['; continue; } if ( *i == '{' ) { *i = '}'; continue; } if ( *i == '}' ) { *i = '{'; continue; } } auto left = batb.run.console.getPS1(); if ( left == right ) { demo::al::demo_play( batb, file::static_data( "easteregg.mp3" ) ); return true; } return false; }
bool check() { CHECK(value.size() == 300); CHECK(value.front() == 'b' && value.back() == 'b'); CHECK(i_wanna_be_big[0] == 'k' && i_wanna_be_big[50] == 'k'); return true; }
std::string LLVMSymbolizer::DemangleName(const std::string &Name, const SymbolizableModule *ModInfo) { #if !defined(_MSC_VER) // We can spoil names of symbols with C linkage, so use an heuristic // approach to check if the name should be demangled. if (Name.substr(0, 2) == "_Z") { int status = 0; char *DemangledName = __cxa_demangle(Name.c_str(), nullptr, nullptr, &status); if (status != 0) return Name; std::string Result = DemangledName; free(DemangledName); return Result; } #else if (!Name.empty() && Name.front() == '?') { // Only do MSVC C++ demangling on symbols starting with '?'. char DemangledName[1024] = {0}; DWORD result = ::UnDecorateSymbolName( Name.c_str(), DemangledName, 1023, UNDNAME_NO_ACCESS_SPECIFIERS | // Strip public, private, protected UNDNAME_NO_ALLOCATION_LANGUAGE | // Strip __thiscall, __stdcall, etc UNDNAME_NO_THROW_SIGNATURES | // Strip throw() specifications UNDNAME_NO_MEMBER_TYPE | // Strip virtual, static, etc specifiers UNDNAME_NO_MS_KEYWORDS | // Strip all MS extension keywords UNDNAME_NO_FUNCTION_RETURNS); // Strip function return types return (result == 0) ? Name : std::string(DemangledName); } #endif if (ModInfo && ModInfo->isWin32Module()) return std::string(demanglePE32ExternCFunc(Name)); return Name; }
std::unique_ptr<CAS::AbstractArithmetic> BASICARITHSHARED_EXPORT Number_jmodule(const std::string &candidate) { if (candidate.size() != 1 && candidate.front() == '0') return nullptr; else { if (candidate.find_first_not_of("0123456789") != std::string::npos) return nullptr; else return make_unique<CAS::NumberArith>(CAS::Natural(candidate)); } }
Variable getVarOrObjectProperty(const Game& game, const std::string& str) { if ((str.size() > 2) && (str.front() == '|') && (str.back() == '|')) { return GameUtils::getProperty(game, str.substr(1, str.size() - 2)); } return Variable(str); }
//remove outer quotes if they exist static std::string unquote(const std::string &s) { if (s.size() > 2 and s.front() == '"' and s.back() == '"') { return s.substr(1, s.length()-2); } else return s; }
static bench::test_class_collection get_tests_by_name(const bench::test_class_collection & tests, const std::string & name) { // All tests chosen. if (name == "*") return tests; bench::test_class_collection chosen_tests; if (!name.empty()) { for (auto test : tests) { bool chosen = false; if (test->name == name) { chosen = true; } else if ((name.front() == '*') && (name.back() == '*')) { assert(name.size() >= 2); auto name_part = name.substr(1, name.size() - 2); if (test->name.find(name_part) != std::string::npos) chosen = true; } else if (name.front() == '*') { auto name_part = name.substr(1); if (test->name.size() >= name_part.size()) { auto test_name_part = test->name.substr(test->name.size() - name_part.size()); if (name_part == test_name_part) chosen = true; } } else if (name.back() == '*') { auto name_part = name.substr(0, name.size() - 1); auto test_name_part = test->name.substr(0, name.size() - 1); if (name_part == test_name_part) chosen = true; } if (chosen) chosen_tests.push_back(test); } } if (chosen_tests.empty()) throw std::runtime_error("Invalid test name: " + name); return chosen_tests; }
inline std::string changeFileExtension(const std::string &file_path, const std::string &new_ext) { assert(!(new_ext.empty() || new_ext.front() == '.')); return file_path + '.' + new_ext; //size_t slash_pos = file_path.find_last_of("/\\"); //return file_path.substr(0, std::min( // file_path.length(), file_path.find_last_of('.', slash_pos == std::string::npos ? 0 : slash_pos) // )) + '.' + new_ext; }
void MainController::onCharactersEntered(std::string chars) { int upCase = ::toupper(static_cast<int>(chars.front() & 0xffffffff)); if (upCase == 'O') _sample.toggleObserving(); if (upCase == 'W') _sample.toggleWireframe(); }
std::string SancusModuleCreator::fixSymbolName(const std::string& name) { assert(!name.empty() && "Empty symbol name?"); // remove the \01 prefix that is used to mangle __asm declarations if (name.front() == '\01') return name.substr(1); else return name; }
std::shared_ptr<fs::device_base> fs::get_virtual_device(const std::string& path) { // Every virtual device path must have "//" at the beginning if (path.size() > 2 && reinterpret_cast<const u16&>(path.front()) == "//"_u16) { return get_device_manager().get_device(path); } return nullptr; }