code: public CharSequence trim(CharSequence sequence, TrimOption trimOption, SpanCondition spanCondition) {
          int endLeadContained, startTrailContained;
          final int length = sequence.length();
          if (trimOption != TrimOption.TRAILING) {
              endLeadContained = unicodeSet.span(sequence, spanCondition);
              if (endLeadContained == length) {
                  return "";
              }
          } else {
              endLeadContained = 0;
          }
          if (trimOption != TrimOption.LEADING) {
              startTrailContained = unicodeSet.spanBack(sequence, spanCondition);
          } else {
              startTrailContained = length;
          }
          return endLeadContained == 0 && startTrailContained == length ? sequence : sequence.subSequence(
                  endLeadContained, startTrailContained);
      }
docs: Returns a trimmed sequence (using CharSequence.subsequence()), that omits matching elements at the start or
  end of the string, depending on the trimOption and spanCondition. For example:
  
  <pre>
  {@code
  
  new UnicodeSet("[ab]").trim("abacatbab", TrimOption.LEADING, SpanCondition.SIMPLE)}
  </pre>
  
  ... returns {@code "catbab"}.
  
  @param sequence
  the sequence to trim
  @param trimOption
  LEADING, TRAILING, or BOTH
  @param spanCondition
  SIMPLE, CONTAINED or NOT_CONTAINED
  @return a subsequence