code-experiments/src/coco_string.c
/**
 * @brief Returns the first index where seq occurs in base and -1 if it doesn't.
 *
 * @note If there is an equivalent standard C function, this can/should be removed.
 */
@brief Returns the first index where seq occurs in base and -1 if it doesn't.
@note If there is an equivalent standard C function, this can/should be removed.
@brief Returns the first index where seq occurs in base and - 1 if it doesn ' t . @note If there is an equivalent standard C function this can / should be removed .
static long coco_strfind(const char *base, const char *seq) {
  const size_t strlen_seq = strlen(seq);
  const size_t last_first_idx = strlen(base) - strlen(seq);
  size_t i, j;
  if (strlen(base) < strlen(seq))
    return -1;
  for (i = 0; i <= last_first_idx; ++i) {
    if (base[i] == seq[0]) {
      for (j = 0; j < strlen_seq; ++j) {
        if (base[i + j] != seq[j])
          break;
      }
      if (j == strlen_seq) {
        if (i > 1e9)
          coco_error("coco_strfind(): strange values observed i=%lu, j=%lu, strlen(base)=%lu",
          		(unsigned long) i, (unsigned long) j, (unsigned long) strlen(base));
        return (long) i;
      }
    }
  }
  return -1;
}
static long coco_strfind ( const char * base , const char * seq ) { const size_t strlen_seq = strlen ( seq ) ; const size_t last_first_idx = strlen ( base ) - strlen ( seq ) ; size_t i , j ; if ( strlen ( base ) < strlen ( seq ) ) return -1 ; for ( i = 0 ; i <= last_first_idx ; ++ i ) { if ( base [ i ] == seq [ 0 ] ) { for ( j = 0 ; j < strlen_seq ; ++ j ) { if ( base [ i + j ] != seq [ j ] ) break ; } if ( j == strlen_seq ) { if ( i > 1e9 ) coco_error ( " " , ( unsigned long ) i , ( unsigned long ) j , ( unsigned long ) strlen ( base ) ) ; return ( long ) i ; } } } return -1 ; }
@brief Returns the first index where seq occurs in base and -1 if it doesn't.
@brief Returns the first index where seq occurs in base and - 1 if it doesn ' t .