<commit_before>//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

func ==(lhs: String.UnicodeScalarView.IndexType, rhs: String.UnicodeScalarView.IndexType) -> Bool {
  return lhs._position == rhs._position
}

extension String {
  struct UnicodeScalarView : Sliceable, Sequence {
    init(_ _base: _StringCore) {
      self._base = _base
    }

    struct ScratchGenerator : Generator {
      var base :_StringCore
      var idx : Int
      init(_ core : _StringCore, _ pos : Int) {
        idx = pos
        base = core
      }
      mutating func next() -> UTF16.CodeUnit? {
        return self.base[idx++]
      }
    }

    // FIXME: This index should probably become bidirectional, as UTF16
    // is traversable in either direction.
    struct IndexType : BidirectionalIndex {
      init(_ _position: Int, _ _base: _StringCore) {
        self._position = _position
        self._base = _base
      }

      func succ() -> IndexType {
        var scratch = ScratchGenerator(_base, _position)
        UTF16.decode(&scratch)
        return IndexType(scratch.idx, _base)
      }

      func pred() -> IndexType {
        var i = _position
        let codeUnit = self._base[--i]
        if codeUnit >= 0xD800 && codeUnit <= 0xE000 {
          --i
        }
        return IndexType(i, _base)
      }
      
      var _position: Int
      var _base: _StringCore
    }

    var startIndex: IndexType {
      return IndexType(_base.startIndex, _base)
    }
    
    var endIndex: IndexType {
      return IndexType(_base.endIndex, _base)
    }
    
    subscript(i: IndexType) -> UnicodeScalar {
      var scratch = ScratchGenerator(_base, i._position)
      return UTF16.decode(&scratch)!
    }

    func __slice__(start: IndexType, end: IndexType) -> UnicodeScalarView {
      return UnicodeScalarView(_base[start._position..end._position])
    }

    subscript(r: Range<IndexType>) -> UnicodeScalarView {
      return UnicodeScalarView(_base[r.startIndex._position..r.endIndex._position])
    }

    struct GeneratorType : Generator {
      init(_ _base: _StringCore.GeneratorType) {
        self._base = _base
      }

      mutating func next() -> UnicodeScalar? {
        return UTF16.decode(&self._base)
      }
      var _base: _StringCore.GeneratorType<commit_msg>[stdlib] 80-column fixes<commit_after>//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

func ==(
  lhs: String.UnicodeScalarView.IndexType,
  rhs: String.UnicodeScalarView.IndexType
) -> Bool {
  return lhs._position == rhs._position
}

extension String {
  struct UnicodeScalarView : Sliceable, Sequence {
    init(_ _base: _StringCore) {
      self._base = _base
    }

    struct ScratchGenerator : Generator {
      var base :_StringCore
      var idx : Int
      init(_ core : _StringCore, _ pos : Int) {
        idx = pos
        base = core
      }
      mutating func next() -> UTF16.CodeUnit? {
        return self.base[idx++]
      }
    }

    // FIXME: This index should probably become bidirectional, as UTF16
    // is traversable in either direction.
    struct IndexType : BidirectionalIndex {
      init(_ _position: Int, _ _base: _StringCore) {
        self._position = _position
        self._base = _base
      }

      func succ() -> IndexType {
        var scratch = ScratchGenerator(_base, _position)
        UTF16.decode(&scratch)
        return IndexType(scratch.idx, _base)
      }

      func pred() -> IndexType {
        var i = _position
        let codeUnit = self._base[--i]
        if codeUnit >= 0xD800 && codeUnit <= 0xE000 {
          --i
        }
        return IndexType(i, _base)
      }
      
      var _position: Int
      var _base: _StringCore
    }

    var startIndex: IndexType {
      return IndexType(_base.startIndex, _base)
    }
    
    var endIndex: IndexType {
      return IndexType(_base.endIndex, _base)
    }
    
    subscript(i: IndexType) -> UnicodeScalar {
      var scratch = ScratchGenerator(_base, i._position)
      return UTF16.decode(&scratch)!
    }

    func __slice__(start: IndexType, end: IndexType) -> UnicodeScalarView {
      return UnicodeScalarView(_base[start._position..end._position])
    }

    subscript(r: Range<IndexType>) -> UnicodeScalarView {
      return UnicodeScalarView(
        _base[r.startIndex._position..r.endIndex._position])
    }

    struct GeneratorType : Generator {
      init(_ _base: _StringCore.GeneratorType) {
        self._base = _base
      }

      mutating func next() -> UnicodeScalar? {
        return UTF16.decode(&self._base)
      }
      var _base: _StringCore.GeneratorType
{'fraction_non_alphanumeric': 0.15109090909090908, 'fraction_numerical': 0.010545454545454545, 'mean_word_length': 2.0043691971600217, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7647709', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1520, 'n_words': 406}