Listing 1: Making a substring from a substring-optimized string object

void
OptStr::MakSubStr(int SubOff, // Offset where the sub-string 
                              // should start.               
                  int SubLen) // Length of sub-string to be  
                              // formed.                     
{
   if (SubOff < 0)      // If offset is before beginning of  
   {                    // string.                           
      SubLen += SubOff; // Set length to start at beginning. 
      SubOff = 0;       // Start at beginning.               
   }
   // Insure SubLen is positive and doesn't extend past the  
   // end of string.                                         
   SubLen = MinInt(SubLen,Len-SubOff));
   SubLen = MaxInt(0,SubLen);

   Len = SubLen;        // Set the sub-string's length.      
   if (Len)             // If the length is not 0, then      
      Off += SubOff;    // Set sub-string's starting offset. 
   else                 // Oherwise, if length is 0, then    
      Off = 0;          // Zero sub-string's starting offset.
}