//! Julian day. Feb29 is never counted, even in leap years // expects range of 1-365 void julian_no_leap(const string_type& s, const string_type& e){ typedef gregorian::gregorian_calendar calendar; const unsigned short year = 2001; // Non-leap year unsigned short sm=1; int sd=0; sd = lexical_cast<int>(s.substr(1)); // skip 'J' while(sd >= calendar::end_of_month_day(year,sm)){ sd -= calendar::end_of_month_day(year,sm++); } unsigned short em=1; int ed=0; ed = lexical_cast<int>(e.substr(1)); // skip 'J' while(ed > calendar::end_of_month_day(year,em)){ ed -= calendar::end_of_month_day(year,em++); } dst_calc_rules_ = shared_ptr<dst_calc_rule>( new partial_date_dst_rule( partial_date_dst_rule::start_rule( sd, static_cast<date_time::months_of_year>(sm)), partial_date_dst_rule::end_rule( ed, static_cast<date_time::months_of_year>(em)) ) ); }
void parse_format(const string_type & format_str) { typedef typename string_type::size_type size_type; size_type msg_idx = format_str.find('%'); if ( msg_idx != string_type::npos) { m_prefix = format_str.substr(0, msg_idx); m_suffix = format_str.substr( msg_idx + 1); } else // no suffix m_prefix = format_str; }
/** @brief sets the format string: what should be before, and what after the original message, separated by "|" Example: \n "[%idx%] |\n" - this writes "[%idx%] " before the message, and "\n" after the message If "|" is not present, the whole message is prepended to the message */ void format(const string_type & format_str) { m_format_str = format_str; typename string_type::size_type idx = format_str.find('|'); string_type before, after; if ( idx != string_type::npos) { before = format_str.substr(0, idx); after = format_str.substr(idx + 1); } else before = format_str; format( before, after); };
void extract( string_type const & data, string_type & name, string_type & value, basic_cookie<Tag> & c ) { std::size_t pos = data.find( string_traits_type::convert('=') ); name = data.substr( 0,pos ); if ( pos != string_type::npos ) { value = data.substr( pos+1 ); } if ( !value.empty() ) { if ( *value.begin() == '"' && *value.rbegin() != '"' ) { value = name + string_traits_type::convert("=") + value; return; } boost::trim_if( value, boost::is_any_of( string_traits_type::convert("\"") ) ); } set_value( name, value, c ); name.clear(); value.clear(); }
int CCommonFnc::BYTE_ConvertFromHexStringToArray(string_type hexaString, BYTE* pArray, DWORD* pbArrayLen) { int status = STAT_OK; DWORD pos = 0; DWORD pos2 = 0; string_type hexNum; DWORD num; BYTE* pTempArray = NULL; DWORD tempArrayPos = 0; // EAT SPACES //hexaString.TrimLeft(); hexaString.TrimRight(); hexaString.erase(hexaString.find_last_not_of(_CONV(" ")) + 1); size_t startpos = hexaString.find_first_not_of(_CONV(" ")); if (string_type::npos != startpos) { hexaString = hexaString.substr(startpos); } hexaString += _CONV(" "); hexaString.length(); if (status == STAT_OK) { pTempArray = new BYTE[hexaString.length()]; memset(pTempArray, 0, hexaString.length()); pos = pos2 = 0; /*while ((pos = hexaString.Find(' ', pos2)) != -1) { hexNum = hexaString.Mid(pos2, pos - pos2); hexNum.TrimLeft(); hexNum.TrimRight(); if (hexNum.GetLength() > 0) { num = strtol((LPCTSTR) hexNum, NULL, 16); if (num == 0xFF) pTempArray[tempArrayPos] = 0xFF; else pTempArray[tempArrayPos] = (BYTE) num & 0xFF; tempArrayPos++; } pos2 = pos + 1; }*/ while ((pos = hexaString.find(' ', pos2)) != string_type::npos) { hexNum = hexaString.substr((pos2, pos - pos2)); hexNum.erase(hexNum.find_last_not_of(_CONV(" ")) + 1); size_t startpos2 = hexNum.find_first_not_of(_CONV(" ")); if (string_type::npos != startpos2) { hexNum = hexNum.substr(startpos2); } if (hexNum.length() > 0) { num = type_to_int((LPCTSTR)hexNum.c_str(), NULL, 16); if (num == 0xFF) pTempArray[tempArrayPos] = 0xFF; else pTempArray[tempArrayPos] = (BYTE)num & 0xFF; tempArrayPos++; } pos2 = pos + 1; } if (tempArrayPos > *pbArrayLen) { status = STAT_NOT_ENOUGHT_MEMORY; } else { memcpy(pArray, pTempArray, tempArrayPos); } *pbArrayLen = tempArrayPos; if (pTempArray) delete[] pTempArray; } return status; }