- // the start & end of the removed span of chars
- initialCharToRemove = len/2;
- size_t endChar = len/2;
+ // NOTE: the following piece of code works also when len == 1
+
+ // start the removal process from the middle of the string
+ // i.e. separe the string in three parts:
+ // - the first one to preserve, valid range [0;initialCharToRemove-1] or the empty range if initialCharToRemove==0
+ // - the second one to remove, valid range [initialCharToRemove;endCharToRemove]
+ // - the third one to preserve, valid range [endCharToRemove+1;len-1] or the empty range if endCharToRemove==len-1
+ // NOTE: empty range != range [0;0] since the range [0;0] contains 1 character (the zero-th one)!
+ initialCharToRemove = len/2; // index of the last character to remove; valid range is [0;len-1]
+ size_t endCharToRemove = initialCharToRemove - 1; // initial removal range is empty