17 #ifndef COM_BORA_SOFTWARE__BALAU_RESOURCE__STRING_URI 18 #define COM_BORA_SOFTWARE__BALAU_RESOURCE__STRING_URI 61 : data(
std::move(data_)) {}
80 data.append(text.data(), text.length());
131 public:
size_t hashcode() const noexcept
override {
132 return std::hash<std::string>()(data);
135 public: std::unique_ptr<Uri>
clone()
const override {
136 return std::unique_ptr<Uri>(
new StringUri(*
this));
139 public: std::unique_ptr<Uri>
append(
const std::string & pathComponent)
const override {
143 public: std::unique_ptr<Uri>
resolve(std::string_view path)
const override {
144 static const std::regex scheme {
"[a-zA-Z][a-zA-Z0-9+-\\.]*:" };
147 auto str = std::string(cleanPath);
150 std::unique_ptr<Uri> uri;
157 ,
"StringUri does not support calls to the resolve method without specifying a schema in the path." 162 const auto * o =
dynamic_cast<const StringUri *
>(&rhs);
163 return o !=
nullptr && data == o->data;
216 public: std::unique_ptr<UriIterator>
iterator()
const override {
224 private: std::string data;
229 #endif // COM_BORA_SOFTWARE__BALAU_RESOURCE__STRING_URI bool isRegularDirectory() const override
Returns true if the URI points to a file directory.
Definition: StringUri.hpp:115
virtual void dispatch(const File &object)=0
Visit a File URI.
A read-only String URI resource which is read as bytes.
Definition: StringUriByteReadResource.hpp:33
bool isRecursivelyIterable() const override
Does the URI have a recursive iterator (examples: file and zip archive URIs).
Definition: StringUri.hpp:204
StringUri(std::string data_)
Create a String URI with the supplied string data.
Definition: StringUri.hpp:60
void dispatch(UriDispatcher &dispatcher) const override
Visitor pattern dispatching.
Definition: StringUri.hpp:220
StringUri & append(std::string_view text)
Append the supplied text to the internal string data.
Definition: StringUri.hpp:79
StringUri & append(char32_t c)
Append the supplied code point to the internal string data.
Definition: StringUri.hpp:101
StringUri & append(char c)
Append the supplied ascii character to the internal string data.
Definition: StringUri.hpp:90
#define ThrowBalauException(ExceptionClass,...)
Throw a Balau style exception, with implicit file and line number, and optional stacktrace.
Definition: BalauException.hpp:45
size_t hashcode() const noexcept override
Get the URI's hash code.
Definition: StringUri.hpp:131
std::unique_ptr< Utf8To32ReadResource > utf8To32ReadResource() const override
Get a UTF-8 to UTF-32 read resource for the URI.
Definition: StringUri.hpp:192
A read-only string URI resource which is read as bytes.
void fromString(File &destination, std::string_view value)
Overwrite the supplied file URI by assignment by converting the supplied UTF-8 string to a file URI...
Definition: File.hpp:733
bool isIterable() const override
Does the URI have a non-recursive iterator (examples: file and zip archive URIs). ...
Definition: StringUri.hpp:208
An abstract universal resource identifier.
Definition: Uri.hpp:131
bool operator==(const Uri &rhs) const override
Compare the supplied URI to the current URI.
Definition: StringUri.hpp:161
std::unique_ptr< ByteWriteResource > byteWriteResource() override
Get a byte write resource for the URI.
Definition: StringUri.hpp:196
bool canWriteTo() const override
Can data be written to the URI via a write resource.
Definition: StringUri.hpp:170
The unified resource class hierarchy.
Definition: ByteReadResource.hpp:24
Thrown when a feature is not yet implemented.
Definition: BalauException.hpp:162
std::unique_ptr< Utf32To8WriteResource > utf32To8WriteResource() override
Get a UTF-32 to UTF-8 write resource for the URI.
Definition: StringUri.hpp:200
std::unique_ptr< RecursiveUriIterator > recursiveIterator() const override
Get a recursive iterator.
Definition: StringUri.hpp:212
const std::string & getString() const
Get a const reference to the string data of the String URI.
Definition: StringUri.hpp:111
A read-only String UTF-8 resource which is read as UTF-32 characters.
Thrown when an illegal argument is passed to a function or method.
Definition: BalauException.hpp:138
StringUri()=default
Create an empty String URI.
std::unique_ptr< ByteReadResource > byteReadResource() const override
Get a byte read resource for the URI.
Definition: StringUri.hpp:188
std::string toUriString() const override
Get a string representing the URI, complete with scheme.
Definition: StringUri.hpp:123
A write-only UTF-8 resource in a standard file on a file system, which is written with UTF-32 charact...
Definition: StringUriUtf32To8WriteResource.hpp:35
static std::string_view trim(const std::string_view &input)
Trim whitespace from the beginning and end of the supplied UTF-8 string.
Definition: Strings.hpp:706
An immediate string pseudo-URI.
Definition: StringUri.hpp:49
std::unique_ptr< UriIterator > iterator() const override
Get a (non-recursive) iterator.
Definition: StringUri.hpp:216
bool isRegularFile() const override
Returns true if the URI is a regular file.
Definition: StringUri.hpp:119
bool canReadFrom() const override
Can data be read from the URI via a read resource.
Definition: StringUri.hpp:166
Balau exceptions for resources.
A write only String URI that is written as bytes.
Definition: StringUriByteWriteResource.hpp:33
std::unique_ptr< Uri > append(const std::string &pathComponent) const override
Appends the path component to the supplied URI, returning a new URI.
Definition: StringUri.hpp:139
StringUriByteReadResource getByteReadResource() const
Get a byte read resource for the HTTP source.
Definition: StringUri.hpp:177
static bool startsWithRegex(const std::string &str, const std::regex &prefix)
Does the string start with the specified regular expression?
Definition: Strings.hpp:94
std::string toRawString() const override
Get a string representing the raw URI.
Definition: StringUri.hpp:127
A write resource onto a String URI that is written as bytes.
static void append(std::string &str, char c, size_t count)
Appends count times the supplied ascii character to the supplied UTF-8 string (in place version)...
Definition: Strings.hpp:507
StringUriUtf8To32ReadResource getUtf8To32ReadResource() const
Get a UTF-8 to UTF-32 read resource for the HTTP source.
Definition: StringUri.hpp:184
std::unique_ptr< Uri > clone() const override
Clone the concrete Uri.
Definition: StringUri.hpp:135
A read-only String UTF-8 resource which is read as UTF-32 characters.
Definition: StringUriUtf8To32ReadResource.hpp:37
Thrown when an operation is deliberately not implemented.
Definition: BalauException.hpp:154
The abstract URI base class.
Visitor interface for URIs.
Definition: UriDispatcher.hpp:32
std::unique_ptr< Uri > resolve(std::string_view path) const override
Resolve the relative or absolute path, in reference to the current URI.
Definition: StringUri.hpp:143
A write-only String based UTF-8 resource which is written as UTF-32 characters.