| ... | ... | @@ -140,11 +140,30 @@ static inline bool buf_eql_str(Buf *buf, const char *str) { |
| 140 | 140 | return buf_eql_mem(buf, str, strlen(str)); |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | static inline bool buf_starts_with_mem(Buf *buf, const char *mem, int mem_len) { |
| 144 | if (buf_len(buf) < mem_len) { |
| 145 | return false; |
| 146 | } |
| 147 | return memcmp(buf_ptr(buf), mem, mem_len) == 0; |
| 148 | } |
| 149 | |
| 143 | 150 | static inline bool buf_starts_with_buf(Buf *buf, Buf *sub) { |
| 144 | | if (buf_len(buf) < buf_len(sub)) { |
| 151 | return buf_starts_with_mem(buf, buf_ptr(sub), buf_len(sub)); |
| 152 | } |
| 153 | |
| 154 | static inline bool buf_starts_with_str(Buf *buf, const char *str) { |
| 155 | return buf_starts_with_mem(buf, str, strlen(str)); |
| 156 | } |
| 157 | |
| 158 | static inline bool buf_ends_with_mem(Buf *buf, const char *mem, int mem_len) { |
| 159 | if (buf_len(buf) < mem_len) { |
| 145 | 160 | return false; |
| 146 | 161 | } |
| 147 | | return buf_eql_mem(sub, buf_ptr(buf), buf_len(sub)); |
| 162 | return memcmp(buf_ptr(buf) + buf_len(buf) - mem_len, mem, mem_len) == 0; |
| 163 | } |
| 164 | |
| 165 | static inline bool buf_ends_with_str(Buf *buf, const char *str) { |
| 166 | return buf_ends_with_mem(buf, str, strlen(str)); |
| 148 | 167 | } |
| 149 | 168 | |
| 150 | 169 | bool buf_eql_buf(Buf *buf, Buf *other); |