code: public static int count(CharSequence self, CharSequence text) {
          int answer = 0;
          for (int idx = 0; true; idx++) {
              idx = self.toString().indexOf(text.toString(), idx);
              // break once idx goes to -1 or for case of empty string once
              // we get to the end to avoid JDK library bug (see GROOVY-5858)
              if (idx < answer) break;
              ++answer;
          }
          return answer;
      }
docs: Count the number of occurrences of a sub CharSequence.
  
  @param self a CharSequence
  @param text a sub CharSequence
  @return the number of occurrences of the given CharSequence inside this CharSequence
  @see #count(String, String)
  @since 1.8.2