예제 #1
0
//! Converts escape sequences to the corresponding characters
void char_constants< char >::translate_escape_sequences(string_type& str)
{
    using namespace std; // to make sure we can use C functions unqualified

    string_type::iterator it = str.begin();
    while (it != str.end())
    {
        it = std::find(it, str.end(), '\\');
        if (std::distance(it, str.end()) >= 2)
        {
            it = str.erase(it);
            switch (*it)
            {
            case 'n':
                *it = '\n'; break;
            case 'r':
                *it = '\r'; break;
            case 'a':
                *it = '\a'; break;
            case '\\':
                ++it; break;
            case 't':
                *it = '\t'; break;
            case 'b':
                *it = '\b'; break;
            case 'x':
                {
                    string_type::iterator b = it;
                    if (std::distance(++b, str.end()) >= 2)
                    {
                        char_type c1 = *b++, c2 = *b++;
                        if (isxdigit(c1) && isxdigit(c2))
                        {
                            *it++ = char_type((to_number(c1) << 4) | to_number(c2));
                            it = str.erase(it, b);
                        }
                    }
                    break;
                }
            default:
                {
                    if (*it >= '0' && *it <= '7')
                    {
                        string_type::iterator b = it;
                        int c = (*b++) - '0';
                        if (*b >= '0' && *b <= '7')
                            c = c * 8 + (*b++) - '0';
                        if (*b >= '0' && *b <= '7')
                            c = c * 8 + (*b++) - '0';

                        *it++ = char_type(c);
                        it = str.erase(it, b);
                    }
                    break;
                }
            }
        }
    }
}
예제 #2
0
			static std::deque<string_type> tokenize(string_type input, string_type br)
			{
				typename string_type::iterator a,b,c;
				std::deque<string_type> tokens;

				// std::cerr << "Tokenising string=" << input << " break=" << br << std::endl;

				while ( input.length() )
				{
					a = input.begin();
					c = input.end();
					typename string_type::size_type e = input.find(br);

					if ( e != string_type::npos )
					{
						b = a+e;
						tokens.push_back(string_type(a,b));
						input = string_type(b+br.length(),c);
					}
					else
					{
						tokens.push_back(input);
						input = string_type();
					}

					// std::cerr << "Pushed token " << tokens.back() << " input now " << input << std::endl;
				}

				return tokens;
			}
 void put_string(iter_type& oi, const string_type& s1) const
 {
   typename string_type::const_iterator si,end;
   for (si=s1.begin(), end=s1.end(); si!=end; si++, oi++) {
     *oi = *si;
   }
 }
예제 #4
0
 template<class manipulator, class parser_type> void set_and_configure(manipulator & manip, const string_type & name, parser_type parser) {
     // need to parse string
     string_type prev ;
     bool parsing_params = false;
     string_type params;
     string_type stripped_str;
     for ( typename string_type::const_iterator b = name.begin(), e = name.end(); b != e; ++b) {
         if ( (*b == '(') && !parsing_params) {
             if ( parser.has_manipulator_name() ) {
                 parsing_params = true;
                 params.clear();
             }
         }
         else if ( (*b == ')') && parsing_params) {
             BOOST_ASSERT ( parser.has_manipulator_name() );
             manip.configure_inner( parser.get_manipulator_name(), params);
             parser.clear();
             parsing_params = false;
         }
         else {
             if ( parsing_params)
                 params += *b;
             else {
                 stripped_str += *b;
                 parser.add( *b);
             }
         }  
     }
     manip.string( stripped_str);
 }
