LCOV - code coverage report
Current view: top level - versiontheca - basic.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 9 9 100.0 %
Date: 2023-01-24 22:36:19 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2023  Made to Order Software Corp.  All Rights Reserved
       2             : //
       3             : // https://snapwebsites.org/project/versiontheca
       4             : // contact@m2osw.com
       5             : //
       6             : // This program is free software: you can redistribute it and/or modify
       7             : // it under the terms of the GNU General Public License as published by
       8             : // the Free Software Foundation, either version 3 of the License, or
       9             : // (at your option) any later version.
      10             : //
      11             : // This program is distributed in the hope that it will be useful,
      12             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             : // GNU General Public License for more details.
      15             : //
      16             : // You should have received a copy of the GNU General Public License
      17             : // along with this program.  If not, see <https://www.gnu.org/licenses/>.
      18             : 
      19             : /** \file
      20             :  * \brief Parse and compare Debian compatible versions.
      21             :  *
      22             :  * Debian versions are very well defined to support a limited set of
      23             :  * characters which can be compared with well defined expected results.
      24             :  * The functions available here implement the Debian algorithm as defined
      25             :  * in the Debian manual. It includes all the features to the letter because
      26             :  * we assume that fully supporting the version is of major importance.
      27             :  *
      28             :  * However, the colon (:) character is not supported in a filename under
      29             :  * the MS-Windows file systems. For this reason we have one exception: we
      30             :  * support a semi-colon (;) as an exact equivalent of a colon. This is fine
      31             :  * because by default the semi-colon is not considered valid in a filename.
      32             :  */
      33             : 
      34             : // self
      35             : //
      36             : #include    <versiontheca/basic.h>
      37             : 
      38             : 
      39             : 
      40             : // C++
      41             : //
      42             : #include    <algorithm>
      43             : 
      44             : 
      45             : // last include
      46             : //
      47             : #include    <snapdev/poison.h>
      48             : 
      49             : 
      50             : 
      51             : namespace versiontheca
      52             : {
      53             : 
      54             : 
      55             : 
      56       10042 : bool basic::parse(std::string const & v)
      57             : {
      58       10042 :     if(!trait::parse(v))
      59             :     {
      60           1 :         return false;
      61             :     }
      62             : 
      63             :     // all must be numbers in a basic version (1.2.3)
      64             :     //
      65       10041 :     std::size_t const max(size());
      66      140104 :     for(std::size_t idx(0); idx < max; ++idx)
      67             :     {
      68      130084 :         if(!at(idx).is_integer())
      69             :         {
      70          21 :             f_last_error = "basic versions only support integers separated by periods (.).";
      71          21 :             return false;
      72             :         }
      73             :     }
      74       10020 :     return true;
      75             : }
      76             : 
      77             : 
      78             : 
      79             : }
      80             : // namespace versiontheca
      81             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.13