1 /************************************************************************
\r
3 ** Copyright (C) 2010 Strahinja Markovic
\r
5 ** This file is part of FlightCrew.
\r
7 ** FlightCrew is free software: you can redistribute it and/or modify
\r
8 ** it under the terms of the GNU Lesser General Public License as published
\r
9 ** by the Free Software Foundation, either version 3 of the License, or
\r
10 ** (at your option) any later version.
\r
12 ** FlightCrew is distributed in the hope that it will be useful,
\r
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 ** GNU Lesser General Public License for more details.
\r
17 ** You should have received a copy of the GNU Lesser General Public License
\r
18 ** along with FlightCrew. If not, see <http://www.gnu.org/licenses/>.
\r
20 *************************************************************************/
\r
28 #include <algorithm>
\r
29 #include <boost/unordered/unordered_set_fwd.hpp>
\r
30 #include "Misc/BoostFilesystemUse.h"
\r
31 #include "XercesHUse.h"
\r
34 namespace FlightCrew
\r
39 std::string ReadUnicodFile( const fs::path &filepath );
\r
41 std::string GetFirstNumChars( const std::string &string, unsigned int num_chars );
\r
43 std::string GetFirstNumCharsFromFile( const fs::path &filepath, unsigned int num_chars );
\r
45 int LineOfCharIndex( const std::string &string, unsigned int char_index );
\r
47 boost::shared_ptr< xc::DOMDocument > LoadXmlDocument( const fs::path &filepath );
\r
49 boost::shared_ptr< xc::DOMDocument > LoadXhtmlDocument( const fs::path &filepath );
\r
51 std::string UrlDecode( const std::string &encoded_url );
\r
53 std::string GetUrlFragment( const std::string &decoded_url );
\r
55 std::string UrlWithoutFragment( const std::string &decoded_url );
\r
57 std::string UrlWithoutFileScheme( const std::string &decoded_url );
\r
59 fs::path NormalizePath( const fs::path &filepath );
\r
61 fs::path Utf8PathToBoostPath( const std::string &utf8_path );
\r
63 std::string BoostPathToUtf8Path( const fs::path &filepath );
\r
65 std::vector< Result > AddPathToResults( const std::vector< Result > &results, const fs::path &filepath );
\r
67 template< typename T >
\r
68 void RemoveDuplicates( std::vector<T> &vector )
\r
70 std::sort( vector.begin(), vector.end() );
\r
71 vector.erase( std::unique( vector.begin(), vector.end() ), vector.end() );
\r
74 template< typename T >
\r
75 bool Contains( const std::vector<T> &vector, const T &value )
\r
77 return std::find( vector.begin(), vector.end(), value ) != vector.end();
\r
80 template< typename T >
\r
81 std::vector<T>& Extend( std::vector<T> &base_vector, const std::vector <T> &extension_vector )
\r
83 base_vector.insert( base_vector.end(), extension_vector.begin(), extension_vector.end() );
\r
87 template< typename T >
\r
88 std::vector<T>& SortedInPlace( std::vector<T> &vector )
\r
90 std::sort( vector.begin(), vector.end() );
\r
94 // The STL algos for set union and intersection
\r
95 // only work for sorted ranges, which boost::unordered_sets aren't.
\r
96 template< typename T >
\r
97 boost::unordered_set< T > SetIntersection(
\r
98 const boost::unordered_set< T > &first,
\r
99 const boost::unordered_set< T > &second )
\r
101 boost::unordered_set< T > intersection;
\r
103 // We will iterate over the smaller set
\r
104 // and check presence in the larger one
\r
105 // for the sake of performance.
\r
106 if ( second.size() < first.size() )
\r
108 return SetIntersection( second, first );
\r
110 for ( typename boost::unordered_set< T > ::const_iterator it = first.begin();
\r
114 if ( second.find( *it ) != second.end() )
\r
116 intersection.insert( *it );
\r
119 return intersection;
\r
122 template< typename T >
\r
123 boost::unordered_set< T > SetUnion(
\r
124 const boost::unordered_set< T > &first,
\r
125 const boost::unordered_set< T > &second )
\r
127 boost::unordered_set< T > union_set;
\r
128 union_set.insert( first .begin(), first .end() );
\r
129 union_set.insert( second.begin(), second.end() );
\r
134 template< typename T >
\r
135 boost::unordered_set< T > SetSubtraction(
\r
136 const boost::unordered_set< T > &first,
\r
137 const boost::unordered_set< T > &second )
\r
139 boost::unordered_set< T > subtracted;
\r
141 for ( typename boost::unordered_set< T >::const_iterator it = first.begin();
\r
145 if ( second.find( *it ) == second.end() )
\r
147 subtracted.insert( *it );
\r
153 } // namespace Util
\r
155 } // namespace FlightCrew
\r
157 #endif // UTILITIES_H
\r