code: public int spanAndCount(CharSequence s, int start, SpanCondition spanCondition,
              OutputInt outCount) {
          if (spanCondition == SpanCondition.NOT_CONTAINED) {
              return spanNot(s, start, outCount);
          }
          // Consider strings; they may overlap with the span,
          // and they may result in a smaller count that with just code points.
          if (spanCondition == SpanCondition.CONTAINED) {
              return spanContainedAndCount(s, start, outCount);
          }
          // SIMPLE (not synchronized, does not use offsets)
          int stringsLength = strings.size();
          int length = s.length();
          int pos = start;
          int rest = length - start;
          int count = 0;
          while (rest != 0) {
              // Try to match the next code point.
              int cpLength = spanOne(spanSet, s, pos, rest);
              int maxInc = (cpLength > 0) ? cpLength : 0;
              // Try to match all of the strings.
              for (int i = 0; i < stringsLength; ++i) {
                  String string = strings.get(i);
                  int length16 = string.length();
                  if (maxInc < length16 && length16 <= rest &&
                          matches16CPB(s, pos, length, string, length16)) {
                      maxInc = length16;
                  }
              }
              // We are done if there is no match beyond pos.
              if (maxInc == 0) {
                  outCount.value = count;
                  return pos;
              }
              // Continue from the longest match.
              ++count;
              pos += maxInc;
              rest -= maxInc;
          }
          outCount.value = count;
          return pos;
      }
docs: Spans a string and counts the smallest number of set elements on any path across the span.
  
  <p>For proper counting, we cannot ignore strings that are fully contained in code point spans.
  
  <p>If the set does not have any fully-contained strings, then we could optimize this
  like span(), but such sets are likely rare, and this is at least still linear.
  
  @param s The string to be spanned
  @param start The start index that the span begins
  @param spanCondition The span condition
  @param outCount The count
  @return the limit (exclusive end) of the span