- char operator[](lenpos_t i) const {
- if (s && i < sSize) // Or < sLen? Depends on the use, both are OK
- return s[i];
- else
- return '\0';
- }
- SString substr(lenpos_t subPos, lenpos_t subLen=measure_length) const {
- if (subPos >= sLen) {
- return SString(); // return a null string if start index is out of bounds
- }
- if ((subLen == measure_length) || (subPos + subLen > sLen)) {
- subLen = sLen - subPos; // can't substr past end of source string
- }
- return SString(s, subPos, subPos + subLen);
- }
- SString &lowercase(lenpos_t subPos = 0, lenpos_t subLen=measure_length) {
- if ((subLen == measure_length) || (subPos + subLen > sLen)) {
- subLen = sLen - subPos; // don't apply past end of string
- }
- for (lenpos_t i = subPos; i < subPos + subLen; i++) {
- if (s[i] < 'A' || s[i] > 'Z')
- continue;
- else
- s[i] = static_cast<char>(s[i] - 'A' + 'a');
- }
- return *this;
- }
- SString &append(const char *sOther, lenpos_t sLenOther=measure_length, char sep = '\0') {
- if (!sOther) {
- return *this;
- }
- if (sLenOther == measure_length) {
- sLenOther = strlen(sOther);
- }
- int lenSep = 0;
- if (sLen && sep) { // Only add a separator if not empty
- lenSep = 1;
- }
- lenpos_t lenNew = sLen + sLenOther + lenSep;
- // Conservative about growing the buffer: don't do it, unless really needed
- if ((lenNew + 1 < sSize) || (grow(lenNew))) {
- if (lenSep) {
- s[sLen] = sep;
- sLen++;
- }
- memcpy(&s[sLen], sOther, sLenOther);
- sLen += sLenOther;
- s[sLen] = '\0';
- }
- return *this;
- }
+ SString substr(lenpos_t subPos, lenpos_t subLen=measure_length) const;
+ SString &lowercase(lenpos_t subPos = 0, lenpos_t subLen=measure_length);
+ SString &uppercase(lenpos_t subPos = 0, lenpos_t subLen=measure_length);
+ SString &append(const char *sOther, lenpos_t sLenOther=measure_length, char sep = '\0');