diff options
author | nyamatongwe <devnull@localhost> | 2002-04-19 12:55:03 +0000 |
---|---|---|
committer | nyamatongwe <devnull@localhost> | 2002-04-19 12:55:03 +0000 |
commit | 13b23b3e3773f4d99fd86df2b998f4b34f0f5987 (patch) | |
tree | 8afa896d0b321f22fd6d86b2867511ec74d7f72d | |
parent | c336e28f36800549707496897820e2489ee53e00 (diff) | |
download | scintilla-mirror-13b23b3e3773f4d99fd86df2b998f4b34f0f5987.tar.gz |
Patch from Don Paul including memcpy use, comments and change method.
-rw-r--r-- | include/SString.h | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/include/SString.h b/include/SString.h index df7fd43b5..eacfef35b 100644 --- a/include/SString.h +++ b/include/SString.h @@ -22,8 +22,8 @@ bool EqualCaseInsensitive(const char *a, const char *b); * * Hold the length of the string for quick operations, * can have a buffer bigger than the string to avoid too many memory allocations and copies. - * May have embedded zeroes as a result of @a substitute, but rely too heavily on C string - * functions to allow reliable manipulations of these strings. + * May have embedded zeroes as a result of @a substitute, but relies too heavily on C string + * functions to allow reliable manipulations of these strings, other than simple appends, etc. **/ class SString { public: @@ -63,7 +63,7 @@ private: } if (sSize > 0 && sSize_ <= sSize) { // Does not allocate new buffer if the current is big enough if (s && sSize_) { - strncpy(s, sOther, sSize_); + memcpy(s, sOther, sSize_); } s[sSize_] = '\0'; sLen = sSize_; @@ -206,7 +206,7 @@ public: s[sLen] = sep; sLen++; } - strncpy(&s[sLen], sOther, sLenOther); + memcpy(&s[sLen], sOther, sLenOther); sLen += sLenOther; s[sLen] = '\0'; } @@ -259,6 +259,13 @@ public: sLen -= len; } } + SString &change(lenpos_t pos, char ch) { + if (pos >= sLen) { // character changed must be in string bounds + return *this; + } + *(s + pos) = ch; + return *this; + } /** Read an integral numeric value from the string. */ int value() const { if (s) @@ -266,7 +273,7 @@ public: else return 0; } - int search(const char *sFind, lenpos_t start=0) { + int search(const char *sFind, lenpos_t start=0) const { if (start < sLen) { const char *sFound = strstr(s + start, sFind); if (sFound) { @@ -325,7 +332,7 @@ public: } char *sNew = new char[len + 1]; if (sNew) { - strncpy(sNew, s, len); + memcpy(sNew, s, len); sNew[len] = '\0'; } return sNew; |