This is the substring method of the String library in Energia.
1 String String::substring(unsigned int left, unsigned int right) const
2 {
3 if (left > right) {
4 unsigned int temp = right;
5 right = left;
6 left = temp;
7 }
8 String out;
9 if (left >= len) return out;
10 if (right > len) right = len;
11 char temp = buffer[right]; // save the replaced character
12 buffer[right] = '\0';
13 out = buffer + left; // pointer arithmetic
14 buffer[right] = temp; //restore character
15 return out;
16 }
Line 12: That seems to set the right character to 0 rather than bringing it into the substring, right?
Line 8: Unsure I understand how memory and object management works in this world and its libraries. Looks like it would allocate space for the object “out” on the stack. Is “out” the object on the stack or perhaps a pointer to the object? Is “String out” the equivalent of “String *out = new String()” ?
Thank you for replying!