code: func Expand(input string, mapping func(string) string) string {
  	var buf bytes.Buffer
  	checkpoint := 0
  	for cursor := 0; cursor < len(input); cursor++ {
  		if input[cursor] == operator && cursor+1 < len(input) {
  			// Copy the portion of the input string since the last
  			// checkpoint into the buffer
  			buf.WriteString(input[checkpoint:cursor])
  
  			// Attempt to read the variable name as defined by the
  			// syntax from the input string
  			read, isVar, advance := tryReadVariableName(input[cursor+1:])
  
  			if isVar {
  				// We were able to read a variable name correctly;
  				// apply the mapping to the variable name and copy the
  				// bytes into the buffer
  				buf.WriteString(mapping(read))
  			} else {
  				// Not a variable name; copy the read bytes into the buffer
  				buf.WriteString(read)
  			}
  
  			// Advance the cursor in the input string to account for
  			// bytes consumed to read the variable name expression
  			cursor += advance
  
  			// Advance the checkpoint in the input string
  			checkpoint = cursor + 1
  		}
  	}
  
  	// Return the buffer and any remaining unwritten bytes in the
  	// input string.
  	return buf.String() + input[checkpoint:]
  }
docs: // Expand replaces variable references in the input string according to
  // the expansion spec using the given mapping function to resolve the
  // values of variables.