made an index_of() method for StringValue, which calculates the index of
a char
This commit is contained in:
parent
8dcfca2d62
commit
44ef56941e
@ -37,4 +37,13 @@ StringValue::operator const char*() const
|
||||
{ return _data; }
|
||||
|
||||
size_t StringValue::size() const
|
||||
{ return _size - 1; }
|
||||
{ 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!");
|
||||
}
|
@ -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;
|
||||
};
|
Loading…
Reference in New Issue
Block a user