예제 #5
0
    OutputIterator format
    (
        OutputIterator out
      , const string_type &fmt
      , regex_constants::match_flag_type flags = regex_constants::format_default
    ) const
    {
        detail::results_traits<char_type> traits;
        typename string_type::const_iterator cur = fmt.begin(), end = fmt.end();

        if(0 != (regex_constants::format_literal & flags))
        {
            out = std::copy(cur, end, out);
        }
        else while(cur != end)
        {
            if(BOOST_XPR_CHAR_(char_type, '$') != *cur)
            {
                *out++ = *cur++;
            }
            else if(++cur == end)
            {
                *out++ = BOOST_XPR_CHAR_(char_type, '$');
            }
            else if(BOOST_XPR_CHAR_(char_type, '$') == *cur)
            {
                *out++ = *cur++;
            }
            else if(BOOST_XPR_CHAR_(char_type, '&') == *cur) // whole match
            {
                ++cur;
                out = std::copy((*this)[ 0 ].first, (*this)[ 0 ].second, out);
            }
            else if(BOOST_XPR_CHAR_(char_type, '`') == *cur) // prefix
            {
                ++cur;
                out = std::copy(this->prefix().first, this->prefix().second, out);
            }
            else if(BOOST_XPR_CHAR_(char_type, '\'') == *cur) // suffix
            {
                ++cur;
                out = std::copy(this->suffix().first, this->suffix().second, out);
            }
            else if(-1 != traits.value(*cur, 10)) // a sub-match
            {
                int max = static_cast<int>(this->size() - 1);
                int br_nbr = detail::toi(cur, end, traits, 10, max);
                detail::ensure(0 != br_nbr, regex_constants::error_subreg, "invalid back-reference");
                out = std::copy((*this)[ br_nbr ].first, (*this)[ br_nbr ].second, out);
            }
            else
            {
                *out++ = BOOST_XPR_CHAR_(char_type, '$');
                *out++ = *cur++;
            }
        }

        return out;
    }
예제 #6
0
 user_string convert<user_string>(const string_type & source,
   system::error_code & ec)
 {
   user_string temp;
   for (string_type::const_iterator it = source.begin();
         it != source.end(); ++it)
     temp += *it - 1;
   return temp;
 }
예제 #7
0
    //! Applies string replacements starting from the specified position
    result_type operator() (string_type& str, typename string_type::size_type start_pos = 0) const
    {
        base_type::operator() (str, start_pos);

        typedef typename string_type::iterator string_iterator;
        for (string_iterator it = str.begin() + start_pos, end = str.end(); it != end; ++it)
        {
            char_type c = *it;
            if (c < 0x20 || c > 0x7e)
            {
                char_type buf[(std::numeric_limits< char_type >::digits + 3) / 4 + 3];
                std::size_t n = traits_type::print_escaped(buf, c);
                std::size_t pos = it - str.begin();
                str.replace(pos, 1, buf, n);
                it = str.begin() + n - 1;
                end = str.end();
            }
        }
    }
 //! helper function to put the various member string into stream
 OutItrT put_string(OutItrT next, const string_type& str) const
 {
   typename string_type::const_iterator itr = str.begin();
   while(itr != str.end()) {
     *next = *itr;
     ++itr;
     ++next;
   }
   return next;
 }
예제 #9
0
파일: mime.hpp 프로젝트: AJLeuer/cpp-netlib
	mime_content_type parse_content_type ( const string_type &theHeader ) {
		tracer t ( __func__ );
		mime_content_type retVal;
		typename string_type::const_iterator first = theHeader.begin ();
		mime_content_type_parser<typename string_type::const_iterator> ct_parser;
		bool b = qi::parse ( first, theHeader.end (), ct_parser, retVal );
		if (!b)
			throw mime_parsing_error ( "Failed to parse the 'Content-Type' header" );
		
		return retVal;
		}
예제 #10
0
void parse_input_line(const string_type& s)
{
   // set matches back to starting values:
   for(int i = 0; i < MAX_MATCHES; ++i)
   {
      matches[i] = -2;
   }
   parse_function op;
   do_test = false;
   regex_grep(op, s.begin(), s.end(), parse_expression);
   jm_trace("expression: " << make_narrow(expression).c_str());
   jm_trace("search string: " << make_narrow(search_text).c_str());
}
예제 #11
0
        /** 
            @brief appends a string (inserts it at the end)
        */
        void append_string(const string_type & str) {
            if ( m_reserve_append < (int)str.size()) {
                int new_reserve_append = (int)str.size() + m_grow_size ;
                resize_string( m_reserve_prepend, new_reserve_append);
            }

            BOOST_ASSERT(m_reserve_append >= (int)str.size() );

            int start_idx = (int)m_str.size() - m_reserve_append;

            std::copy(str.begin(), str.end(), m_str.begin() + start_idx);
            m_reserve_append -= (int)str.size();
            m_full_msg_computed = false;
        }
