libparser++-0.2.3/0000755000175000017500000000000011173572272013516 5ustar richterrichterlibparser++-0.2.3/deb822.hpp0000644000175000017500000001054611173572215015220 0ustar richterrichter/* Copyright 2007, 2008, 2009 Simon Richter * * Released under the Boost Software Licence 1.0 */ #ifndef util_deb822_hpp_ #define util_deb822_hpp_ 1 #include "parser.hpp" #include #include #include namespace util { namespace deb822 { template< typename CharT_ = char, typename Traits_ = std::char_traits > class key_string : public std::basic_string { public: typedef CharT_ char_type; typedef Traits_ traits_type; typedef std::basic_string string_type; key_string(void) : string_type() { } key_string(string_type const &k) : string_type(k) { } }; template< typename CharT_ = char, typename Traits_ = std::char_traits > class value_string : public std::basic_string { public: typedef CharT_ char_type; typedef Traits_ traits_type; typedef std::basic_string string_type; value_string(void) : string_type() { } value_string(string_type const &k) : string_type(k) { } }; template< typename CharT_ = char, typename Traits_ = std::char_traits > class pair { public: typedef key_string key_type; typedef value_string value_type; key_type key; value_type value; }; } template< typename CharT_ = char, typename Traits_ = std::char_traits > class deb822_parser_impl : public parser >::impl { public: typedef CharT_ char_type; typedef Traits_ traits_type; typedef deb822::pair value_type; typedef std::basic_string string_type; typedef std::basic_istream stream_type; deb822_parser_impl(stream_type &); virtual ~deb822_parser_impl(void) throw(); typedef value_type const *pointer; typedef value_type const &reference; virtual reference operator*(void) const; virtual pointer operator->(void) const; virtual deb822_parser_impl &operator++(void); virtual bool operator!(void) const throw(); private: stream_type &stream; value_type obj; bool fake_failure; }; template deb822_parser_impl::deb822_parser_impl( std::basic_istream &stream) : stream(stream), fake_failure(false) { stream >> std::noskipws; ++*this; return; } template deb822_parser_impl::~deb822_parser_impl(void) throw() { if(fake_failure) stream.clear(stream.rdstate() & ~std::ios::failbit); return; } template typename deb822_parser_impl::reference deb822_parser_impl::operator*(void) const { return obj; } template typename deb822_parser_impl::pointer deb822_parser_impl::operator->(void) const { return &obj; } template deb822_parser_impl & deb822_parser_impl::operator++(void) { typename stream_type::sentry sentry(stream); if(!sentry) return *this; string_type line; if(!std::getline(stream, line)) return *this; if(line.empty()) { stream.setstate(std::ios::failbit); fake_failure = true; return *this; } typedef typename string_type::size_type pos_type; pos_type const colon = line.find(':'); if(colon == string_type::npos) { stream.setstate(std::ios::failbit|std::ios::badbit); return *this; } bool const first_line_is_empty = (line.size() == (colon + 1)); typename value_type::key_type key = line.substr(0, colon); typename value_type::value_type value = first_line_is_empty? typename value_type::value_type(): line.substr( line.find_first_not_of(' ', colon + 1)); while(stream.peek() == traits_type::to_int_type(' ')) { if(!std::getline(stream, line)) return *this; if(line.empty()) { stream.setstate(std::ios::failbit); fake_failure = true; return *this; } char_type const space_dot[] = {' ', '.'}; if(line == string_type(space_dot, 2)) line.resize(1); line[0] = '\n'; value += line; } obj.key = key; obj.value = value; return *this; } template bool deb822_parser_impl::operator!(void) const throw() { return !stream; } typedef deb822_parser_impl<> deb822_parser; typedef deb822_parser_impl deb822_wparser; } #endif libparser++-0.2.3/LICENCE0000644000175000017500000000247210757667172014523 0ustar richterrichterBoost Software License - Version 1.0 - August 17th, 2003 Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. libparser++-0.2.3/parser.hpp0000644000175000017500000000364311015154440015515 0ustar richterrichter/* Copyright 2008 Simon Richter * * Released under the Boost Software Licence 1.0 */ #ifndef util_parser_hpp_ #define util_parser_hpp_ 1 #include namespace util { template void intrusive_ptr_add_ref(T *i, typename T::is_parser_impl * = 0) { ++i->refcount; } template void intrusive_ptr_release(T *i, typename T::is_parser_impl * = 0) { if(!--i->refcount) delete i; } template class parser { public: class impl; parser(void) : slave(0) { } parser(boost::intrusive_ptr const &slave) : slave(slave) { } typedef T value_type; typedef std::forward_iterator_tag iterator_category; typedef void difference_type; typedef T const *pointer; typedef T const &reference; bool operator==(parser const &rhs) const { return !slave && !rhs.slave; } bool operator!=(parser const &rhs) const { return slave || rhs.slave; } pointer operator->(void) const { return slave->operator->(); } reference operator*(void) const { return slave->operator*(); } parser &operator++(void) { slave->operator++(); if(!*slave) slave = 0; return *this; } class impl { public: impl(void) throw() : refcount(0) { } virtual ~impl(void) throw() { } typedef typename parser::value_type value_type; typedef typename parser::pointer pointer; typedef typename parser::reference reference; virtual pointer operator->(void) const = 0; virtual reference operator*(void) const = 0; virtual impl &operator++(void) = 0; virtual bool operator!(void) const = 0; operator void const *(void) const { if(!*this) return 0; return this; } typedef void is_parser_impl; private: unsigned int refcount; friend void intrusive_ptr_add_ref<>(impl *, is_parser_impl *); friend void intrusive_ptr_release<>(impl *, is_parser_impl *); }; private: boost::intrusive_ptr slave; }; } #endif