module.exports = function Count (s, sep) {
  //  discuss at: http://locutus.io/php/printf/
  // original by: Kevin van Zonneveld (http://kvz.io)
  //    input by: GopherJS (http://www.gopherjs.org/)
  //   example 1: Count("cheese", "e")
  //   returns 1: 3
  //   example 2: Count("five", "") // before & after each rune
  //   returns 2: 5

  var Index = require('../strings/Index2')

  var pos
  var n = 0

  if ((sep.length === 0)) {
    return s.split(sep).length + 1
  } else if (sep.length > s.length) {
    return 0
  } else if ((sep.length === s.length)) {
    if (sep === s) {
      return 1
    }
    return 0
  }
  while (true) {
    pos = Index(s, sep)
    if (pos === -1) {
      break
    }
    n = n + (1) >> 0
    s = s.substring((pos + sep.length >> 0))
  }
  return n
}

module.exports = function Count (s, sep) {
  //  discuss at: http://locutus.io/php/printf/
  // original by: Kevin van Zonneveld (http://kvz.io)
  //    input by: GopherJS (http://www.gopherjs.org/)
  //   example 1: Count("cheese", "e")
  //   returns 1: 3
  //   example 2: Count("five", "") // before & after each rune
  //   returns 2: 5

  var pos
  var n = 0

  if ((sep.length === 0)) {
    return s.split(sep).length + 1
  } else if (sep.length > s.length) {
    return 0
  } else if ((sep.length === s.length)) {
    if (sep === s) {
      return 1
    }
    return 0
  }
  while (true) {
    pos = (s + '').indexOf(sep)
    if (pos === -1) {
      break
    }
    n = n + (1) >> 0
    s = s.substring((pos + sep.length >> 0))
  }
  return n
}

Remove strings.Index dependency in Go's string.Count