-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
str_to_date function push down (#1961)
- Loading branch information
1 parent
fb45ed9
commit 30db147
Showing
20 changed files
with
1,290 additions
and
37 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
#include <Common/StringUtils/StringUtils.h> | ||
#include <common/StringRef.h> | ||
|
||
inline bool startsWith(const StringRef & view, const StringRef & prefix) | ||
{ | ||
return detail::startsWith(view.data, view.size, prefix.data, prefix.size); | ||
} | ||
|
||
// case insensitive version of startsWith | ||
inline bool startsWithCI(const StringRef & view, const StringRef & prefix) | ||
{ | ||
return detail::startsWithCI(view.data, view.size, prefix.data, prefix.size); | ||
} | ||
|
||
inline bool endsWith(const StringRef & view, const char * prefix) | ||
{ | ||
return detail::endsWith(view.data, view.size, prefix, strlen(prefix)); // | ||
} | ||
|
||
// case insensitive version of endsWith | ||
inline bool endsWithCI(const StringRef & view, const char * prefix) | ||
{ | ||
return detail::endsWithCI(view.data, view.size, prefix, strlen(prefix)); | ||
} | ||
|
||
// n - number of characters to remove from the start of the view, | ||
// The behavior is undefined if `n > view.size` | ||
inline StringRef removePrefix(const StringRef & view, size_t n) { return StringRef{view.data + n, view.size - n}; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,44 @@ | ||
#include "StringUtils.h" | ||
|
||
#include <cctype> | ||
|
||
namespace detail | ||
{ | ||
|
||
bool startsWith(const std::string & s, const char * prefix, size_t prefix_size) | ||
bool startsWith(const char * s, size_t size, const char * prefix, size_t prefix_size) | ||
{ | ||
return size >= prefix_size && 0 == memcmp(s, prefix, prefix_size); | ||
} | ||
|
||
bool endsWith(const char * s, size_t size, const char * suffix, size_t suffix_size) | ||
{ | ||
return s.size() >= prefix_size && 0 == memcmp(s.data(), prefix, prefix_size); | ||
return size >= suffix_size && 0 == memcmp(s + size - suffix_size, suffix, suffix_size); | ||
} | ||
|
||
bool endsWith(const std::string & s, const char * suffix, size_t suffix_size) | ||
bool startsWithCI(const char * s, size_t size, const char * prefix, size_t prefix_size) | ||
{ | ||
return s.size() >= suffix_size && 0 == memcmp(s.data() + s.size() - suffix_size, suffix, suffix_size); | ||
if (size < prefix_size) | ||
return false; | ||
// case insensitive compare | ||
for (size_t i = 0; i < prefix_size; ++i) | ||
{ | ||
if (std::tolower(s[i]) != std::tolower(prefix[i])) | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool endsWithCI(const char * s, size_t size, const char * suffix, size_t suffix_size) | ||
{ | ||
if (size < suffix_size) | ||
return false; | ||
// case insensitive compare | ||
for (size_t i = 0; i < suffix_size; ++i) | ||
{ | ||
if (std::tolower(s[i]) != std::tolower(suffix[i])) | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
} // namespace detail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.