Skip to content

Commit 3b40e02

Browse files
committed
Add const and reference
1 parent a746dc2 commit 3b40e02

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

homework/password-check/validation.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <string>
22
#include "validation.hpp"
33

4-
std::string getErrorMessage(ErrorCode errorCode) {
4+
std::string getErrorMessage(const ErrorCode errorCode) {
55
std::string errorMessage{};
66
switch(errorCode) {
77
case ErrorCode::Ok:
@@ -26,17 +26,18 @@ std::string getErrorMessage(ErrorCode errorCode) {
2626
errorMessage = "An unkown error occured";
2727
break;
2828
}
29+
return errorMessage;
2930
}
3031

31-
bool doPasswordsMatch(std::string password, std::string repeatedPassword) {
32+
bool doPasswordsMatch(const std::string& password, const std::string& repeatedPassword) {
3233
return password == repeatedPassword;
3334
}
3435

35-
ErrorCode checkPasswordRules(std::string password) {
36+
ErrorCode checkPasswordRules(const std::string& password) {
3637
return ErrorCode::Ok;
3738
}
3839

39-
ErrorCode checkPassword(std::string password, std::string repeatedPassowrd) {
40+
ErrorCode checkPassword(const std::string& password, const std::string& repeatedPassowrd) {
4041
if (!doPasswordsMatch(password, repeatedPassowrd)) {
4142
return ErrorCode::PasswordsDoNotMatch;
4243
}

homework/password-check/validation.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ enum class ErrorCode {
1010
PasswordsDoNotMatch
1111
};
1212

13-
std::string getErrorMessage(ErrorCode errorCode);
13+
std::string getErrorMessage(const ErrorCode errorCode);
1414

15-
bool doPasswordsMatch(std::string password, std::string repeatedPassword);
15+
bool doPasswordsMatch(const std::string& password, const std::string& repeatedPassword);
1616

17-
ErrorCode checkPasswordRules(std::string password);
17+
ErrorCode checkPasswordRules(const std::string& password);
1818

19-
ErrorCode checkPassword(std::string password, std::string repeatedPassowrd);
19+
ErrorCode checkPassword(const std::string& password, const std::string& repeatedPassowrd);

0 commit comments

Comments
 (0)