Back to index

unity  6.0.0
HudPrivate.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2012 Canonical Ltd.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser 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, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranties of
00010  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00011  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00012  * License for more details.
00013  *
00014  * You should have received a copy of both the GNU Lesser General Public
00015  * License version 3 along with this program.  If not, see
00016  * <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Andrea Azzarone <azzaronea@gmail.com>
00019  *              Tim Penhey <tim.penhey@canonical.com>
00020  *
00021  */
00022 
00023 #include "HudPrivate.h"
00024 
00025 namespace unity
00026 {
00027 namespace hud
00028 {
00029 namespace impl
00030 {
00031 
00032 std::vector<std::pair<std::string, bool>> RefactorText(std::string const& text)
00033 {
00034   std::vector<std::pair<std::string, bool>> ret;
00035 
00036   static const std::string bold_start("<b>");
00037   static const std::string bold_end("</b>");
00038 
00039   std::string::size_type last = 0;
00040   std::string::size_type len = text.length();
00041   std::string::size_type pos = text.find(bold_start);
00042 
00043   while (pos != std::string::npos)
00044   {
00045     if (pos != last)
00046     {
00047       ret.push_back(std::pair<std::string, bool>(text.substr(last, pos - last), false));
00048     }
00049 
00050     // Look for the end
00051     pos += 3; // // to skip the "<b>"
00052     std::string::size_type end_pos = text.find(bold_end, pos);
00053     // We hope we find it, if we don't, just output everything...
00054     if (end_pos != std::string::npos)
00055     {
00056       ret.push_back(std::pair<std::string, bool>(text.substr(pos, end_pos - pos), true));
00057       last = end_pos + 4; // the length of "</b>"
00058       pos = text.find(bold_start, last);
00059     }
00060     else
00061     {
00062       ret.push_back(std::pair<std::string, bool>(text.substr(pos), true));
00063       pos = std::string::npos;
00064       last = len;
00065     }
00066   }
00067 
00068   if (last < len)
00069   {
00070     ret.push_back(std::pair<std::string, bool>(text.substr(last), false));
00071   }
00072 
00073   return ret;
00074 }
00075 
00076 } // namespace unity
00077 } // namespace hud
00078 } // namespace impl