diff --git a/StringValue.cpp b/StringValue.cpp index 90426ad..cee8e78 100644 --- a/StringValue.cpp +++ b/StringValue.cpp @@ -37,4 +37,13 @@ StringValue::operator const char*() const { return _data; } size_t StringValue::size() const -{ return _size - 1; } \ No newline at end of file +{ return _size - 1; } + +size_t StringValue::index_of(char* c) const +{ + size_t index = c - _data; // this is totally safe pointer-arithmetic + if (index <= this->size()) // if it is within our data + return index; + else + throw std::invalid_argument("char* not within held data!"); +} \ No newline at end of file diff --git a/StringValue.h b/StringValue.h index 1a65bba..5cebb8a 100644 --- a/StringValue.h +++ b/StringValue.h @@ -28,4 +28,5 @@ public: char& operator[](size_t index); operator const char*() const; size_t size() const; + size_t index_of(char* c) const; }; \ No newline at end of file