-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update uri.hpp #1131
base: master
Are you sure you want to change the base?
Update uri.hpp #1131
Conversation
std::string get_port_str() const { std::stringstream p; p << m_port; return p.str(); } if m_port == 9999, sometimes p.str() returns "9,999",i don't know why. but change to use std::to_string() is ok.
std::locale("") |
it should be function get_port_str
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overview
The modifications in the code improve the functionality by simplifying the string conversion process for port numbers and ensuring consistency in the format of the returned strings. Here are the key points of the review:
-
Consistency and Simplification:
- The changes improve the consistency in string conversion across the methods by using
std::to_string
for port conversion. - The updated code simplifies the logic by removing the use of
std::stringstream
where not necessary.
- The changes improve the consistency in string conversion across the methods by using
-
Readability and Maintainability:
- The refactoring enhances readability by making the code more straightforward.
- The usage of
std::to_string
directly in return statements reduces the lines of code, making it easier to maintain.
Improvement Suggestions
- Optimization of Host and Port Concatenation:
- To further simplify and optimize the code, consider using
std::to_string
consistently for the host and port concatenation.
- To further simplify and optimize the code, consider using
if (m_port == (m_secure ? uri_default_secure_port : uri_default_port)) {
return m_host;
} else {
return m_host + ":" + std::to_string(m_port);
}
- Documentation and Comments:
- Add comments to explain the logic, particularly for why certain conversions are used. This helps in maintaining the code in the long term.
// Return the host if the port is default for the scheme, otherwise return host:port
if (m_port == (m_secure ? uri_default_secure_port : uri_default_port)) {
return m_host;
} else {
return m_host + ":" + std::to_string(m_port);
}
- Consistency in String Conversion Methods:
- Ensure that
std::to_string
is used throughout the codebase for consistency, unless there is a specific need forstd::stringstream
.
- Ensure that
Summary
The changes made are effective in improving the code by simplifying the string conversion and making it more readable and maintainable. Implementing the suggested improvements will further enhance the code's clarity and performance.
std::string get_port_str() const {
std::stringstream p;
p << m_port;
return p.str();
}
if m_port == 9999, sometimes p.str() returns "9,999",i don't know why. But I can use std::to_string () instead