File tree 1 file changed +6
-16
lines changed
1 file changed +6
-16
lines changed Original file line number Diff line number Diff line change @@ -148,24 +148,14 @@ std::string GetDomainFromHostName(const char * hostnameWithDomain)
148
148
{
149
149
std::string hostname = std::string (hostnameWithDomain);
150
150
151
- // Find the last occurence of '.'
152
- size_t last_pos = hostname.find_last_of (" ." );
151
+ // Find the first occurence of '.'
152
+ size_t first_pos = hostname.find (" ." );
153
153
154
- // The last occurence of the dot should be the last character in the hostname with domain.
155
- VerifyOrReturnValue ((last_pos != std::string::npos && (last_pos == strlen (hostnameWithDomain) - 1 )) , std::string ());
154
+ // if not found, return empty string
155
+ VerifyOrReturnValue (first_pos != std::string::npos, std::string ());
156
156
157
- // Get a substring without last '.'
158
- std::string substring = hostname.substr (0 , last_pos);
159
-
160
- // Find the last occurence of '.' in the substring created above.
161
- size_t pos = substring.find_last_of (" ." );
162
- if (pos != std::string::npos)
163
- {
164
- // Return the domain name between the last 2 occurences of '.' including the trailing dot'.'.
165
- return std::string (hostname.substr (pos + 1 , last_pos));
166
- }
167
-
168
- return std::string ();
157
+ // Get a substring after the first occurence of '.' to the end of the string
158
+ return hostname.substr (first_pos + 1 , hostname.size ());
169
159
}
170
160
171
161
/* *
You can’t perform that action at this time.
0 commit comments