void DepositFileSource::insertRateIntoMap(std::string tenorStr, double liborRate, Market market, map<long, double>* depositRateMap, map<long, double>* overnightRateMap){ date startDate = dateUtil::dayRollAdjust(dateUtil::getToday(),enums::Following,market.getMarketEnum()); char tenorUnit = *tenorStr.rbegin(); int tenorNum = std::stoi(tenorStr.substr(0,tenorStr.size()-1)); // 2 if (tenorUnit != 'D') startDate = dateUtil::getBizDateOffSet(startDate,market.getBusinessDaysAfterSpot(enums::SWAP),market.getMarketEnum()); // day after spot adjust long JDN = dateUtil::getEndDate(startDate,tenorNum, market.getDayRollCashConvention(), market.getMarketEnum(), dateUtil::getDateUnit(tenorUnit)).getJudianDayNumber(); if (tenorUnit == 'D'){ overnightRateMap->insert(pair<long, double>(tenorNum, liborRate)); cout << market.getNameString()<< " -> tenor[" << tenorStr <<"], accrual start["<<startDate.toString()<<"], duration [" <<tenorNum <<"], deposit rate["<< liborRate << "]"<<endl; }else{ date accrualEndDate(JDN); depositRateMap->insert(pair<long, double>(JDN, liborRate)); cout << market.getNameString()<< " -> tenor[" << tenorStr<<"], accrual start["<<startDate.toString()<<"], accrual end[" <<accrualEndDate.toString() <<"], deposit rate["<< liborRate << "]"<<endl; } }
//----------------------------------------------------------------------- void ChopTrailingChars( std::string& str, s8 inbyChar) { u32 udwNumCharsToRemove = 0; for(std::string::reverse_iterator it = str.rbegin(); it != str.rend(); ++it) { if((*it) == inbyChar) { ++udwNumCharsToRemove; } else { break; } } if(udwNumCharsToRemove > 0) { Chop(str, udwNumCharsToRemove); } }
std::string Builder::Get_Directory_Of_File(std::string const& path){ std::string return_value = "/"; bool slash_found = false; for (auto it = path.rbegin(); it != path.rend(); ++it){ if (!slash_found){ if (*it == '/'){ slash_found = true; } }else{ return_value = *it + return_value; } } return return_value; }
size_t removePseudoAsterisks(std::string & phrase) { size_t pseudoAsterisksCount = 0; if( !phrase.empty() ) { std::string::reverse_iterator rit = phrase.rbegin(); const char specialPseudoAsteriskCharacter = 127; while( rit != phrase.rend() && *rit == specialPseudoAsteriskCharacter ) { pseudoAsterisksCount++; ++rit; } } phrase = phrase.substr(0, phrase.length() - pseudoAsterisksCount); return pseudoAsterisksCount; }
/** * Remove ':' at the end of the path, split and remove empty elements. */ std::vector<std::string> prep_path(std::string path) { // If path ends with colon, remove it. if (*path.rbegin() == ':') { path = path.substr(0, path.size() - 1); } // split path std::vector<std::string> path_splited = split(path, '/'); // remove empty elements for (int i = 0; i < path_splited.size(); i++) { if (path_splited[i] == "") { path_splited.erase(path_splited.begin() + i); i = 0; } } return path_splited; }
std::string get_file_extension(const std::string& filename) { std::string::const_reverse_iterator rit; std::string result; // search for the first dot from the end of the string for (rit=filename.rbegin(); rit!=filename.rend(); ++rit) { if (is_path_separator(*rit)) return result; else if (*rit == '.') break; } if (rit != filename.rend()) { std::copy(std::string::const_iterator(rit.base()), filename.end(), std::back_inserter(result)); } return result; }
std::string Relais::write_channels(std::string channels) { // int input_int=0; // std::string::iterator i; // int counter=0; // for (i=channels.begin(); i!=channels.end(); i++) // { // counter++; // if (*i!= '0'&&*i!= '1') return "Input error"; // else if (*i= '1') input_int+= std::pow(2,counter-1); // // std::cout<<std::pow(2,counter-1)<<" "<< std::hex<<input_int<<std::endl; // } std::string tmp(channels.rbegin(),channels.rend()); //Reverse to keep the endian straight! channels = tmp; this->channel_bench = std::bitset<8>(channels); std::string s; s.clear(); s = "\xf0"; s += static_cast<char>(this->channel_bench.to_ulong()); std::string answer=this->inputOutput(s); std::bitset<8> answerBS; answerBS = (long unsigned int) answer[0]; if(!answer.c_str()==static_cast<char>(this->channel_bench.to_ulong())) std::cout << "Relais: SET ERROR: Relais answered" << answer << " (" << answerBS << ")" << std::endl; std::bitset<8> helper; helper.reset(); std::string debugString; debugString.clear(); for (int i = 0; i < s.size(); i++) { helper = static_cast<long unsigned int>(s[i]); debugString += helper.to_string(); } std::cout << "Relais: SET COMMAND: " << s << " = " << debugString << " (" << channels << " = " << channel_bench.to_string() << " = " << static_cast<char>(this->channel_bench.to_ulong()) << ")" << std::endl; //return read_channels(); return channel_bench.to_string(); }
inline bool fast_getline(std::string& line, FILE* input = stdin) { line.clear(); static const size_t max_buffer = 65536; char buffer[max_buffer]; bool done = false; while (!done) { if (!fgets(buffer, max_buffer, input)) { if (!line.size()) { return false; } else { done = true; } } line += buffer; if (*line.rbegin() == '\n') { done = true; } } return true; }
void TeaSafe::addFile(std::string const &path) { StateLock lock(m_stateMutex); std::string thePath(path); char ch = *path.rbegin(); // file entries with trailing slash should throw if (ch == '/') { throw TeaSafeException(TeaSafeError::IllegalFilename); } SharedTeaSafeFolder parentEntry = doGetParentTeaSafeFolder(thePath); if (!parentEntry) { throw TeaSafeException(TeaSafeError::NotFound); } // throw if already exists throwIfAlreadyExists(path); parentEntry->addTeaSafeFile(boost::filesystem::path(thePath).filename().string()); }
static void DumpStringToStreamWithNewline (Stream &strm, const std::string &s, bool add_newline_if_empty) { bool add_newline = false; if (s.empty()) { add_newline = add_newline_if_empty; } else { // We already checked for empty above, now make sure there is a newline // in the error, and if there isn't one, add one. strm.Write(s.c_str(), s.size()); const char last_char = *s.rbegin(); add_newline = last_char != '\n' && last_char != '\r'; } if (add_newline) strm.EOL(); }
void TeaSafe::addFolder(std::string const &path) const { StateLock lock(m_stateMutex); std::string thePath(path); char ch = *path.rbegin(); // ignore trailing slash if (ch == '/') { std::string(path.begin(), path.end() - 1).swap(thePath); } SharedTeaSafeFolder parentEntry = doGetParentTeaSafeFolder(thePath); if (!parentEntry) { throw TeaSafeException(TeaSafeError::NotFound); } // throw if already exists throwIfAlreadyExists(path); parentEntry->addTeaSafeFolder(boost::filesystem::path(thePath).filename().string()); }
static void generate_permutations(const std::string& i_str, StringSet& permutations) { permutations.insert(i_str); bool starts_with_wildcard(char_to_modifier(*i_str.begin()) != InvalidModifier), ends_with_wildcard(char_to_modifier(*i_str.rbegin()) != InvalidModifier); if (!starts_with_wildcard && !ends_with_wildcard) { return; } else { if (starts_with_wildcard) { generate_permutations(i_str.substr(1), permutations); // _xxxx -> xxxx } if (ends_with_wildcard) { generate_permutations(i_str.substr(0, i_str.size()-1), permutations); // xxxx_ -> xxxx } } }
void get_next(){ bool comment; do{ if(!std::getline(input, next_line)){ has_next = false; } else{ comment = false; next_line_idx++; // strip trailing carriage return, if any if(next_line.length() > 0 && *(next_line.rbegin()) == '\r') next_line.resize(next_line.size()-1); // convert to lowercase strlower(next_line); // Append a space, to catch blank comment lines (e.g. "c\n") that would otherwise not meet // the MCNP comment card spec ("a C anywhere in columns 1-5 followed by at least one blank.") // I have seen lines like "c\n" or " c\n" as complete comment cards in practice, so MCNP must // accept them. next_line.append(" "); // We want to find "c " within the first five // columns, but not if the c has anything other than a space before it. size_t idx = next_line.find("c "); if( idx < 5 ){ if( idx == 0 || next_line.at(idx-1) == ' '){ comment = true; } } } } while( has_next && comment ); // iterate until next_line is not a comment line. }
HostAndPort parseName(std::string const& str) { // Attempt to find the first and last non-whitespace auto const find_whitespace = std::bind ( &std::isspace <std::string::value_type>, std::placeholders::_1, std::locale ()); auto host_first = std::find_if_not ( str.begin (), str.end (), find_whitespace); auto port_last = std::find_if_not ( str.rbegin (), str.rend(), find_whitespace).base(); // This should only happen for all-whitespace strings if (host_first >= port_last) return std::make_pair(std::string (), std::string ()); // Attempt to find the first and last valid port separators auto const find_port_separator = [](char const c) -> bool { if (std::isspace (c)) return true; if (c == ':') return true; return false; }; auto host_last = std::find_if ( host_first, port_last, find_port_separator); auto port_first = std::find_if_not ( host_last, port_last, find_port_separator); return make_pair ( std::string (host_first, host_last), std::string (port_first, port_last)); }
void TeaSafe::removeFolder(std::string const &path, FolderRemovalType const &removalType) { StateLock lock(m_stateMutex); std::string thePath(path); char ch = *path.rbegin(); // ignore trailing slash, but only if folder type // an entry of file type should never have a trailing // slash and is allowed to fail in this case if (ch == '/') { std::string(path.begin(), path.end() - 1).swap(thePath); } SharedTeaSafeFolder parentEntry = doGetParentTeaSafeFolder(thePath); if (!parentEntry) { throw TeaSafeException(TeaSafeError::NotFound); } SharedEntryInfo childInfo = parentEntry->getEntryInfo(boost::filesystem::path(thePath).filename().string()); if (!childInfo) { throw TeaSafeException(TeaSafeError::NotFound); } if (childInfo->type() == EntryType::FileType) { throw TeaSafeException(TeaSafeError::NotFound); } if (removalType == FolderRemovalType::MustBeEmpty) { TeaSafeFolder childEntry = parentEntry->getTeaSafeFolder(boost::filesystem::path(thePath).filename().string()); if (!childEntry.listAllEntries().empty()) { throw TeaSafeException(TeaSafeError::FolderNotEmpty); } } parentEntry->removeTeaSafeFolder(boost::filesystem::path(thePath).filename().string()); // also remove entry from parent cache this->removeDeletedParentFromCache(boost::filesystem::path(thePath)); }
bool SyntaxTree::wildCardMatch(std::string name, std::string search_string) { // Assume that an empty string matches anything if (search_string == "") return true; // transform to lower for case insenstive matching std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))std::toupper); std::transform(search_string.begin(), search_string.end(), search_string.begin(), (int(*)(int))std::toupper); // exact match! if (search_string.find("*") == std::string::npos) return search_string == name; // wildcard std::vector<std::string> tokens; MooseUtils::tokenize(search_string, tokens, 1, "*"); size_t pos = 0; for (unsigned int i=0; i<tokens.size() && pos != std::string::npos; ++i) { pos = name.find(tokens[i], pos); // See if we have a leading wildcard if (search_string[0] != '*' && i == 0 && pos != 0) return false; } if (pos != std::string::npos && tokens.size() > 0) { // Now see if we have a trailing wildcard size_t last_token_length = tokens.back().length(); if (*search_string.rbegin() == '*' || pos == name.size() - last_token_length) return true; else return false; } else return false; }
int32 Chunk::FindSubChunkOffset(std::string name) { // Reverse the name name = std::string(name.rbegin(), name.rend()); if (name.size() != 4) return -1; FILE* stream = GetStream(); uint32 matched = 0; while (uint32(ftell(stream)) < Utils::Size(stream)) { char b = 0; if (fread(&b, sizeof(char), 1, stream) != 1 || b != name[matched]) matched = 0; else ++matched; if (matched == 4) return ftell(stream) - 4; } return -1; }
void CoreFS::addFile(std::string const &path) { StateLock lock(m_stateMutex); auto thePath(path); char ch = *path.rbegin(); // file entries with trailing slash should throw if (ch == '/') { throw KnoxCryptException(KnoxCryptError::IllegalFilename); } auto parentEntry(doGetParentCompoundFolder(thePath)); if (!parentEntry) { throw KnoxCryptException(KnoxCryptError::NotFound); } // throw if already exists throwIfAlreadyExists(path); parentEntry->addFile(boost::filesystem::path(thePath).filename().string()); }
int32 Chunk::FindSubChunkOffset(std::string name) { // Reverse the name name = std::string(name.rbegin(), name.rend()); if (name.size() != 4) return -1; Stream* stream = GetStream(); uint32 matched = 0; while (stream->GetPos() < stream->GetSize()) { char b = stream->Read<char>(); if (b != name[matched]) matched = 0; else ++matched; if (matched == 4) return stream->GetPos() - 4; } return -1; }
bool connection_finder::host_key_info::validate(const std::string &secret, std::string client_host) { if (client_host != host) { // we want to see if client_host is a subdomain of host. To do that, // we want to do a reverse string match on ".#{client_host}" to host. // if their ends match that, then we're good. if (client_host.length() <= host.length()) // but first, if client_host isn't longer than host, return false; // bail. std::string prefixed_host = "."; prefixed_host += host; if (!std::equal(prefixed_host.rbegin(), prefixed_host.rend(), client_host.rbegin())) return false; } // now check if the hash in question is actually real. (saved for last because it's the more expensive op) std::string compare = secret; compare += ":" + timestamp + ":" + host; std::string real_hash = sha1_str(compare); return real_hash == hash; }
void MsgScrollNewUI::display_string(std::string s, Font *f, bool include_on_map_window) { if(s.empty()) return; bool has_trailing_whitespace = (!trailing_whitespace.empty()); s = trailing_whitespace + s; trailing_whitespace.clear(); std::string::reverse_iterator iter; uint16 i; for(i=0,iter=s.rbegin();iter != s.rend();iter++,i++) { char c = *iter; if(c != '\t' && c != '\n') break; } if(i>0) { trailing_whitespace = s.substr(s.length()-i,i); s = s.substr(0, s.length()-i); } if(!s.empty()) { if(position>0 && position == msg_buf.size()) { if(!has_trailing_whitespace) position--; else { position += count_empty_lines(s) - 1; } } timer = new TimedCallback(this, NULL, 2000); MsgScroll::display_string(s, f, include_on_map_window); } }
// BASE64 解码. inline std::string base64_decode(std::string str) { static int shrik_map[] = {0, 2, 1}; // 移除尾部的 == 后面的 \r\n\r\n while ( boost::is_any_of("\r\n.")(* str.rbegin())) str.erase(str.length()-1); // 统计结尾的 = 数目 std::size_t num = 0; if (str.find_last_of("=")!=std::string::npos) num = str.find_last_of("=") - str.find_first_of("=") + 1; BOOST_ASSERT(num < 3); std::size_t num_to_shrik = shrik_map[num]; // convert base64 characters to binary values std::string result(base64decodeIterator(str.c_str()), base64decodeIterator(str.c_str() + str.length())); result.erase(result.length() -1 - num_to_shrik, num_to_shrik); return result; }
void StringTokenizer::trim(std::string& token) { std::string::size_type front = 0; std::string::size_type back = 0; std::string::size_type length = token.length(); std::string::const_iterator tIt = token.begin(); std::string::const_iterator tEnd = token.end(); for (; tIt != tEnd; ++tIt, ++front) { if (!Ascii::isSpace(*tIt)) break; } if (tIt != tEnd) { std::string::const_reverse_iterator tRit = token.rbegin(); std::string::const_reverse_iterator tRend = token.rend(); for (; tRit != tRend; ++tRit, ++back) { if (!Ascii::isSpace(*tRit)) break; } } token = token.substr(front, length - back - front); }
/** Refactored by Brain, Jun 2009. Much faster with some clever O(1) array * lookups and pointer maths. */ long InspIRCd::Duration(const std::string &str) { unsigned char multiplier = 0; long total = 0; long times = 1; long subtotal = 0; /* Iterate each item in the string, looking for number or multiplier */ for (std::string::const_reverse_iterator i = str.rbegin(); i != str.rend(); ++i) { /* Found a number, queue it onto the current number */ if ((*i >= '0') && (*i <= '9')) { subtotal = subtotal + ((*i - '0') * times); times = times * 10; } else { /* Found something thats not a number, find out how much * it multiplies the built up number by, multiply the total * and reset the built up number. */ if (subtotal) total += subtotal * duration_multi[multiplier]; /* Next subtotal please */ subtotal = 0; multiplier = *i; times = 1; } } if (multiplier) { total += subtotal * duration_multi[multiplier]; subtotal = 0; } /* Any trailing values built up are treated as raw seconds */ return total + subtotal; }
void _join_two_win32(std::string &result_drive, std::string &result_path, const std::string &rpath) { std::string pdrive; std::string ppath; std::tie(pdrive, ppath) = _splitdrive_win32(rpath); if (!ppath.empty() && (ppath[0] == sep || ppath[0] == altsep)) { if (!pdrive.empty() && result_drive.empty()) { result_drive = pdrive; } result_path = ppath; return; } else if (!pdrive.empty() && pdrive != result_drive) { std::string lower_pdrive = pdrive; std::string lower_lpath = result_drive; std::transform(lower_pdrive.begin(), lower_pdrive.end(), lower_pdrive.begin(), std::tolower); std::transform(lower_lpath.begin(), lower_lpath.end(), lower_lpath.begin(), std::tolower); if (lower_pdrive != lower_lpath) { result_drive = pdrive; result_path = ppath; return; } result_drive = pdrive; } if (!result_path.empty()) { auto c = *(result_path.rbegin()); if (c != sep && c != altsep) { result_path += sep; } result_path += ppath; } }
std::string url_cleanup(std::string pattern) { LLStringUtil::trim(pattern); S32 length = pattern.length(); S32 position = 0; std::string::reverse_iterator it = pattern.rbegin(); ++it; // skip last char, might be '/' ++position; for (; it < pattern.rend(); ++it) { char c = *it; if (c == '/') { // found second to last '/' S32 desired_length = length - position; LLStringUtil::truncate(pattern, desired_length); break; } ++position; } return pattern; }
std::string get_file_title(const std::string& filename) { std::string::const_reverse_iterator rit; std::string::const_iterator last_dot = filename.end(); std::string result; for (rit=filename.rbegin(); rit!=filename.rend(); ++rit) { if (is_path_separator(*rit)) break; else if (*rit == '.' && last_dot == filename.end()) last_dot = rit.base()-1; } for (std::string::const_iterator it(rit.base()); it!=filename.end(); ++it) { if (it == last_dot) break; else result.push_back(*it); } return result; }
void CoreFS::addFolder(std::string const &path) const { StateLock lock(m_stateMutex); auto thePath(path); char ch = *path.rbegin(); // ignore trailing slash if (ch == '/') { std::string(path.begin(), path.end() - 1).swap(thePath); } auto parentEntry(doGetParentCompoundFolder(thePath)); if (!parentEntry) { throw KnoxCryptException(KnoxCryptError::NotFound); } // throw if already exists throwIfAlreadyExists(path); parentEntry->addFolder(boost::filesystem::path(thePath).filename().string()); parentEntry->getCompoundFolder()->getStream()->close(); }
std::string trim(std::string s) { for (std::string::reverse_iterator i = s.rbegin(); i != s.rend(); ) { char c = *i++; if (c == '\n' || c == '\r' || c == ' ' || c == '\t') s.erase(s.size()-1); else break; } // also trim beginning whitespace int first_relevant = -1; for (int i = 0; i < s.size(); ++i) if (!(s[i] == '\n' || s[i] == '\r' || s[i] == ' ' || s[i] == '\t')) { first_relevant = i; break; } if (first_relevant != -1) s = s.substr(first_relevant); return s; }
std::vector<std::string> StringHelper::Split(const std::string& src, char deli) { std::vector<std::string> res; size_t p = 0, q; while (p < src.length()) { if ((q = src.substr(p).find(deli)) != std::string::npos) { res.push_back(src.substr(p, q)); p += q + 1; } else { res.push_back(src.substr(p)); p = src.length(); } } if (*src.rbegin() == deli) { res.push_back(""); } return res; }