26 #include "raul/Atom.hpp"
39 class BadURI :
public std::exception {
41 BadURI(
const std::string& uri) : _uri(uri) {}
43 const char* what()
const throw() {
return _uri.c_str(); }
53 URI(
const std::basic_string<char>& uri=
"nil:0") : _str(g_intern_string(uri.c_str())) {
63 URI(
const char* uri) : _str(g_intern_string(uri)) {
68 static bool is_valid(
const std::basic_string<char>& uri) {
69 return uri.find(
":") != std::string::npos;
73 inline const std::string
chop_start(
const std::string& str)
const {
74 return substr(find(str) + str.length());
81 inline std::string
scheme()
const {
return substr(0, find(
":")); }
83 inline const std::string str()
const {
return _str; }
84 inline const char* c_str()
const {
return _str; }
86 inline std::string substr(
size_t start,
size_t end=std::string::npos)
const {
87 return str().substr(start, end);
90 inline bool operator<(
const URI& uri)
const {
return strcmp(_str, uri.c_str()) < 0; }
91 inline bool operator<=(
const URI& uri)
const {
return (*
this) == uri || (*this) < uri; }
92 inline bool operator==(
const URI& uri)
const {
return _str == uri._str; }
93 inline bool operator!=(
const URI& uri)
const {
return _str != uri._str; }
95 inline size_t length()
const {
return str().length(); }
96 inline size_t find(
const std::string& s)
const {
return str().find(s); }
97 inline size_t find_last_of(
char c)
const {
return str().find_last_of(c); }
107 operator<<(std::ostream& os,
const URI& uri)
109 return (os << uri.c_str());
114 #endif // RAUL_URI_HPP
A piece of data with some type.
Definition: Atom.hpp:43
URI(const std::basic_string< char > &uri="nil:0")
Construct a URI from an std::string.
Definition: URI.hpp:53
Simple wrapper around standard string with useful URI-specific methods.
Definition: URI.hpp:37
URI(const char *uri)
Construct a URI from a C string.
Definition: URI.hpp:63
const std::string chop_start(const std::string &str) const
Return path with everything up to and including the first occurence of str chopped.
Definition: URI.hpp:73
std::string chop_scheme() const
Return the URI with the scheme removed (as a string)
Definition: URI.hpp:78
std::string scheme() const
Return the URI scheme (everything before the first ':')
Definition: URI.hpp:81