Back to index

unity  6.0.0
DashViewPrivate.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Canonical Ltd
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License version 3 as
00006  * published by the Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00015  *
00016  * Authored by: Marco Biscaro <marcobiscaro2112@gmail.com>
00017  */
00018 
00019 #include "DashViewPrivate.h"
00020 
00021 #include <vector>
00022 #include <boost/algorithm/string.hpp>
00023 
00024 namespace unity
00025 {
00026 namespace dash
00027 {
00028 namespace impl
00029 {
00030 
00031 LensFilter parse_lens_uri(std::string const& uri)
00032 {
00033   LensFilter filter;
00034 
00035   filter.id = uri;
00036   std::size_t pos = uri.find("?");
00037 
00038   // it's a real URI (with parameters)
00039   if (pos != std::string::npos)
00040   {
00041     // id is the uri from begining to the '?' position
00042     filter.id = uri.substr(0, pos);
00043 
00044     // the components are from '?' position to the end
00045     std::string components = uri.substr(++pos);
00046 
00047     // split components in tokens
00048     std::vector<std::string> tokens;
00049     boost::split(tokens, components, boost::is_any_of("&"));
00050 
00051     for (std::string const& token : tokens)
00052     {
00053       // split each token in a pair
00054       std::size_t equals_pos = token.find("=");
00055 
00056       if (equals_pos != std::string::npos)
00057       {
00058         std::string key = token.substr(0, equals_pos);
00059         std::string value = token.substr(equals_pos + 1);
00060 
00061         // check if it's a filter
00062         if (boost::starts_with(key, "filter_"))
00063         {
00064           filter.filters[key.substr(7)] = value;
00065         }
00066       }
00067 
00068     }
00069   }
00070 
00071   return filter;
00072 }
00073 
00074 } // namespace impl
00075 } // namespace dash
00076 } // namespace unity