From 4fe22a4f393e5e7731a07405767571da021602da Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 12 Aug 2012 16:29:52 +0000 Subject: Remove redundant Path::is_valid_name and Path::nameify. git-svn-id: http://svn.drobilla.net/lad/trunk/raul@4671 a436a847-0d15-0410-975c-d299462d15a1 --- raul/Path.hpp | 14 ++++---------- raul/Symbol.hpp | 23 ++++++++++++++++++----- raul/URI.hpp | 2 +- src/Path.cpp | 19 ------------------- 4 files changed, 23 insertions(+), 35 deletions(-) diff --git a/raul/Path.hpp b/raul/Path.hpp index 15adf53..7404877 100644 --- a/raul/Path.hpp +++ b/raul/Path.hpp @@ -48,7 +48,7 @@ public: ~BadPath() throw() {} const char* what() const throw() { return _path.c_str(); } private: - std::string _path; + const std::string _path; }; /** Return the root path. @@ -102,13 +102,7 @@ public: static bool is_valid(const std::basic_string& path); - static bool is_valid_name(const std::basic_string& name) { - return name.length() > 0 && name.find("/") == std::string::npos - && is_valid(std::string("/").append(name)); - } - static std::string pathify(const std::basic_string& str); - static std::string nameify(const std::basic_string& str); static void replace_invalid_chars(std::string& str, size_t start, @@ -166,7 +160,7 @@ public: } } - /** Return the path's child with the given name (symbol) + /** Return the path's child with the given symbol */ inline Path child(const Raul::Symbol& symbol) const { return base() + symbol.c_str(); @@ -186,7 +180,7 @@ public: /** Return path with a trailing "/". * * Returned value is guaranteed to be a valid parent path, i.e. a valid - * child path can be made using parent.base() + child_name. + * child path can be made using parent.base() + symbol. */ inline const std::string base() const { std::string ret = str(); @@ -199,7 +193,7 @@ public: /** Return path with a trailing "/". * * Returned value is guaranteed to be a valid parent path, i.e. a valid - * child path can be made using parent.base() + child_name. + * child path can be made using parent.base() + symbol. */ inline const std::string base_no_scheme() const { return base().substr(find(":") + 1); diff --git a/raul/Symbol.hpp b/raul/Symbol.hpp index 469a4cf..b872e3a 100644 --- a/raul/Symbol.hpp +++ b/raul/Symbol.hpp @@ -17,9 +17,9 @@ #ifndef RAUL_SYMBOL_HPP #define RAUL_SYMBOL_HPP -#include #include #include +#include #include #include @@ -40,15 +40,26 @@ namespace Raul { */ class Symbol { public: + class BadSymbol : public std::exception { + public: + explicit BadSymbol(const std::string& symbol) : _symbol(symbol) {} + ~BadSymbol() throw() {} + const char* what() const throw() { return _symbol.c_str(); } + private: + const std::string _symbol; + }; + /** Construct a Symbol from an std::string. * * It is a fatal error to construct a Symbol from an invalid string, * use is_valid first to check. */ - explicit Symbol(const std::basic_string& symbol) + explicit Symbol(const std::basic_string& symbol) throw(BadSymbol) : _str(g_intern_string(symbol.c_str())) { - assert(is_valid(symbol)); + if (!is_valid(symbol)) { + throw BadSymbol(symbol); + } } /** Construct a Symbol from a C string. @@ -56,10 +67,12 @@ public: * It is a fatal error to construct a Symbol from an invalid string, * use is_valid first to check. */ - explicit Symbol(const char* csymbol) + explicit Symbol(const char* csymbol) throw(BadSymbol) : _str(g_intern_string(csymbol)) { - assert(is_valid(csymbol)); + if (!is_valid(csymbol)) { + throw BadSymbol(csymbol); + } } Symbol& operator=(const Symbol& other) { diff --git a/raul/URI.hpp b/raul/URI.hpp index 1548375..bc64b8c 100644 --- a/raul/URI.hpp +++ b/raul/URI.hpp @@ -39,7 +39,7 @@ public: ~BadURI() throw() {} const char* what() const throw() { return _uri.c_str(); } private: - std::string _uri; + const std::string _uri; }; /** Construct a URI from an std::string. diff --git a/src/Path.cpp b/src/Path.cpp index 8bc4f89..2bf194d 100644 --- a/src/Path.cpp +++ b/src/Path.cpp @@ -129,25 +129,6 @@ Path::pathify(const std::basic_string& str) return path; } -/** Convert a string to a valid name (or "method" - tokens between slashes) - * - * This will strip all slashes, etc, and always return a valid name/method. - */ -string -Path::nameify(const std::basic_string& str) -{ - string name = str; - - if (name.length() == 0) - return "_"; // this might not be wise - - replace_invalid_chars(name, 0, true); - - assert(is_valid(string("/") + name)); - - return name; -} - /** Replace any invalid characters in @a str with a suitable replacement. */ void -- cgit v1.2.1