diff options
Diffstat (limited to 'src/base/io')
| -rw-r--r-- | src/base/io/BufferStream.cpp | 2 | ||||
| -rw-r--r-- | src/base/io/CFileStream.cpp | 12 | ||||
| -rw-r--r-- | src/base/io/MemoryStream.cpp | 4 | ||||
| -rw-r--r-- | src/base/io/Resource.cpp | 2 | ||||
| -rw-r--r-- | src/base/io/Stream.cpp | 34 |
5 files changed, 25 insertions, 29 deletions
diff --git a/src/base/io/BufferStream.cpp b/src/base/io/BufferStream.cpp index 57a8b694..0dbb438b 100644 --- a/src/base/io/BufferStream.cpp +++ b/src/base/io/BufferStream.cpp @@ -57,7 +57,7 @@ Index BufferStream::DoWrite(const std::byte* buffer, Index offset, Index size) { if (eof_) { throw WriteAfterEofException( - u"Stream has been set eof. Can't write to it any more."); + "Stream has been set eof. Can't write to it any more."); } condition_variable_.wait(lock, [this] { diff --git a/src/base/io/CFileStream.cpp b/src/base/io/CFileStream.cpp index 45eb2eaf..f0d4790b 100644 --- a/src/base/io/CFileStream.cpp +++ b/src/base/io/CFileStream.cpp @@ -28,7 +28,7 @@ CFileStream::CFileStream(const char* path, const char* mode) file_(std::fopen(path, mode)), auto_close_(true) { if (file_ == nullptr) { - throw ErrnoException(u"Cannot open file."); + throw ErrnoException("Cannot open file."); } } @@ -36,7 +36,7 @@ CFileStream::CFileStream(std::FILE* file, bool readable, bool writable, bool auto_close) : Stream(true, readable, writable), file_(file), auto_close_(auto_close) { if (file_ == nullptr) { - throw Exception(u"File is NULL."); + throw Exception("File is NULL."); } } @@ -55,13 +55,13 @@ static int ConvertOriginFlag(Stream::SeekOrigin origin) { case Stream::SeekOrigin::End: return SEEK_END; default: - throw Exception(u"Unknown seek origin."); + throw Exception("Unknown seek origin."); } } Index CFileStream::DoSeek(Index offset, SeekOrigin origin) { if (std::fseek(file_, offset, ConvertOriginFlag(origin))) { - throw ErrnoException(u"Seek failed."); + throw ErrnoException("Seek failed."); } return DoTell(); } @@ -69,7 +69,7 @@ Index CFileStream::DoSeek(Index offset, SeekOrigin origin) { Index CFileStream::DoTell() { long position = std::ftell(file_); if (position == -1) { - throw ErrnoException(u"Tell failed."); + throw ErrnoException("Tell failed."); } return position; } @@ -91,7 +91,7 @@ void CFileStream::DoFlush() { std::fflush(file_); } void CFileStream::DoClose() { CRU_STREAM_BEGIN_CLOSE if (auto_close_ && !std::fclose(file_)) { - throw Exception(u"Failed to close FILE."); + throw Exception("Failed to close FILE."); } file_ = nullptr; } diff --git a/src/base/io/MemoryStream.cpp b/src/base/io/MemoryStream.cpp index 4c650f3e..bba0e618 100644 --- a/src/base/io/MemoryStream.cpp +++ b/src/base/io/MemoryStream.cpp @@ -14,10 +14,10 @@ MemoryStream::MemoryStream( position_(0), release_func_(std::move(release_func)) { if (!buffer) { - throw Exception(u"Buffer is nullptr"); + throw Exception("Buffer is nullptr"); } if (size <= 0) { - throw Exception(u"Size is 0 or negative."); + throw Exception("Size is 0 or negative."); } } diff --git a/src/base/io/Resource.cpp b/src/base/io/Resource.cpp index e599f8a9..48045e59 100644 --- a/src/base/io/Resource.cpp +++ b/src/base/io/Resource.cpp @@ -49,7 +49,7 @@ std::filesystem::path GetResourceDir() { } } - throw Exception(u"Failed to find resource directory."); + throw Exception("Failed to find resource directory."); #endif diff --git a/src/base/io/Stream.cpp b/src/base/io/Stream.cpp index 4cb58eca..1aafc839 100644 --- a/src/base/io/Stream.cpp +++ b/src/base/io/Stream.cpp @@ -6,28 +6,24 @@ namespace cru::io { StreamOperationNotSupportedException::StreamOperationNotSupportedException( - StringView operation) - : StreamOperationNotSupportedException(operation.ToUtf8()) {} - -StreamOperationNotSupportedException::StreamOperationNotSupportedException( std::string operation) : Exception(std::format("Stream operation {} not supported.", operation)), operation_(std::move(operation)) {} void StreamOperationNotSupportedException::CheckSeek(bool seekable) { - if (!seekable) throw StreamOperationNotSupportedException(u"seek"); + if (!seekable) throw StreamOperationNotSupportedException("seek"); } void StreamOperationNotSupportedException::CheckRead(bool readable) { - if (!readable) throw StreamOperationNotSupportedException(u"read"); + if (!readable) throw StreamOperationNotSupportedException("read"); } void StreamOperationNotSupportedException::CheckWrite(bool writable) { - if (!writable) throw StreamOperationNotSupportedException(u"write"); + if (!writable) throw StreamOperationNotSupportedException("write"); } StreamClosedException::StreamClosedException() - : Exception(u"Stream is already closed.") {} + : Exception("Stream is already closed.") {} void StreamClosedException::Check(bool closed) { if (closed) throw StreamClosedException(); @@ -122,8 +118,8 @@ bool Stream::DoCanSeek() { return *supported_operations_->can_seek; } else { throw Exception( - u"Can seek is neither set in supported_operations nor implemeted in " - u"virtual function."); + "Can seek is neither set in supported_operations nor implemeted in " + "virtual function."); } } @@ -132,8 +128,8 @@ bool Stream::DoCanRead() { return *supported_operations_->can_read; } else { throw Exception( - u"Can read is neither set in supported_operations nor implemeted in " - u"virtual function."); + "Can read is neither set in supported_operations nor implemeted in " + "virtual function."); } } @@ -142,13 +138,13 @@ bool Stream::DoCanWrite() { return *supported_operations_->can_write; } else { throw Exception( - u"Can write is neither set in supported_operations nor implemeted in " - u"virtual function."); + "Can write is neither set in supported_operations nor implemeted in " + "virtual function."); } } Index Stream::DoSeek(Index offset, SeekOrigin origin) { - throw Exception(u"Stream is seekable but DoSeek is not implemented."); + throw Exception("Stream is seekable but DoSeek is not implemented."); } Index Stream::DoTell() { @@ -171,11 +167,11 @@ Index Stream::DoGetSize() { } Index Stream::DoRead(std::byte* buffer, Index offset, Index size) { - throw Exception(u"Stream is readable but DoRead is not implemented."); + throw Exception("Stream is readable but DoRead is not implemented."); } Index Stream::DoWrite(const std::byte* buffer, Index offset, Index size) { - throw Exception(u"Stream is writable but DoWrite is not implemented."); + throw Exception("Stream is writable but DoWrite is not implemented."); } void Stream::DoFlush() {} @@ -195,8 +191,8 @@ Buffer Stream::ReadToEnd(Index grow_size) { return buffer; } -String Stream::ReadToEndAsUtf8String() { +std::string Stream::ReadToEndAsUtf8String() { auto buffer = ReadToEnd(); - return String::FromUtf8(buffer); + return std::string(buffer.GetUsedBeginPtr(), buffer.GetUsedEndPtr()); } } // namespace cru::io |