예제 #12
0
        /**
            @brief appends a string (inserts it at the end)
        */
        void append_string(const string_type & str) {
            if ( m_reserve_append < str.size()) {
                std::size_t new_reserve_append = str.size() + m_grow_size ;
                resize_string( m_reserve_prepend, new_reserve_append);
            }

            BOOST_ASSERT(m_reserve_append >= str.size());

            typename string_type::difference_type start_idx = static_cast<typename string_type::difference_type>(m_str.size() - m_reserve_append);

            std::copy(str.begin(), str.end(), m_str.begin() + start_idx);
            m_reserve_append -= str.size();
            m_full_msg_computed = false;
        }
예제 #13
0
 static bool equals(const string_type& str1, const string_type& str2) {
     if(str1.size() != str2.size()) {
         return false;
     } else if(str1.empty() && str2.empty()) {
         return true;
     } else {
         return std::equal(
             str1.begin(),
             str1.end(),
             str2.begin()
         );
     }
     
 }
예제 #14
0
파일: Parser.hpp 프로젝트: rayfill/cpplib
	bool parse(scanner_t& scanner, skip_t& ) const
	{
		scanner.save();
		
		for (typename string_type::const_iterator itor = literal.begin();
			 itor != literal.end(); ++itor)
		{
			const int val = scanner.read();
			if (val == -1 ||
				traits_type::to_char_type(val) != *itor)
			{
				scanner.rollback();
				return false;
			}
		}
		scanner.commit();
		return true;
	}
예제 #15
0
DecodedBBox decode_bbox(const string_type & _hash_string)
{
    // Copy of the string down-cased
    // Wish this was ruby, then it would be simple: _hash_string.downcase();
    string_type hash_string(_hash_string);
    std::transform(
        _hash_string.begin(),
        _hash_string.end(),
        hash_string.begin(),
        ::tolower);

    DecodedBBox output;
    output.maxlat = 90;
    output.maxlon = 180;
    output.minlat = -90;
    output.minlon = -180;

    bool islon = true;

    for(int i = 0, max = hash_string.length(); i < max; i++) {
        int char_index = base32_codes_index_of(hash_string[i]);

        for (int bits = 4; bits >= 0; --bits) {
            int bit = (char_index >> bits) & 1;
            if (islon) {
                double mid = (output.maxlon + output.minlon) / 2;
                if(bit == 1) {
                    output.minlon = mid;
                } else {
                    output.maxlon = mid;
                }
            } else {
                double mid = (output.maxlat + output.minlat) / 2;
                if(bit == 1) {
                    output.minlat = mid;
                } else {
                    output.maxlat = mid;
                }
            }
            islon = !islon;
        }
    }
    return output;
}
예제 #16
0
 bool is_c(Char e) {
   char_eq f(e);
   return std::find_if(c_.begin(),c_.end(),f)!=c_.end();
 }
예제 #17
0
 bool is_escape(Char e) {
   char_eq f(e);
   return std::find_if(escape_.begin(),escape_.end(),f)!=escape_.end();
 }
예제 #18
0
 /// Returns the end of the contained sequence of the given string
 static const_iterator_type end(string_type const& s)
 {
     return s.end();
 }
예제 #19
0
 void set_string(const string_type & str) {
     m_str.resize( str.size() + m_reserve_prepend + m_reserve_append);
     std::copy( str.begin(), str.end(), m_str.begin() + m_reserve_prepend);
     m_full_msg_computed = false;
 }
