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

Unified Diff: third_party/WebKit/Source/platform/LayoutLocale.cpp

Issue 2715153003: Implement 'normal', 'strict', and 'loose' of the 'line-break' property (Closed)
Patch Set: Rebase Created 3 years, 10 months 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: third_party/WebKit/Source/platform/LayoutLocale.cpp
diff --git a/third_party/WebKit/Source/platform/LayoutLocale.cpp b/third_party/WebKit/Source/platform/LayoutLocale.cpp
index b4153d364ab07b8cfe48e1d2c86e1de02623ec98..dcda244d1eb76f581c4a706e08f70ae25af6c3ca 100644
--- a/third_party/WebKit/Source/platform/LayoutLocale.cpp
+++ b/third_party/WebKit/Source/platform/LayoutLocale.cpp
@@ -6,6 +6,7 @@
#include "platform/Language.h"
#include "platform/fonts/AcceptLanguagesResolver.h"
+#include "platform/text/ICUError.h"
#include "platform/text/LocaleToScriptMapping.h"
#include "wtf/HashMap.h"
#include "wtf/text/AtomicStringHash.h"
@@ -183,4 +184,54 @@ void LayoutLocale::setHyphenationForTesting(
locale.m_hyphenation = hyphenation;
}
+AtomicString LayoutLocale::localeWithBreakKeyword(
+ LineBreakIteratorMode mode) const {
+ if (m_string.isEmpty())
+ return m_string;
+
+ CString utf8Locale = m_string.utf8();
+ Vector<char> buffer(utf8Locale.length() + 11, 0);
+ memcpy(buffer.data(), utf8Locale.data(), utf8Locale.length());
+
+ const char* keywordValue = nullptr;
+ switch (mode) {
+ default:
+ NOTREACHED();
+ // Fall through.
+ case LineBreakIteratorMode::Default:
+ // nullptr will cause any existing values to be removed.
+ break;
+ case LineBreakIteratorMode::Normal:
+ keywordValue = "normal";
+ break;
+ case LineBreakIteratorMode::Strict:
+ keywordValue = "strict";
+ break;
+ case LineBreakIteratorMode::Loose:
+ keywordValue = "loose";
+ break;
+ }
+
+ ICUError status;
+ int32_t lengthNeeded = uloc_setKeywordValue("lb", keywordValue, buffer.data(),
+ buffer.size(), &status);
+ if (U_SUCCESS(status))
+ return AtomicString::fromUTF8(buffer.data(), lengthNeeded);
+
+ if (status == U_BUFFER_OVERFLOW_ERROR) {
+ buffer.grow(lengthNeeded + 1);
+ memset(buffer.data() + utf8Locale.length(), 0,
+ buffer.size() - utf8Locale.length());
+ status = U_ZERO_ERROR;
+ int32_t lengthNeeded2 = uloc_setKeywordValue(
+ "lb", keywordValue, buffer.data(), buffer.size(), &status);
+ DCHECK_EQ(lengthNeeded, lengthNeeded2);
+ if (U_SUCCESS(status) && lengthNeeded == lengthNeeded2)
+ return AtomicString::fromUTF8(buffer.data(), lengthNeeded);
+ }
+
+ NOTREACHED();
+ return m_string;
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/platform/LayoutLocale.h ('k') | third_party/WebKit/Source/platform/LayoutLocaleTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698