 
 func charAt(s : String, i : Int) -> Character {
   let index = s.index(s.startIndex, offsetBy: i);
+  assert(index < s.endIndex);
   return s[index];
 }
 


  var (i, space, index) = (size + 1, false, point);
  index += 1;
  var currentChar : Character = " ";

  while (i < s.characters.count &&
  !space && index < asciiString.characters.count) {

      s = setCharAt(s: s, n: i, c: x);
      i -= 1;
      space = false;
    } else {
      if !space { i -= 1; space = true; }
    }
    index -= 1;
  }
  return s;
}

let contextSize = 10;

func matchPattern(dlist : [String: Int], point : Int) -> Bool {
  var rank = dlist.count * 2;
  let s = getContext(size: contextSize, point: point);
  var (start, end, _len) = (0, 0, s.characters.count);

  while start <= contextSize {
    end = contextSize + 1;
    while end <= _len {
      let s = substring(x: start, y: end, s: s);
      if let r = dlist[s] { if abs(r) < abs(rank) { rank = r; } }
      end += 1;
    }
    start += 1;
  }
  return rank > 0;
}

func needsCorrectionAux(c : Character, point : Int) -> Bool {
