Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Unified Diff: ios/web/string_util.cc

Issue 780873002: Upstream iOS web code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/web/string_util.cc
diff --git a/ios/web/string_util.cc b/ios/web/string_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a00d023e35e68bd6b50e46eb1d5d00dedf93eb26
--- /dev/null
+++ b/ios/web/string_util.cc
@@ -0,0 +1,26 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ios/web/public/string_util.h"
+
+#include "base/strings/string_util.h"
+
+namespace web {
+
+base::string16 GetStringByClippingLastWord(const base::string16& contents,
+ size_t length) {
+ if (contents.size() < length)
+ return contents;
+
+ base::string16 clipped_contents = contents.substr(0, length);
+ size_t last_space_index =
+ clipped_contents.find_last_of(base::kWhitespaceUTF16);
+ // TODO(droger): Check if we should return the empty string instead.
+ // See http://crbug.com/324304
+ if (last_space_index != base::string16::npos)
+ clipped_contents.resize(last_space_index);
+ return clipped_contents;
+}
+
+} // namespace web

Powered by Google App Engine
This is Rietveld 408576698