let first_sentence ?(limit=40) s =
  let rec get_before_dot s =
    try
      let len = String.length s in
      let n = String.index s '.' in
      if n + 1 >= len then
        (* the dot is the last character *)
        (true, s)
      else
        (
         match s.[n+1] with
           ' ' | '\n' | '\r' | '\t' ->
             (trueString.sub s 0 (n+1))
         | _ ->
             let (b, s2) = get_before_dot (String.sub s (n + 1) (len - n - 1)) in
             (b, (String.sub s 0 (n+1))^s2)
        )
    with
      Not_found -> (false, s)
  in
  let len = String.length s in
  let s_limited =
    if len > limit then
      String.sub s 0 limit
    else
      s
  in
  let (found, res) = get_before_dot s_limited in
  if found then
    res
  else
    if len > limit then
      if limit > 3 then
        (String.sub s_limited 0 (limit - 3) ^ "...")
      else
        s_limited
    else
      s