aboutsummaryrefslogtreecommitdiff
path: root/src/string.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/string.cpp')
-rw-r--r--src/string.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/string.cpp b/src/string.cpp
index e1c4cf9..d0361e6 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -39,6 +39,9 @@
namespace {
char kEmptyString[1] = { '\0' };
+// Dummy char used in the 'at' accessor when the index is out of
+// range.
+char sDummy;
}
namespace std {
@@ -446,6 +449,26 @@ char& string::operator[](const size_type pos)
return mData[pos];
}
+const char& string::at(const size_type pos) const
+{
+ if (pos < mLength) {
+ return mData[pos];
+ } else {
+ sDummy = 'X';
+ return sDummy;
+ }
+}
+
+char& string::at(const size_type pos)
+{
+ if (pos < mLength) {
+ return mData[pos];
+ } else {
+ sDummy = 'X';
+ return sDummy;
+ }
+}
+
string& string::assign(const string& str)
{
clear();