예제 #20
0
//! Converts escape sequences to the corresponding characters
void char_constants< wchar_t >::translate_escape_sequences(string_type& str)
{
    using namespace std; // to make sure we can use C functions unqualified

    string_type::iterator it = str.begin();
    while (it != str.end())
    {
        it = std::find(it, str.end(), L'\\');
        if (std::distance(it, str.end()) >= 2)
        {
            it = str.erase(it);
            switch (*it)
            {
            case L'n':
                *it = L'\n'; break;
            case L'r':
                *it = L'\r'; break;
            case L'a':
                *it = L'\a'; break;
            case L'\\':
                ++it; break;
            case L't':
                *it = L'\t'; break;
            case L'b':
                *it = L'\b'; break;
            case L'x':
                {
                    string_type::iterator b = it;
                    if (std::distance(++b, str.end()) >= 2)
                    {
                        char_type c1 = *b++, c2 = *b++;
                        if (iswxdigit(c1) && iswxdigit(c2))
                        {
                            *it++ = char_type((to_number(c1) << 4) | to_number(c2));
                            it = str.erase(it, b);
                        }
                    }
                    break;
                }
            case L'u':
                {
                    string_type::iterator b = it;
                    if (std::distance(++b, str.end()) >= 4)
                    {
                        char_type c1 = *b++, c2 = *b++, c3 = *b++, c4 = *b++;
                        if (iswxdigit(c1) && iswxdigit(c2) && iswxdigit(c3) && iswxdigit(c4))
                        {
                            *it++ = char_type(
                                (to_number(c1) << 12) |
                                (to_number(c2) << 8) |
                                (to_number(c3) << 4) |
                                to_number(c4));
                            it = str.erase(it, b);
                        }
                    }
                    break;
                }
            case L'U':
                {
                    string_type::iterator b = it;
                    if (std::distance(++b, str.end()) >= 8)
                    {
                        char_type c1 = *b++, c2 = *b++, c3 = *b++, c4 = *b++;
                        char_type c5 = *b++, c6 = *b++, c7 = *b++, c8 = *b++;
                        if (iswxdigit(c1) && iswxdigit(c2) && iswxdigit(c3) && iswxdigit(c4) &&
                            iswxdigit(c5) && iswxdigit(c6) && iswxdigit(c7) && iswxdigit(c8))
                        {
                            *it++ = char_type(
                                (to_number(c1) << 28) |
                                (to_number(c2) << 24) |
                                (to_number(c3) << 20) |
                                (to_number(c4) << 16) |
                                (to_number(c5) << 12) |
                                (to_number(c6) << 8) |
                                (to_number(c7) << 4) |
                                to_number(c8));
                            it = str.erase(it, b);
                        }
                    }
                    break;
                }
            default:
                {
                    if (*it >= L'0' && *it <= L'7')
                    {
                        string_type::iterator b = it;
                        int c = (*b++) - L'0';
                        if (*b >= L'0' && *b <= L'7')
                            c = c * 8 + (*b++) - L'0';
                        if (*b >= L'0' && *b <= L'7')
                            c = c * 8 + (*b++) - L'0';

                        *it++ = char_type(c);
                        it = str.erase(it, b);
                    }
                    break;
                }
            }
        }
    }
}
예제 #21
0
파일: convert_format.hpp 프로젝트: 41i/hpx
 inline void write(const string_type & src, string_type & dest) {
     dest.insert( dest.begin(), src.begin(), src.end() );
 }
예제 #22
0
 void set_string(const string_type & str) {
     m_str.resize(str.size() + m_reserve_prepend + m_reserve_append);
     std::copy( str.begin(), str.end(), m_str.begin() + static_cast<typename string_type::difference_type>(m_reserve_prepend));
     m_full_msg_computed = false;
 }
예제 #23
0
 bool is_quote(Char e) {
   char_eq f(e);
   return std::find_if(quote_.begin(),quote_.end(),f)!=quote_.end();
 }
예제 #24
0
    /*! Take a line from the csv, turn it into a time_zone_type,
     * and add it to the map. Zone_specs in csv file are expected to
     * have eleven fields that describe the time zone. Returns true if
     * zone_spec successfully added to database */
    bool parse_string(string_type& s)
    {

        std::vector<string_type> result;
        typedef boost::token_iterator_generator<boost::escaped_list_separator<charT>, string_type::const_iterator, string_type >::type token_iter_type;

        token_iter_type i = boost::make_token_iterator<string_type>(s.begin(), s.end(),boost::escaped_list_separator<charT>());

        token_iter_type end;
        while (i != end) {
            result.push_back(*i);
            i++;
        }

        enum db_fields { ID, STDABBR, STDNAME, DSTABBR, DSTNAME, GMTOFFSET,
                         DSTADJUST, START_DATE_RULE, START_TIME, END_DATE_RULE,
                         END_TIME, FIELD_COUNT
                       };

        //take a shot at fixing gcc 4.x error
        const unsigned int expected_fields = static_cast<unsigned int>(FIELD_COUNT);
        if (result.size() != expected_fields) {
            std::stringstream msg;
            msg << "Expecting " << FIELD_COUNT << " fields, got "
                << result.size() << " fields in line: " << s;
            throw bad_field_count(msg.str());
        }

        // initializations
        bool has_dst = true;
        if(result[DSTABBR] == std::string()) {
            has_dst = false;
        }


        // start building components of a time_zone
        time_zone_names names(result[STDNAME], result[STDABBR],
                              result[DSTNAME], result[DSTABBR]);

        time_duration_type utc_offset =
            posix_time::duration_from_string(result[GMTOFFSET]);

        dst_adjustment_offsets adjust(time_duration_type(0,0,0),
                                      time_duration_type(0,0,0),
                                      time_duration_type(0,0,0));

        boost::shared_ptr<rule_type> rules;

        if(has_dst) {
            adjust = dst_adjustment_offsets(
                         posix_time::duration_from_string(result[DSTADJUST]),
                         posix_time::duration_from_string(result[START_TIME]),
                         posix_time::duration_from_string(result[END_TIME])
                     );

            rules =
                boost::shared_ptr<rule_type>(parse_rules(result[START_DATE_RULE],
                                             result[END_DATE_RULE]));
        }
        string_type id(result[ID]);
        boost::shared_ptr<time_zone_base_type> zone(new time_zone_type(names, utc_offset, adjust, rules));
        return (add_record(id, zone));

    }
