blob: 0202285231bba4aa5aa9b0e0cd83f5756dadfdb6 [file] [log] [blame]
droger8eabfbc2014-12-09 13:57:211// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ios/web/public/string_util.h"
6
avi571943672015-12-22 02:12:497#include <stddef.h>
8
droger8eabfbc2014-12-09 13:57:219#include "base/strings/string_util.h"
10
11namespace web {
12
13base::string16 GetStringByClippingLastWord(const base::string16& contents,
14 size_t length) {
15 if (contents.size() < length)
16 return contents;
17
18 base::string16 clipped_contents = contents.substr(0, length);
19 size_t last_space_index =
20 clipped_contents.find_last_of(base::kWhitespaceUTF16);
21 // TODO(droger): Check if we should return the empty string instead.
22 // See http://crbug.com/324304
23 if (last_space_index != base::string16::npos)
24 clipped_contents.resize(last_space_index);
25 return clipped_contents;
26}
27
28} // namespace web