Skip to content

Commit fa32ed1

Browse files
authored
Remove use of std::begin() and std::end()
Remove single use of std::begin() and std::end() on a const char array. std::end() is actually incorrect for this use since it returns the end location AFTER the terminating null character so std::find() would match any null character in the string (although there are none). Replace std::end() with internal::kAlphabet + internal::kEncodingBase, consistent with a very similar std::find() search earlier in the code.
1 parent bd54569 commit fa32ed1

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

cpp/openlocationcode.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,10 @@ bool IsValid(const std::string &code) {
405405
return false;
406406
}
407407
// Are there any invalid characters?
408+
const char* end = internal::kAlphabet + internal::kEncodingBase;
408409
for (char c : code) {
409410
if (c != internal::kSeparator && c != internal::kPaddingCharacter &&
410-
std::find(std::begin(internal::kAlphabet),
411-
std::end(internal::kAlphabet),
412-
(char)toupper(c)) == std::end(internal::kAlphabet)) {
411+
std::find(internal::kAlphabet, end, (char)toupper(c)) == end) {
413412
return false;
414413
}
415414
}

0 commit comments

Comments
 (0)