예제 #25
0
  date_type
  parse_date(std::istreambuf_iterator<charT>& sitr, 
             std::istreambuf_iterator<charT>& stream_end,
             string_type format) const
  {
    bool use_current_char = false;
    charT current_char = *sitr;

    unsigned short year(0), month(0), day(0), day_of_year(0);
    
    const_itr itr(format.begin());
    while (itr != format.end() && (sitr != stream_end)) {
      if (*itr == '%') {
        itr++;
        if (*itr != '%') { //ignore '%%'
          unsigned short i = 0;
          switch(*itr) {
          case 'a': 
            {
              //this value is just throw away.  It could be used for
              //error checking potentially, but it isn't helpful in 
              //actually constructing the date - we just need to get it
              //out of the stream
              match_results mr = m_weekday_short_names.match(sitr, stream_end);
              unsigned int wkday = mr.current_match;
              if (mr.has_remaining()) {
                current_char = mr.last_char();
                use_current_char = true;
              }
              break;
            }
          case 'A': 
            {
              //this value is just throw away.  It could be used for
              //error checking potentially, but it isn't helpful in 
              //actually constructing the date - we just need to get it
              //out of the stream
              match_results mr = m_weekday_long_names.match(sitr, stream_end);
              unsigned int wkday = mr.current_match;
              if (mr.has_remaining()) {
                current_char = mr.last_char();
                use_current_char = true;
              }
              break;
            }
          case 'b': 
            {
              match_results mr = m_month_short_names.match(sitr, stream_end);
              month = mr.current_match;
              if (mr.has_remaining()) {
                current_char = mr.last_char();
                use_current_char = true;
              }
              break;
            }
          case 'B': 
            {
              match_results mr = m_month_long_names.match(sitr, stream_end);
              month = mr.current_match;
              if (mr.has_remaining()) {
                current_char = mr.last_char();
                use_current_char = true;
              }
              break;
            }
          case 'd': 
            {
              day = var_string_to_int<unsigned short, charT>(sitr, 2);
              break;
            }
          case 'j': 
            {
              day_of_year = fixed_string_to_int<unsigned short, charT>(sitr, 3);
              break;
            }
          case 'm': 
            {
              month = var_string_to_int<unsigned short, charT>(sitr, 2);
              break;
            }
          case 'Y': 
            {
              year = fixed_string_to_int<unsigned short, charT>(sitr, 4);
              break;
            }
          case 'y': 
            {
              year = fixed_string_to_int<unsigned short, charT>(sitr, 2);
              year += 2000; //make 2 digit years in this century
              break;
            }
          default:
            {} //ignore those we don't understand
            
          }//switch
          
        }
        
        itr++; //advance past format specifier
      }
      else {  //skip past chars in format and in buffer
        itr++;
        if (use_current_char) {
          use_current_char = false;
          current_char = *sitr;
        }
        else {
          sitr++;
        }
      }
    }
    
    if (day_of_year != 0) {
      date_type d(year-1,12,31); //end of prior year
      return d + duration_type(day_of_year);
    }
    return date_type(year, month, day);
  }