made an index_of() method for StringValue, which calculates the index of

a char
This commit is contained in:
Kjistóf 2016-10-23 15:28:28 +02:00
parent 8dcfca2d62
commit 44ef56941e
2 changed files with 11 additions and 1 deletions

View File

@ -38,3 +38,12 @@ StringValue::operator const char*() const
size_t StringValue::size() const
{ 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!");
}

View File

@ -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;
};