LCOV - code coverage report
Current view: top level - irohad/ametsuchi/impl - postgres_options.cpp (source / functions) Hit Total Coverage
Test: coverage_cleared.info Lines: 17 17 100.0 %
Date: 2018-12-05 17:11:35 Functions: 7 7 100.0 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #include "ametsuchi/impl/postgres_options.hpp"
       7             : 
       8             : #include <boost/algorithm/string.hpp>
       9             : #include <regex>
      10             : 
      11             : namespace iroha {
      12             :   namespace ametsuchi {
      13             : 
      14             :     // regex to fetch dbname from pg_opt string
      15             :     const static std::regex e("\\bdbname=([^ ]*)");
      16             : 
      17             :     PostgresOptions::PostgresOptions(const std::string &pg_opt)
      18         437 :         : pg_opt_(pg_opt) {
      19         437 :       std::smatch m;
      20             : 
      21         437 :       if (std::regex_search(pg_opt_, m, e)) {
      22         436 :         dbname_ = *(m.end() - 1);
      23             : 
      24             :         // get pg_opt_without_db_name_
      25         436 :         pg_opt_without_db_name_ = m.prefix().str() + m.suffix().str();
      26             : 
      27             :         // remove consecutive spaces
      28             :         auto end =
      29         436 :             std::unique(pg_opt_without_db_name_.begin(),
      30         436 :                         pg_opt_without_db_name_.end(),
      31             :                         [](char l, char r) {
      32       27845 :                           return std::isspace(l) && std::isspace(r) && l == r;
      33             :                         });
      34         436 :         pg_opt_without_db_name_ =
      35         436 :             std::string(pg_opt_without_db_name_.begin(), end);
      36         436 :       } else {
      37           1 :         dbname_ = boost::none;
      38           1 :         pg_opt_without_db_name_ = pg_opt_;
      39             :       }
      40         437 :     }
      41             : 
      42             :     std::string PostgresOptions::optionsString() const {
      43           2 :       return pg_opt_;
      44             :     }
      45             : 
      46             :     std::string PostgresOptions::optionsStringWithoutDbName() const {
      47         869 :       return pg_opt_without_db_name_;
      48             :     }
      49             : 
      50             :     boost::optional<std::string> PostgresOptions::dbname() const {
      51        1303 :       return dbname_;
      52             :     }
      53             : 
      54             :   }  // namespace ametsuchi
      55             : }  // namespace iroha

Generated by: LCOV version 1.13