title: What is the best way to test if a CharacterSet contains a Character in Swift 4?
body: <p>I'm looking for a way, in Swift 4, to test if a Character is a member of an arbitrary CharacterSet.  I have this <code>Scanner</code> class that will be used for some lightweight parsing.  One of the functions in the class is to skip any characters, at the current position, that belong to a certain set of possible characters.</p>
  
  <pre><code>class MyScanner {
    let str: String
    var idx: String.Index
    init(_ string: String) {
      str = string
      idx = str.startIndex
    }
    var remains: String { return String(str[idx..&lt;str.endIndex])}
  
    func skip(charactersIn characters: CharacterSet) {
      while idx &lt; str.endIndex &amp;&amp; characters.contains(str[idx])) {
        idx = source.index(idx, offsetBy: 1)
      }
    }
  }
  
  let scanner = MyScanner("fizz   buzz fizz")
  scanner.skip(charactersIn: CharacterSet.alphanumerics)
  scanner.skip(charactersIn: CharacterSet.whitespaces)
  print("what remains: \"\(scanner.remains)\"")
  </code></pre>
  
  <p>I would like to implement the <code>skip(charactersIn:)</code> function so that the above code would print <code>buzz fizz</code>.</p>
  
  <p>The tricky part is <code>characters.contains(str[idx]))</code> in the <code>while</code> - <code>.contains()</code> requires a <code>Unicode.Scalar</code>, and I'm at a loss trying to figure out the next step.</p>
  
  <p>I know I could pass in a <code>String</code> to the <code>skip</code> function, but I'd like to find a way to make it work with a <code>CharacterSet</code>, because of all the convenient static members (<code>alphanumerics</code>, <code>whitespaces</code>, etc.).</p>
  
  <p>How does one test a <code>CharacterSet</code> if it contains a <code>Character</code>?</p>