Refactor, rename String convenience methods.

This commit is contained in:
lganzzzo 2021-08-25 01:10:03 +03:00
parent f70f949cf2
commit e8b7aac6af
9 changed files with 40 additions and 40 deletions

View File

@ -64,17 +64,17 @@ const std::string& String::operator*() const {
return this->m_ptr.operator*();
}
bool String::equalsCI(const std::string& other) {
bool String::equalsCI_ASCII(const std::string& other) {
auto ciLabel = share::StringKeyLabelCI(m_ptr);
return ciLabel == other;
}
bool String::equalsCI(const String& other) {
bool String::equalsCI_ASCII(const String& other) {
auto ciLabel = share::StringKeyLabelCI(m_ptr);
return ciLabel == other;
}
bool String::equalsCI(const char* other) {
bool String::equalsCI_ASCII(const char* other) {
auto ciLabel = share::StringKeyLabelCI(m_ptr);
return ciLabel == other;
}

View File

@ -189,25 +189,25 @@ public:
}
/**
* Case insensitive compare.
* Case insensitive compare (ASCII only).
* @param other
* @return
*/
bool equalsCI(const std::string& other);
bool equalsCI_ASCII(const std::string& other);
/**
* Case insensitive compare.
* Case insensitive compare (ASCII only).
* @param other
* @return
*/
bool equalsCI(const String& other);
bool equalsCI_ASCII(const String& other);
/**
* Case insensitive compare.
* Case insensitive compare (ASCII only).
* @param other
* @return
*/
bool equalsCI(const char* str);
bool equalsCI_ASCII(const char* str);
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, std::nullptr_t>::value, void>::type

View File

@ -260,7 +260,7 @@ public:
inline bool operator==(const char* str) const {
auto len = str != nullptr ? std::strlen(str) : 0;
return utils::String::compareCI(m_data, m_size, str, len) == 0;
return utils::String::compareCI_ASCII(m_data, m_size, str, len) == 0;
}
inline bool operator!=(const char* str) const {
@ -270,7 +270,7 @@ public:
inline bool operator==(const String& str) const {
if(m_data == nullptr) return str == nullptr;
if(str == nullptr) return false;
return utils::String::compareCI(m_data, m_size, str->data(), str->size()) == 0;
return utils::String::compareCI_ASCII(m_data, m_size, str->data(), str->size()) == 0;
}
inline bool operator!=(const String& str) const {
@ -278,7 +278,7 @@ public:
}
inline bool operator==(const StringKeyLabelCI &other) const {
return utils::String::compareCI(m_data, m_size, other.m_data, other.m_size) == 0;
return utils::String::compareCI_ASCII(m_data, m_size, other.m_data, other.m_size) == 0;
}
inline bool operator!=(const StringKeyLabelCI &other) const {
@ -286,11 +286,11 @@ public:
}
inline bool operator < (const StringKeyLabelCI &other) const {
return utils::String::compareCI(m_data, m_size, other.m_data, other.m_size) < 0;
return utils::String::compareCI_ASCII(m_data, m_size, other.m_data, other.m_size) < 0;
}
inline bool operator > (const StringKeyLabelCI &other) const {
return utils::String::compareCI(m_data, m_size, other.m_data, other.m_size) > 0;
return utils::String::compareCI_ASCII(m_data, m_size, other.m_data, other.m_size) > 0;
}
};

View File

@ -49,7 +49,7 @@ v_buff_size String::compare(const void* data1, v_buff_size size1, const void* da
}
v_buff_size String::compareCI(const void* data1, v_buff_size size1, const void* data2, v_buff_size size2) {
v_buff_size String::compareCI_ASCII(const void* data1, v_buff_size size1, const void* data2, v_buff_size size2) {
if(data1 == data2) return 0;
if(data1 == nullptr) return -1;
@ -82,14 +82,14 @@ v_buff_size String::compareCI(const void* data1, v_buff_size size1, const void*
}
void String::lowerCaseASCII(void* data, v_buff_size size) {
void String::lowerCase_ASCII(void* data, v_buff_size size) {
for(v_buff_size i = 0; i < size; i++) {
v_char8 a = ((p_char8) data)[i];
if(a >= 'A' && a <= 'Z') ((p_char8) data)[i] = a | 32;
}
}
void String::upperCaseASCII(void* data, v_buff_size size) {
void String::upperCase_ASCII(void* data, v_buff_size size) {
for(v_buff_size i = 0; i < size; i++) {
v_char8 a = ((p_char8) data)[i];
if(a >= 'a' && a <= 'z') ((p_char8) data)[i] = a & 223;

View File

@ -49,7 +49,7 @@ public:
static v_buff_size compare(const void* data1, v_buff_size size1, const void* data2, v_buff_size size2);
/**
* Compare data1, data2 - case insensitive.
* Compare data1, data2 - case insensitive (ASCII only).
* *It's safe to pass nullptr for data1/data2*
* @param data1 - pointer to data1.
* @param size1 - size of data1.
@ -59,21 +59,21 @@ public:
* 0 if all count bytes of data1 and data2 are equal.<br>
* Positive value if the first differing byte in data1 is greater than the corresponding byte in data2.
*/
static v_buff_size compareCI(const void* data1, v_buff_size size1, const void* data2, v_buff_size size2);
static v_buff_size compareCI_ASCII(const void* data1, v_buff_size size1, const void* data2, v_buff_size size2);
/**
* Change characters in data to lowercase (ASCII only).
* @param data - pointer to data.
* @param size - size of the data.
*/
static void lowerCaseASCII(void* data, v_buff_size size);
static void lowerCase_ASCII(void* data, v_buff_size size);
/**
* Change characters in data to uppercase (ASCII only).
* @param data - pointer to data.
* @param size - size of the data.
*/
static void upperCaseASCII(void* data, v_buff_size size);
static void upperCase_ASCII(void* data, v_buff_size size);
};

View File

@ -35,7 +35,7 @@ oatpp::String Url::Parser::parseScheme(oatpp::parser::Caret& caret) {
if(size > 0) {
std::unique_ptr<v_char8[]> buff(new v_char8[size]);
std::memcpy(buff.get(), &caret.getData()[pos0], size);
utils::String::lowerCaseASCII(buff.get(), size);
utils::String::lowerCase_ASCII(buff.get(), size);
return oatpp::String((const char*)buff.get(), size);
}
return nullptr;

View File

@ -55,7 +55,7 @@ void CommunicationUtils::considerConnectionState(const std::shared_ptr<protocol:
/* Set HTTP/1.1 default Connection header value (Keep-Alive), if no Connection header present in response. */
/* Set keep-alive to value specified in response otherwise */
auto& protocol = request->getStartingLine().protocol;
if(protocol && oatpp::utils::String::compareCI(protocol.getData(), protocol.getSize(), "HTTP/1.1", 8) == 0) {
if(protocol && oatpp::utils::String::compareCI_ASCII(protocol.getData(), protocol.getSize(), "HTTP/1.1", 8) == 0) {
if(outState && outState != Header::Value::CONNECTION_KEEP_ALIVE) {
connectionState = ConnectionState::CLOSING;
}

View File

@ -93,7 +93,7 @@ public:
ProcessorToUpper(v_int32 bufferSize) : BaseProcessor(bufferSize) {}
void process(p_char8 data, v_buff_size size) override {
utils::String::upperCaseASCII(data, size);
utils::String::upperCase_ASCII(data, size);
}
};
@ -104,7 +104,7 @@ public:
ProcessorToLower(v_int32 bufferSize) : BaseProcessor(bufferSize) {}
void process(p_char8 data, v_buff_size size) override {
utils::String::lowerCaseASCII(data, size);
utils::String::lowerCase_ASCII(data, size);
}
};

View File

@ -222,54 +222,54 @@ void StringTest::onRun() {
}
{
OATPP_LOGI(TAG, "test compareCI methods 1");
OATPP_LOGI(TAG, "test compareCI_ASCII methods 1");
oatpp::String s1 = "hello";
{
oatpp::String s2;
OATPP_ASSERT(!s1.equalsCI(s2));
OATPP_ASSERT(!s1.equalsCI_ASCII(s2));
}
{
const char* s2 = nullptr;
OATPP_ASSERT(!s1.equalsCI(s2));
OATPP_ASSERT(!s1.equalsCI_ASCII(s2));
}
}
{
OATPP_LOGI(TAG, "test compareCI methods 2");
OATPP_LOGI(TAG, "test compareCI_ASCII methods 2");
oatpp::String s1;
{
oatpp::String s2 = "hello";
OATPP_ASSERT(!s1.equalsCI(s2));
OATPP_ASSERT(!s1.equalsCI_ASCII(s2));
}
{
std::string s2 = "hello";
OATPP_ASSERT(!s1.equalsCI(s2));
OATPP_ASSERT(!s1.equalsCI_ASCII(s2));
}
{
const char* s2 = "hello";
OATPP_ASSERT(!s1.equalsCI(s2));
OATPP_ASSERT(!s1.equalsCI_ASCII(s2));
}
{
oatpp::String s2;
OATPP_ASSERT(s1.equalsCI(s2));
OATPP_ASSERT(s1.equalsCI_ASCII(s2));
}
{
const char* s2 = nullptr;
OATPP_ASSERT(s1.equalsCI(s2));
OATPP_ASSERT(s1.equalsCI_ASCII(s2));
}
{
OATPP_ASSERT(s1.equalsCI(nullptr));
OATPP_ASSERT(s1.equalsCI_ASCII(nullptr));
}
{
@ -289,27 +289,27 @@ void StringTest::onRun() {
}
{
OATPP_LOGI(TAG, "test compareCI methods 3");
OATPP_LOGI(TAG, "test compareCI_ASCII methods 3");
oatpp::String s1 = "hello";
{
oatpp::String s2 = "HELLO";
OATPP_ASSERT(s1.equalsCI(s2));
OATPP_ASSERT(s1.equalsCI_ASCII(s2));
}
{
std::string s2 = "HELLO";
OATPP_ASSERT(s1.equalsCI(s2));
OATPP_ASSERT(s1.equalsCI_ASCII(s2));
}
{
const char* s2 = "HELLO";
OATPP_ASSERT(s1.equalsCI(s2));
OATPP_ASSERT(s1.equalsCI_ASCII(s2));
}
{
OATPP_ASSERT(s1.equalsCI("HELLO"));
OATPP_ASSERT(s1.equalsCI_ASCII("HELLO"));
}
}