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

Unified Diff: Source/platform/text/PlatformLocale.cpp

Issue 1100273002: input[type=number] UI should reject invalid characters. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 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
« no previous file with comments | « Source/platform/text/PlatformLocale.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/text/PlatformLocale.cpp
diff --git a/Source/platform/text/PlatformLocale.cpp b/Source/platform/text/PlatformLocale.cpp
index 8a1801d9c8bb5c738c76a2b421ddc66889262ec8..28e6aec9b56983b81e63d585b559ae7733869cbf 100644
--- a/Source/platform/text/PlatformLocale.cpp
+++ b/Source/platform/text/PlatformLocale.cpp
@@ -248,6 +248,18 @@ void Locale::setLocaleData(const Vector<String, DecimalSymbolsSize>& symbols, co
m_negativeSuffix = negativeSuffix;
ASSERT(!m_positivePrefix.isEmpty() || !m_positiveSuffix.isEmpty() || !m_negativePrefix.isEmpty() || !m_negativeSuffix.isEmpty());
m_hasLocaleData = true;
+
+ StringBuilder builder;
+ for (size_t i = 0; i < DecimalSymbolsSize; ++i) {
+ // We don't accept group separatros.
+ if (i != GroupSeparatorIndex)
+ builder.append(m_decimalSymbols[i]);
+ }
+ builder.append(m_positivePrefix);
+ builder.append(m_positiveSuffix);
+ builder.append(m_negativePrefix);
+ builder.append(m_negativeSuffix);
+ m_acceptableNumberCharacters = builder.toString();
}
String Locale::convertToLocalizedNumber(const String& input)
@@ -381,6 +393,20 @@ String Locale::convertFromLocalizedNumber(const String& localized)
return builder.toString();
}
+String Locale::stripInvalidNumberCharacters(const String& input, const String& standardChars) const
+{
+ StringBuilder builder;
+ builder.reserveCapacity(input.length());
+ for (unsigned i = 0; i < input.length(); ++i) {
+ UChar ch = input[i];
+ if (standardChars.find(ch) != kNotFound)
+ builder.append(ch);
+ else if (m_acceptableNumberCharacters.find(ch) != kNotFound)
+ builder.append(ch);
+ }
+ return builder.toString();
+}
+
#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
String Locale::localizedDecimalSeparator()
{
« no previous file with comments | « Source/platform/text/PlatformLocale.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698