aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/Utilities/Containers.h16
-rw-r--r--src/common/Utilities/Util.cpp6
2 files changed, 11 insertions, 11 deletions
diff --git a/src/common/Utilities/Containers.h b/src/common/Utilities/Containers.h
index cf4d31d4dc2..01ffac76769 100644
--- a/src/common/Utilities/Containers.h
+++ b/src/common/Utilities/Containers.h
@@ -41,7 +41,7 @@ namespace Trinity
}
template <class T>
- class BufferWriteGuard
+ class CheckedBufferOutputIterator
{
public:
using iterator_category = std::output_iterator_tag;
@@ -50,20 +50,20 @@ namespace Trinity
using reference = T&;
using difference_type = std::ptrdiff_t;
- BufferWriteGuard(T* buf, size_t n) : _buf(buf), _n(n) {}
+ CheckedBufferOutputIterator(T* buf, size_t n) : _buf(buf), _end(buf+n) {}
T& operator*() const { check(); return *_buf; }
- BufferWriteGuard& operator++() { check(); ++_buf; --_n; return *this; }
- T* operator++(int) { check(); T* b = _buf; ++_buf; --_n; return b; }
+ CheckedBufferOutputIterator& operator++() { check(); ++_buf; return *this; }
+ CheckedBufferOutputIterator operator++(int) { CheckedBufferOutputIterator v = *this; operator++(); return v; }
- size_t size() const { return _n; }
+ size_t remaining() const { return (_end - _buf); }
private:
T* _buf;
- size_t _n;
- void check()
+ T* _end;
+ void check() const
{
- if (!_n)
+ if (!(_buf < _end))
throw std::out_of_range("index");
}
};
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp
index 36099263c03..099de72c7af 100644
--- a/src/common/Utilities/Util.cpp
+++ b/src/common/Utilities/Util.cpp
@@ -251,9 +251,9 @@ bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize)
{
try
{
- Trinity::BufferWriteGuard<wchar_t> guard(wstr, wsize);
- guard = utf8::utf8to16(utf8str, utf8str+csize, guard);
- wsize -= guard.size(); // remaining unused space
+ Trinity::CheckedBufferOutputIterator<wchar_t> out(wstr, wsize);
+ out = utf8::utf8to16(utf8str, utf8str+csize, out);
+ wsize -= out.remaining(); // remaining unused space
wstr[wsize] = L'\0';
}
catch (std::exception const&)