diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2018-07-25 12:57:03 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2018-07-25 12:57:03 +0200 |
commit | 190fb7a0ef8a28193a89c66d9d1fd84340ff99bd (patch) | |
tree | 3aef0e5d8801b610afdec7c776d4dacc9555af08 /libbpkg/package-name.cxx | |
parent | 3374ce4f2982edff59ed5ca29edc7fde1286b0a2 (diff) |
Add package_name::{base,extension,variable}()
Diffstat (limited to 'libbpkg/package-name.cxx')
-rw-r--r-- | libbpkg/package-name.cxx | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/libbpkg/package-name.cxx b/libbpkg/package-name.cxx index 7a42ee3..9a3e787 100644 --- a/libbpkg/package-name.cxx +++ b/libbpkg/package-name.cxx @@ -7,9 +7,11 @@ #include <string> #include <vector> #include <utility> // move() -#include <algorithm> // find() +#include <iterator> // back_inserter +#include <algorithm> // find(), transform() #include <stdexcept> // invalid_argument +#include <libbutl/path.mxx> // path::traits #include <libbutl/utility.mxx> // alpha(), alnum() using namespace std; @@ -56,4 +58,37 @@ namespace bpkg value_ = move (nm); } + + string package_name:: + base () const + { + using std::string; + + size_t p (path::traits::find_extension (value_)); + return string (value_, 0, p); + } + + string package_name:: + extension () const + { + using std::string; + + size_t p (path::traits::find_extension (value_)); + return p != string::npos ? string (value_, p + 1) : string (); + } + + string package_name:: + variable () const + { + using std::string; + + auto sanitize = [] (char c) + { + return (c == '-' || c == '+' || c == '.') ? '_' : c; + }; + + string r; + transform (value_.begin (), value_.end (), back_inserter (r), sanitize); + return r; + } } |