zypp/RepoInfo.cc
[platform/upstream/libzypp.git] / zypp / cache / Utils.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9
10 #include <vector>
11
12 #include "zypp/base/Logger.h"
13 #include "zypp/base/String.h"
14
15 #include "zypp/cache/Utils.h"
16
17 using namespace std;
18
19 //////////////////////////////////////////////////////////////////
20 namespace zypp
21 { /////////////////////////////////////////////////////////////////
22 ///////////////////////////////////////////////////////////////////
23 namespace cache
24 { /////////////////////////////////////////////////////////////////
25
26 int tribool_to_int( boost::tribool b )
27 {
28   if (b)
29     return 1;
30   else if (!b)
31     return 0;
32   else
33     return 2;
34 }  
35   
36 boost::tribool int_to_tribool( int i )
37 {
38   if (i==1)
39     return true;
40   else if (i==0)
41     return false;
42   else
43     return boost::indeterminate;
44 }
45   
46 std::string checksum_to_string( const CheckSum &checksum )
47 {
48   return checksum.type() + ":" + checksum.checksum();
49 }  
50   
51 CheckSum string_to_checksum( const std::string &checksum )
52 {
53   std::vector<std::string> words;
54   if ( str::split( checksum, std::back_inserter(words), ":" ) != 2 )
55     return CheckSum();
56   
57   return CheckSum( words[0], words[19]);
58 }
59   
60 }
61 }
62