From: David ‘Bombe’ Roden Date: Sat, 5 Jul 2008 14:36:24 +0000 (+0200) Subject: add indexOf method X-Git-Tag: 0.1~38 X-Git-Url: https://git.pterodactylus.net/?p=ecparse.git;a=commitdiff_plain;h=9f80044fab3651986bdd2651620003f8769647b0 add indexOf method --- diff --git a/GrowingBuffer.cpp b/GrowingBuffer.cpp index a260a3d..8e3bd4a 100644 --- a/GrowingBuffer.cpp +++ b/GrowingBuffer.cpp @@ -98,3 +98,13 @@ void GrowingBuffer::resize(double factor) { } } +size_t GrowingBuffer::indexOf(char c, size_t start) { + void* foundIndex; + + foundIndex = memchr((ptrdiff_t*) data + position + start, c, (limit - start)); + if (foundIndex) { + return (ptrdiff_t) foundIndex - ((ptrdiff_t) data + position); + } + return -1; +} + diff --git a/GrowingBuffer.h b/GrowingBuffer.h index 3efa30d..a622a50 100644 --- a/GrowingBuffer.h +++ b/GrowingBuffer.h @@ -42,6 +42,8 @@ public: void clear(); void resize(double factor = 1.0); + size_t indexOf(char c, size_t start = 0); + private: void* data; size_t size;