aboutsummaryrefslogtreecommitdiff
path: root/src/buffer.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.hpp')
-rw-r--r--src/buffer.hpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/buffer.hpp b/src/buffer.hpp
index 8155df87a1..afe9fd8a91 100644
--- a/src/buffer.hpp
+++ b/src/buffer.hpp
@@ -181,5 +181,15 @@ static inline Slice<uint8_t> buf_to_slice(Buf *buf) {
return Slice<uint8_t>{reinterpret_cast<uint8_t*>(buf_ptr(buf)), buf_len(buf)};
}
+static inline void buf_replace(Buf* buf, char from, char to) {
+ const size_t count = buf_len(buf);
+ char* ptr = buf_ptr(buf);
+ for (size_t i = 0; i < count; ++i) {
+ char& l = ptr[i];
+ if (l == from)
+ l = to;
+ }
+}
+
#endif