From 3a6c4ab1b6fc79a6a543088553cdd6bc8cb0a1dd Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 21 May 2018 21:10:09 +0300 Subject: Adapt to inventing package_name type --- bpkg/manifest-utility.cxx | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'bpkg/manifest-utility.cxx') diff --git a/bpkg/manifest-utility.cxx b/bpkg/manifest-utility.cxx index defa675..fcda389 100644 --- a/bpkg/manifest-utility.cxx +++ b/bpkg/manifest-utility.cxx @@ -35,32 +35,34 @@ namespace bpkg return package_scheme::none; } - string - parse_package_name (const char* s) + package_name + parse_package_name (const char* s, bool allow_version) { using traits = string::traits_type; + if (!allow_version) + try + { + return package_name (s); + } + catch (const invalid_argument& e) + { + fail << "invalid package name '" << s << "': " << e; + } + size_t n (traits::length (s)); if (const char* p = traits::find (s, n, '/')) n = static_cast (p - s); - string nm (s, n); - - // The package name may be a part of some compound argument. So while the - // invalid package name would likely result in the operation failure, the - // validating can ease the troubleshooting. - // try { - validate_package_name (nm); + return package_name (string (s, n)); } catch (const invalid_argument& e) { - fail << "invalid package name in '" << s << "': " << e; + fail << "invalid package name in '" << s << "': " << e << endf; } - - return nm; } version -- cgit v1.1