LTP GCOV extension - code coverage report
Current view: directory - ept/apt - packagerecord.cc
Test: lcov.info
Date: 2008-08-14 Instrumented lines: 44
Code covered: 90.9 % Executed lines: 40

       1                 : /** \file
       2                 :  * Parser for APT records, with specialised accessors for package records
       3                 :  */
       4                 : 
       5                 : /* 
       6                 :  * Copyright (C) 2007  Enrico Zini <enrico@enricozini.org>
       7                 :  *
       8                 :  * This library is free software; you can redistribute it and/or
       9                 :  * modify it under the terms of the GNU Lesser General Public
      10                 :  * License as published by the Free Software Foundation; either
      11                 :  * version 2.1 of the License, or (at your option) any later version.
      12                 :  *
      13                 :  * This library is distributed in the hope that it will be useful,
      14                 :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15                 :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16                 :  * Lesser General Public License for more details.
      17                 :  *
      18                 :  * You should have received a copy of the GNU Lesser General Public
      19                 :  * License along with this library; if not, write to the Free Software
      20                 :  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
      21                 :  */
      22                 : 
      23                 : #include <ept/apt/packagerecord.h>
      24                 : 
      25                 : #include <cctype>
      26                 : #include <cstdlib>
      27                 : 
      28                 : //#include <iostream>
      29                 : 
      30                 : using namespace std;
      31                 : 
      32                 : namespace ept {
      33                 : namespace apt {
      34                 : 
      35            5210 : size_t PackageRecord::parseSize(size_t def, const std::string& str) const
      36                 : {
      37            5210 :         if (str == string())
      38              54 :                 return def;
      39            5156 :         return (size_t)strtoul(str.c_str(), NULL, 10);
      40                 : }
      41                 : 
      42               1 : std::string PackageRecord::parseShortDescription(const std::string& def, const std::string& str) const
      43                 : {
      44               1 :         if (str == std::string())
      45               0 :                 return def;
      46               1 :         size_t pos = str.find("\n");
      47               1 :         if (pos == std::string::npos)
      48               0 :                 return str;
      49                 :         else
      50               1 :                 return str.substr(0, pos);
      51                 : }
      52                 : 
      53               1 : std::string PackageRecord::parseLongDescription(const std::string& def, const std::string& str) const
      54                 : {
      55               1 :         if (str == std::string())
      56               0 :                 return def;
      57               1 :         size_t pos = str.find("\n");
      58               1 :         if (pos == std::string::npos)
      59               0 :                 return str;
      60                 :         else
      61                 :         {
      62                 :                 // Trim trailing spaces
      63               1 :                 for (++pos; pos < str.size() && isspace(str[pos]); ++pos)
      64                 :                         ;
      65               1 :                 return str.substr(pos);
      66                 :         }
      67                 : }
      68                 : 
      69            2605 : std::set<std::string> PackageRecord::parseTags(const std::set<std::string>& def, const std::string& str) const
      70                 : {
      71            2605 :         if (str == string())
      72            2604 :                 return def;
      73                 : 
      74               1 :         set<string> res;
      75                 : 
      76               1 :         size_t pos = 0;
      77              13 :         while (pos < str.size())
      78                 :         {
      79              12 :                 string tag;
      80              12 :                 size_t i = str.find(", ", pos);
      81              12 :                 if (i == string::npos)
      82               1 :                         tag = str.substr(pos);
      83                 :                 else
      84              11 :                         tag = str.substr(pos, i-pos);
      85                 : 
      86                 :                 // Check if we need curly brace expansion
      87              12 :                 if (tag[tag.size() - 1] == '}')
      88                 :                 {
      89               1 :                         size_t begin = tag.find('{');
      90               1 :                         if (begin != string::npos)
      91                 :                         {
      92               1 :                                 string prefix(tag, 0, begin);
      93               1 :                                 ++begin;
      94                 :                                 size_t end;
      95               4 :                                 while ((end = tag.find(',', begin)) != string::npos)
      96                 :                                 {
      97               2 :                                         res.insert(prefix + tag.substr(begin, end-begin));
      98               2 :                                         begin = end + 1;
      99                 :                                 }
     100               1 :                                 res.insert(prefix + tag.substr(begin, tag.size() - 1 - begin));
     101                 :                         }
     102                 :                 } else {
     103              11 :                         res.insert(tag);
     104                 :                 }
     105                 : 
     106              12 :                 if (i == string::npos)
     107               1 :                         break;
     108                 :                 else
     109              11 :                         pos = i + 2;
     110                 :         }
     111                 : 
     112               1 :         return res;
     113                 : }
     114                 : 
     115                 : }
     116                 : }
     117                 : 
     118                 : // vim:set ts=4 sw=4:

Generated by: LTP GCOV extension version 1.6