diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-22 22:26:53 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-22 22:26:53 +0000 |
commit | 62cfbad7377b4db2497fec6e88821a36a1b767fe (patch) | |
tree | c7be44ea69ddb94285d7a779ade049411fb004e1 /ui/base/l10n/l10n_util.cc | |
parent | 078ed5486f50579a03463961738f6d57759d10ce (diff) | |
download | chromium_src-62cfbad7377b4db2497fec6e88821a36a1b767fe.zip chromium_src-62cfbad7377b4db2497fec6e88821a36a1b767fe.tar.gz chromium_src-62cfbad7377b4db2497fec6e88821a36a1b767fe.tar.bz2 |
(shlib failure) Revert 97750 - content: Move render_widget_host_view_gtk to content/
This also moves some other files:
- OwnedWidgetGtk now goes in ui/base/gtk/
- TruncateString moved from l10n_util:: to ui::
- GtkIMContextWrapper has part of its code split into chrome/ (IDC using code goes in RenderViewContextMenu) and the rest go in content/ (gtk using code goes with GtkIMContextWrapper).
- gtk_key_bindings_handler[_unittest] now goes in content, as it's a utility class to RenderWidgetHostGtk.
BUG=93804
TEST=existing unit tests
Review URL: http://codereview.chromium.org/7669040
TBR=erg@google.com
Review URL: http://codereview.chromium.org/7708017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97756 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base/l10n/l10n_util.cc')
-rw-r--r-- | ui/base/l10n/l10n_util.cc | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/ui/base/l10n/l10n_util.cc b/ui/base/l10n/l10n_util.cc index cabda81..ae7e710 100644 --- a/ui/base/l10n/l10n_util.cc +++ b/ui/base/l10n/l10n_util.cc @@ -741,6 +741,69 @@ string16 GetStringFUTF16Int(int message_id, int64 a) { return GetStringFUTF16(message_id, UTF8ToUTF16(base::Int64ToString(a))); } +string16 TruncateString(const string16& string, size_t length) { + if (string.size() <= length) + // String fits, return it. + return string; + + if (length == 0) { + // No room for the elide string, return an empty string. + return string16(); + } + size_t max = length - 1; + + // Added to the end of strings that are too big. + static const char16 kElideString[] = { 0x2026, 0 }; + + if (max == 0) { + // Just enough room for the elide string. + return kElideString; + } + + // Use a line iterator to find the first boundary. + UErrorCode status = U_ZERO_ERROR; + scoped_ptr<icu::RuleBasedBreakIterator> bi( + static_cast<icu::RuleBasedBreakIterator*>( + icu::RuleBasedBreakIterator::createLineInstance( + icu::Locale::getDefault(), status))); + if (U_FAILURE(status)) + return string.substr(0, max) + kElideString; + bi->setText(string.c_str()); + int32_t index = bi->preceding(static_cast<int32_t>(max)); + if (index == icu::BreakIterator::DONE) { + index = static_cast<int32_t>(max); + } else { + // Found a valid break (may be the beginning of the string). Now use + // a character iterator to find the previous non-whitespace character. + icu::StringCharacterIterator char_iterator(string.c_str()); + if (index == 0) { + // No valid line breaks. Start at the end again. This ensures we break + // on a valid character boundary. + index = static_cast<int32_t>(max); + } + char_iterator.setIndex(index); + while (char_iterator.hasPrevious()) { + char_iterator.previous(); + if (!(u_isspace(char_iterator.current()) || + u_charType(char_iterator.current()) == U_CONTROL_CHAR || + u_charType(char_iterator.current()) == U_NON_SPACING_MARK)) { + // Not a whitespace character. Advance the iterator so that we + // include the current character in the truncated string. + char_iterator.next(); + break; + } + } + if (char_iterator.hasPrevious()) { + // Found a valid break point. + index = char_iterator.getIndex(); + } else { + // String has leading whitespace, return the elide string. + return kElideString; + } + } + return string.substr(0, index) + kElideString; +} + // Compares the character data stored in two different string16 strings by // specified Collator instance. UCollationResult CompareString16WithCollator(const icu::Collator* collator, |