code: int [] findTemplate( String name ) {
          String text = buff.toString();
          int len = text.length();
  
          int start = 0;
  
          while ( start < len ) {
  
              // Find begin and end comment
              int cstart = text.indexOf( "<!--", start );
              if ( cstart == -1 )
                  return null;  // no more comments
              int cend = text.indexOf( "-->", cstart );
              if ( cend == -1 )
                  return null;  // no more complete comments
              cend += "-->".length();
  
              // Find template tag
              int tstart = text.indexOf( "TEMPLATE-", cstart );
              if ( tstart == -1 ) {
                  start = cend; // try the next comment
                  continue;
              }
  
              // Is the tag inside the comment we found?
              if ( tstart > cend ) {
                  start = cend; // try the next comment
                  continue;
              }
  
              // find begin and end of param name
              int pstart = tstart + "TEMPLATE-".length();
  
              int pend = len;
              for ( pend = pstart; pend < len; pend++) {
                  char c = text.charAt( pend );
                  if ( c == ' ' || c == '\t' || c == '-' )
                      break;
              }
              if ( pend >= len )
                  return null;
  
              String param = text.substring( pstart, pend );
  
              // If it's the correct one, return the comment extent
              if ( param.equals( name ) )
                  return new int [] { cstart, cend };
  
  //System.out.println( "Found param: {"+param+"} in comment: "+ text.substring(cstart, cend) +"}");
              // Else try the next one
              start = cend;
          }
  
          // Not found
          return null;
      }
docs: Find the starting (inclusive) and ending (exclusive) index of the
  named template and return them as a two element int [].
  Or return null if the param is not found.