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

Unified Diff: components/payments/content/payments_validators.cc

Issue 2713033004: Layered component for web payments (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: components/payments/content/payments_validators.cc
diff --git a/components/payments/payments_validators.cc b/components/payments/content/payments_validators.cc
similarity index 52%
rename from components/payments/payments_validators.cc
rename to components/payments/content/payments_validators.cc
index 1d83c237c6ebfc9165d229c78c5a44e6883aefad..ed2b448c205d0392b73abf189d13532e9bdc8d02 100644
--- a/components/payments/payments_validators.cc
+++ b/components/payments/content/payments_validators.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/payments/payments_validators.h"
+#include "components/payments/content/payments_validators.h"
#include "third_party/re2/src/re2/re2.h"
#include "url/gurl.h"
@@ -15,29 +15,29 @@ static const int maximumStringLength = 2048;
bool PaymentsValidators::isValidCurrencyCodeFormat(
const std::string& code,
const std::string& system,
- std::string* optionalErrorMessage) {
+ std::string* optional_error_message) {
if (system == "urn:iso:std:iso:4217") {
if (RE2::FullMatch(code, "[A-Z]{3}"))
return true;
- if (optionalErrorMessage)
- *optionalErrorMessage = "'" + code +
- "' is not a valid ISO 4217 currency code, should "
- "be 3 upper case letters [A-Z]";
+ if (optional_error_message)
+ *optional_error_message =
+ "'" + code +
+ "' is not a valid ISO 4217 currency code, should "
+ "be 3 upper case letters [A-Z]";
return false;
}
if (code.size() > maximumStringLength) {
- if (optionalErrorMessage)
- *optionalErrorMessage =
+ if (optional_error_message)
+ *optional_error_message =
"The currency code should be at most 2048 characters long";
return false;
}
if (!GURL(system).is_valid()) {
- if (optionalErrorMessage)
- *optionalErrorMessage =
- "The system should be a valid URL";
+ if (optional_error_message)
+ *optional_error_message = "The system should be a valid URL";
return false;
}
return true;
@@ -45,74 +45,77 @@ bool PaymentsValidators::isValidCurrencyCodeFormat(
bool PaymentsValidators::isValidAmountFormat(
const std::string& amount,
- std::string* optionalErrorMessage) {
+ std::string* optional_error_message) {
if (RE2::FullMatch(amount, "-?[0-9]+(\\.[0-9]+)?"))
return true;
- if (optionalErrorMessage)
- *optionalErrorMessage = "'" + amount + "' is not a valid amount format";
+ if (optional_error_message)
+ *optional_error_message = "'" + amount + "' is not a valid amount format";
return false;
}
bool PaymentsValidators::isValidCountryCodeFormat(
const std::string& code,
- std::string* optionalErrorMessage) {
+ std::string* optional_error_message) {
if (RE2::FullMatch(code, "[A-Z]{2}"))
return true;
- if (optionalErrorMessage)
- *optionalErrorMessage = "'" + code +
- "' is not a valid CLDR country code, should be 2 "
- "upper case letters [A-Z]";
+ if (optional_error_message)
+ *optional_error_message = "'" + code +
+ "' is not a valid CLDR country code, should be 2 "
+ "upper case letters [A-Z]";
return false;
}
bool PaymentsValidators::isValidLanguageCodeFormat(
const std::string& code,
- std::string* optionalErrorMessage) {
+ std::string* optional_error_message) {
if (RE2::FullMatch(code, "([a-z]{2,3})?"))
return true;
- if (optionalErrorMessage)
- *optionalErrorMessage = "'" + code +
- "' is not a valid BCP-47 language code, should be "
- "2-3 lower case letters [a-z]";
+ if (optional_error_message)
+ *optional_error_message =
+ "'" + code +
+ "' is not a valid BCP-47 language code, should be "
+ "2-3 lower case letters [a-z]";
return false;
}
bool PaymentsValidators::isValidScriptCodeFormat(
const std::string& code,
- std::string* optionalErrorMessage) {
+ std::string* optional_error_message) {
if (RE2::FullMatch(code, "([A-Z][a-z]{3})?"))
return true;
- if (optionalErrorMessage)
- *optionalErrorMessage = "'" + code +
- "' is not a valid ISO 15924 script code, should be "
- "an upper case letter [A-Z] followed by 3 lower "
- "case letters [a-z]";
+ if (optional_error_message)
+ *optional_error_message =
+ "'" + code +
+ "' is not a valid ISO 15924 script code, should be "
+ "an upper case letter [A-Z] followed by 3 lower "
+ "case letters [a-z]";
return false;
}
bool PaymentsValidators::isValidShippingAddress(
const mojom::PaymentAddressPtr& address,
- std::string* optionalErrorMessage) {
- if (!isValidCountryCodeFormat(address->country, optionalErrorMessage))
+ std::string* optional_error_message) {
+ if (!isValidCountryCodeFormat(address->country, optional_error_message))
return false;
- if (!isValidLanguageCodeFormat(address->language_code, optionalErrorMessage))
+ if (!isValidLanguageCodeFormat(address->language_code,
+ optional_error_message))
return false;
- if (!isValidScriptCodeFormat(address->script_code, optionalErrorMessage))
+ if (!isValidScriptCodeFormat(address->script_code, optional_error_message))
return false;
if (address->language_code.empty() && !address->script_code.empty()) {
- if (optionalErrorMessage)
- *optionalErrorMessage =
+ if (optional_error_message)
+ *optional_error_message =
"If language code is empty, then script code should also be empty";
return false;
@@ -123,12 +126,12 @@ bool PaymentsValidators::isValidShippingAddress(
bool PaymentsValidators::isValidErrorMsgFormat(
const std::string& error,
- std::string* optionalErrorMessage) {
+ std::string* optional_error_message) {
if (error.length() <= maximumStringLength)
return true;
- if (optionalErrorMessage)
- *optionalErrorMessage =
+ if (optional_error_message)
+ *optional_error_message =
"Error message should be at most 2048 characters long";
return false;
« no previous file with comments | « components/payments/content/payments_validators.h ('k') | components/payments/content/payments_validators_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698