Merge pull request #454 from oatpp/types_refactoring

Types refactoring
This commit is contained in:
Leonid Stryzhevskyi 2021-08-04 00:08:50 +03:00 committed by GitHub
commit 48bac535f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
102 changed files with 885 additions and 1489 deletions

View File

@ -55,8 +55,6 @@ add_library(oatpp
oatpp/core/base/Environment.cpp
oatpp/core/base/Environment.hpp
oatpp/core/base/ObjectHandle.hpp
oatpp/core/base/StrBuffer.cpp
oatpp/core/base/StrBuffer.hpp
oatpp/core/base/memory/Allocator.cpp
oatpp/core/base/memory/Allocator.hpp
oatpp/core/base/memory/MemoryPool.cpp
@ -130,6 +128,8 @@ add_library(oatpp
oatpp/core/utils/ConversionUtils.hpp
oatpp/core/utils/Random.cpp
oatpp/core/utils/Random.hpp
oatpp/core/utils/String.cpp
oatpp/core/utils/String.hpp
oatpp/encoding/Base64.cpp
oatpp/encoding/Base64.hpp
oatpp/encoding/Hex.cpp

View File

@ -47,8 +47,6 @@ private: \
return ↦ \
} \
public: \
\
TYPE_NAME() = default; \
\
template<typename ... Args> \
static Wrapper createShared(Args... args){ \

View File

@ -52,7 +52,7 @@ namespace oatpp {
/**
* Mapping-Enabled String type. &id:oatpp::data::mapping::type::String; <br>
* For `oatpp::String` methods see &id:oatpp::base::StrBuffer;
* For `oatpp::String` methods see `std::string`
*/
typedef oatpp::data::mapping::type::String String;

View File

@ -1,388 +0,0 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#include "StrBuffer.hpp"
#include <fstream>
namespace oatpp { namespace base {
void StrBuffer::set(const void* data, v_buff_size size, bool hasOwnData) {
m_data = (p_char8) data;
m_size = size;
m_hasOwnData = hasOwnData;
}
void StrBuffer::setAndCopy(const void* data, const void* originData, v_buff_size size){
m_data = (p_char8) data;
m_size = size;
//m_hasOwnData = false;
if(originData != nullptr) {
std::memcpy(m_data, originData, size);
}
m_data[size] = 0;
}
std::shared_ptr<StrBuffer> StrBuffer::allocShared(const void* data, v_buff_size size, bool copyAsOwnData) {
if(copyAsOwnData) {
memory::AllocationExtras extras(size + 1);
std::shared_ptr<StrBuffer> ptr;
if(size + 1 > getSmStringSize()) {
ptr = memory::allocateSharedWithExtras<StrBuffer>(extras);
} else {
ptr = memory::customPoolAllocateSharedWithExtras<StrBuffer>(extras, getSmallStringPool());
}
ptr->setAndCopy(extras.extraPtr, data, size);
return ptr;
}
return std::make_shared<StrBuffer>(data, size, copyAsOwnData);
}
p_char8 StrBuffer::allocStrBuffer(const void* originData, v_buff_size size, bool copyAsOwnData) {
if(copyAsOwnData) {
p_char8 data = new v_char8[size + 1];
data[size] = 0;
if(originData != nullptr) {
std::memcpy(data, originData, size);
}
return data;
}
return (p_char8) originData;
}
StrBuffer::StrBuffer()
: m_data((p_char8)"[<nullptr>]")
, m_size(11)
, m_hasOwnData(false)
{}
StrBuffer::StrBuffer(const void* data, v_buff_size size, bool copyAsOwnData)
: m_data(allocStrBuffer(data, size, copyAsOwnData))
, m_size(size)
, m_hasOwnData(copyAsOwnData)
{}
StrBuffer::~StrBuffer() {
if(m_hasOwnData) {
delete [] m_data;
}
m_data = nullptr;
}
std::shared_ptr<StrBuffer> StrBuffer::createShared(const void* data, v_buff_size size, bool copyAsOwnData) {
return allocShared(data, size, copyAsOwnData);
}
std::shared_ptr<StrBuffer> StrBuffer::createShared(const char* data, bool copyAsOwnData) {
return allocShared(data, std::strlen(data), copyAsOwnData);
}
std::shared_ptr<StrBuffer> StrBuffer::createShared(StrBuffer* other, bool copyAsOwnData) {
return allocShared(other->getData(), other->getSize(), copyAsOwnData);
}
std::shared_ptr<StrBuffer> StrBuffer::createShared(v_buff_size size) {
return allocShared(nullptr, size, true);
}
std::shared_ptr<StrBuffer> StrBuffer::createSharedConcatenated(const void* data1, v_buff_size size1, const void* data2, v_buff_size size2) {
const auto& ptr = allocShared(nullptr, size1 + size2, true);
std::memcpy(ptr->m_data, data1, size1);
std::memcpy(ptr->m_data + size1, data2, size2);
return ptr;
}
std::shared_ptr<StrBuffer> StrBuffer::loadFromFile(const char* filename) {
std::ifstream file (filename, std::ios::in|std::ios::binary|std::ios::ate);
if (file.is_open()) {
auto result = createShared(file.tellg());
file.seekg(0, std::ios::beg);
file.read((char*)result->getData(), result->getSize());
file.close();
return result;
}
return nullptr;
}
void StrBuffer::saveToFile(const char* filename) {
std::ofstream fs(filename, std::ios::out | std::ios::binary);
fs.write((const char*)m_data, m_size);
fs.close();
}
p_char8 StrBuffer::getData() const {
return m_data;
}
v_buff_size StrBuffer::getSize() const {
return m_size;
}
const char* StrBuffer::c_str() const {
return (const char*) m_data;
}
std::string StrBuffer::std_str() const {
return std::string((const char*) m_data, m_size);
}
bool StrBuffer::hasOwnData() const {
return m_hasOwnData;
}
std::shared_ptr<StrBuffer> StrBuffer::toLowerCase() const {
const auto& ptr = allocShared(m_data, m_size, true);
lowerCase(ptr->m_data, ptr->m_size);
return ptr;
}
std::shared_ptr<StrBuffer> StrBuffer::toUpperCase() const {
const auto& ptr = allocShared(m_data, m_size, true);
upperCase(ptr->m_data, ptr->m_size);
return ptr;
}
bool StrBuffer::equals(const void* data, v_buff_size size) const {
if(m_size == size) {
return equals(m_data, data, size);
}
return false;
}
bool StrBuffer::equals(const char* data) const {
if(data == nullptr) {
return m_data == nullptr;
}
if(m_size == (v_buff_size) std::strlen(data)) {
return equals(m_data, data, m_size);
}
return false;
}
bool StrBuffer::equals(StrBuffer* other) const {
return equals((StrBuffer*)this, other);
}
bool StrBuffer::startsWith(const void* data, v_buff_size size) const {
if(m_size >= size) {
return equals(m_data, data, size);
}
return false;
}
bool StrBuffer::startsWith(const char* data) const {
if(data == nullptr) return false;
v_buff_size length = std::strlen(data);
if(m_size >= length) {
return equals(m_data, data, length);
}
return false;
}
bool StrBuffer::startsWith(StrBuffer* data) const {
if(data == nullptr) return false;
if(m_size >= data->m_size) {
return equals(m_data, data, data->m_size);
}
return false;
}
// static
v_buff_size StrBuffer::compare(const void* data1, v_buff_size size1, const void* data2, v_buff_size size2) {
if(data1 == data2) return 0;
if(data1 == nullptr) return -1;
if(data2 == nullptr) return 1;
if(size1 < size2) {
auto res = std::memcmp(data1, data2, size1);
if(res == 0) return -1;
return res;
}
if(size1 > size2) {
auto res = std::memcmp(data1, data2, size2);
if(res == 0) return 1;
return res;
}
return std::memcmp(data1, data2, size1);
}
v_buff_size StrBuffer::compareCI(const void* data1, v_buff_size size1, const void* data2, v_buff_size size2) {
if(data1 == data2) return 0;
if(data1 == nullptr) return -1;
if(data2 == nullptr) return 1;
auto d1 = (p_char8) data1;
auto d2 = (p_char8) data2;
v_buff_size size = size1;
if(size2 < size1) size = size2;
for(v_buff_size i = 0; i < size; i ++) {
v_char8 a = d1[i];
v_char8 b = d2[i];
if(a >= 'A' && a <= 'Z') a |= 32;
if(b >= 'A' && b <= 'Z') b |= 32;
if(a != b) {
return (int) a - (int) b;
}
}
if(size1 < size2) return -1;
if(size1 > size2) return 1;
return 0;
}
v_buff_size StrBuffer::compareCI_FAST(const void* data1, v_buff_size size1, const void* data2, v_buff_size size2) {
if(data1 == data2) return 0;
if(data1 == nullptr) return -1;
if(data2 == nullptr) return 1;
auto d1 = (p_char8) data1;
auto d2 = (p_char8) data2;
v_buff_size size = size1;
if(size2 < size1) size = size2;
for(v_buff_size i = 0; i < size; i ++) {
v_char8 a = d1[i] | 32;
v_char8 b = d2[i] | 32;
if(a != b) {
return (int) a - (int) b;
}
}
if(size1 < size2) return -1;
if(size1 > size2) return 1;
return 0;
}
bool StrBuffer::equals(const void* data1, const void* data2, v_buff_size size) {
if(data1 == data2) return true;
if(data1 == nullptr || data2 == nullptr) return false;
return std::memcmp(data1, data2, size) == 0;
}
bool StrBuffer::equals(const char* data1, const char* data2) {
if(data1 == data2) return true;
if(data1 == nullptr || data2 == nullptr) return false;
const auto size = std::strlen(data1);
return (size == std::strlen(data2) && std::memcmp(data1, data2, size) == 0);
}
bool StrBuffer::equals(StrBuffer* str1, StrBuffer* str2) {
if(str1 == str2) return true;
if(str1 == nullptr || str2 == nullptr) return false;
if(str1->m_size != str2->m_size) return false;
return str1->m_data == str2->m_data || std::memcmp(str1->m_data, str2->m_data, str1->m_size) == 0;
}
bool StrBuffer::equalsCI(const void* data1, const void* data2, v_buff_size size) {
for(v_buff_size i = 0; i < size; i++) {
v_char8 a = ((p_char8) data1) [i];
v_char8 b = ((p_char8) data2) [i];
if(a >= 'A' && a <= 'Z') a |= 32;
if(b >= 'A' && b <= 'Z') b |= 32;
if(a != b) {
return false;
}
}
return true;
}
bool StrBuffer::equalsCI(const char* data1, const char* data2) {
if(data1 == data2) return true;
if(data1 == nullptr || data2 == nullptr) return false;
const auto size = std::strlen(data1);
return (size == std::strlen(data2) && equalsCI(data1, data2, size) == 0);
}
bool StrBuffer::equalsCI(StrBuffer* str1, StrBuffer* str2) {
if(str1 == str2) return true;
if(str1 == nullptr || str2 == nullptr) return false;
if(str1->m_size != str2->m_size) return false;
return (str1->m_data == str2->m_data || equalsCI(str1->m_data, str2->m_data, str1->m_size));
}
bool StrBuffer::equalsCI_FAST(const void* data1, const void* data2, v_buff_size size) {
for(v_buff_size i = 0; i < size; i++) {
if((((p_char8) data1) [i] | 32) != (((p_char8) data2) [i] | 32)) {
return false;
}
}
return true;
}
bool StrBuffer::equalsCI_FAST(const char* data1, const char* data2) {
if(data1 == data2) return true;
if(data1 == nullptr || data2 == nullptr) return false;
const auto size = std::strlen(data1);
return (size == std::strlen(data2) && equalsCI_FAST(data1, data2, size) == 0);
}
bool StrBuffer::equalsCI_FAST(StrBuffer* str1, StrBuffer* str2) {
if(str1 == str2) return true;
if(str1 == nullptr || str2 == nullptr) return false;
if(str1->m_size != str2->m_size) return false;
return (str1->m_data == str2->m_data || equalsCI_FAST(str1->m_data, str2->m_data, str1->m_size));
}
bool StrBuffer::equalsCI_FAST(StrBuffer* str1, const char* str2) {
v_buff_size len = std::strlen(str2);
return (str1->getSize() == len && equalsCI_FAST(str1->m_data, str2, str1->m_size));
}
void StrBuffer::lowerCase(const 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 StrBuffer::upperCase(const 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

@ -1,391 +0,0 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#ifndef oatpp_base_StrBuffer_hpp
#define oatpp_base_StrBuffer_hpp
#include "memory/ObjectPool.hpp"
#include "./Countable.hpp"
#include <cstring>
namespace oatpp { namespace base {
/**
* String buffer class.
*/
class StrBuffer : public oatpp::base::Countable {
private:
static constexpr v_buff_size SM_STRING_POOL_ENTRY_SIZE = 256;
static memory::ThreadDistributedMemoryPool& getSmallStringPool() {
static auto pool = new memory::ThreadDistributedMemoryPool("Small_String_Pool", SM_STRING_POOL_ENTRY_SIZE, 16);
return *pool;
}
static v_buff_size getSmStringBaseSize() {
memory::AllocationExtras extras(0);
auto ptr = memory::customPoolAllocateSharedWithExtras<StrBuffer>(extras, getSmallStringPool());
return extras.baseSize;
}
static v_buff_size getSmStringSize() {
static v_buff_size size = SM_STRING_POOL_ENTRY_SIZE - getSmStringBaseSize();
return size;
}
private:
p_char8 m_data;
v_buff_size m_size;
bool m_hasOwnData;
private:
void set(const void* data, v_buff_size size, bool hasOwnData);
void setAndCopy(const void* data, const void* originData, v_buff_size size);
static std::shared_ptr<StrBuffer> allocShared(const void* data, v_buff_size size, bool copyAsOwnData);
/*
* Allocate memory for string or use originData<br>
* if copyAsOwnData == false return originData
*/
static p_char8 allocStrBuffer(const void* originData, v_buff_size size, bool copyAsOwnData);
public:
/**
* Constructor. Default.
*/
StrBuffer();
/**
* Constructor.
* @param data - pointer to data.
* @param size - size of the data.
* @param copyAsOwnData - if true then allocate own buffer and copy data to that buffer.
*/
StrBuffer(const void* data, v_buff_size size, bool copyAsOwnData);
public:
/**
* virtual Destructor.
*/
virtual ~StrBuffer();
/**
* Create shared StrBuffer of specified size.
* @param size - size of the buffer.
* @return - shared_ptr to StrBuffer.
*/
static std::shared_ptr<StrBuffer> createShared(v_buff_size size);
/**
* Create shared StrBuffer with data, size, and copyAsOwnData parameters.
* @param data - buffer data.
* @param size - size of the data.
* @param copyAsOwnData - if true then allocate own buffer and copy data to that buffer.
* @return - shared_ptr to StrBuffer.
*/
static std::shared_ptr<StrBuffer> createShared(const void* data, v_buff_size size, bool copyAsOwnData = true);
/**
* Create shared StrBuffer with data, and copyAsOwnData parameters.
* @param data - buffer data.
* @param copyAsOwnData - if true then allocate own buffer and copy data to that buffer.
* @return - shared_ptr to StrBuffer.
*/
static std::shared_ptr<StrBuffer> createShared(const char* data, bool copyAsOwnData = true);
/**
* Create shared StrBuffer from other StrBuffer.
* @param other - other StrBuffer.
* @param copyAsOwnData - if true then allocate own buffer and copy data to that buffer.
* @return - shared_ptr to StrBuffer.
*/
static std::shared_ptr<StrBuffer> createShared(StrBuffer* other, bool copyAsOwnData = true);
/**
* Create shared StrBuffer of size=size1 + size2 and data=data1 + data2.
* @param data1 - pointer to data1.
* @param size1 - size of the data1.
* @param data2 - pointer to data2.
* @param size2 - size of the data2.
* @return - shared_ptr to StrBuffer.
*/
static std::shared_ptr<StrBuffer> createSharedConcatenated(const void* data1, v_buff_size size1, const void* data2, v_buff_size size2);
/**
* Create shared StrBuffer from c-string.
* @param data - data.
* @param copyAsOwnData - if true then allocate own buffer and copy data to that buffer.
* @return - shared_ptr to StrBuffer.
*/
static std::shared_ptr<StrBuffer> createFromCString(const char* data, bool copyAsOwnData = true) {
if(data != nullptr) {
return allocShared(data, std::strlen(data), copyAsOwnData);
}
return nullptr;
}
/**
* Load data from file and store in StrBuffer.
* @param filename - name of the file.
* @return - shared_ptr to StrBuffer.
*/
static std::shared_ptr<StrBuffer> loadFromFile(const char* filename);
/**
* Save content of the buffer to file.
* @param filename - name of the file.
*/
void saveToFile(const char* filename);
/**
* Get pointer to data of the buffer.
* @return - pointer to data of the buffer.
*/
p_char8 getData() const;
/**
* Get buffer size.
* @return - buffer size.
*/
v_buff_size getSize() const;
/**
* Get pointer to data of the buffer as `const* char`.
* @return - pointer to data of the buffer.
*/
const char* c_str() const;
/**
* Get copy of the buffer data as `std::string`.
* @return - copy of the buffer data as `std::string`.
*/
std::string std_str() const;
/**
* Is this object is responsible for freeing buffer data.
* @return - true if this object is responsible for freeing buffer data.
*/
bool hasOwnData() const;
/**
* Create lowercase copy of the buffer.<br>
* (correct for ASCII only)
* @return - copy of the buffer containing lowercase variants of ascii symbols.
*/
std::shared_ptr<StrBuffer> toLowerCase() const;
/**
* Create uppercase copy of the buffer.<br>
* (correct for ASCII only)
* @return - copy of the buffer containing uppercase variants of ascii symbols.
*/
std::shared_ptr<StrBuffer> toUpperCase() const;
/**
* Check string equality of the buffer to data of specified size.
* @param data - pointer to data to be compared with the buffer data.
* @param size - size of the data.
* @return - true if all chars of buffer are same as in data, and size == this.getSize().
*/
bool equals(const void* data, v_buff_size size) const;
/**
* Check string equality of the buffer to data of specified size.
* @param data - pointer to data to be compared with the buffer data.
* @return - true if all chars of buffer are same as in data, and std::strlen(data) == this.getSize().
*/
bool equals(const char* data) const;
/**
* Check string equality to other buffer.
* @param other - pointer to other StrBuffer to be compared with the buffer data.
* @return - true if all chars of one buffer are same as in other, and other.getSize() == this.getSize().
*/
bool equals(StrBuffer* other) const;
/**
* Check if buffer starts with specified data, size.
* @param data - data as `const void*`.
* @param size - size of the data.
* @return - true if buffer starts with specified data.
*/
bool startsWith(const void* data, v_buff_size size) const;
/**
* Check if buffer starts with specified data.
* @param data - data as `const char*`.
* @return - true if buffer starts with specified data.
*/
bool startsWith(const char* data) const;
/**
* Check if buffer starts with specified data.
* @param data - data as `StrBuffer`.
* @return - true if buffer starts with specified data.
*/
bool startsWith(StrBuffer* data) const;
public:
/**
* Compare data1, data2 using `std::memcmp`.
* @param data1 - pointer to data1.
* @param size1 - size of data1.
* @param data2 - pointer to data2.
* @param size2 - size of data2.
* @return - Negative value if the first differing byte (reinterpreted as unsigned char) in data1 is less than the corresponding byte in data2.<br>
* 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 compare(const void* data1, v_buff_size size1, const void* data2, v_buff_size size2);
/**
* Compare data1, data2 - case insensitive.
* @param data1 - pointer to data1.
* @param size1 - size of data1.
* @param data2 - pointer to data2.
* @param size2 - size of data2.
* @return - Negative value if the first differing byte (reinterpreted as unsigned char) in data1 is less than the corresponding byte in data2.<br>
* 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);
/**
* Compare data1, data2 - case insensitive (ASCII only, correct compare if one of strings contains letters only).
* @param data1 - pointer to data1.
* @param size1 - size of data1.
* @param data2 - pointer to data2.
* @param size2 - size of data2.s
* @return - Negative value if the first differing byte (reinterpreted as unsigned char) in data1 is less than the corresponding byte in data2.<br>
* 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_FAST(const void* data1, v_buff_size size1, const void* data2, v_buff_size size2);
/**
* Check string equality of data1 to data2.
* @param data1 - pointer to data1.
* @param data2 - pointer to data2.
* @param size - number of characters to compare.
* @return - `true` if equals.
*/
static bool equals(const void* data1, const void* data2, v_buff_size size);
/**
* Check string equality of data1 to data2.
* @param data1 - pointer to data1.
* @param data2 - pointer to data2.
* @return - `true` if equals.
*/
static bool equals(const char* data1, const char* data2);
/**
* Check string equality of str1 to str2.
* @param str1 - pointer to str1.
* @param str2 - pointer to str2.
* @return - `true` if equals.
*/
static bool equals(StrBuffer* str1, StrBuffer* str2);
/**
* Check Case Insensitive string equality of data1 to data2.
* @param data1 - pointer to data1.
* @param data2 - pointer to data2.
* @param size - number of characters to compare.
* @return - `true` if equals.
*/
static bool equalsCI(const void* data1, const void* data2, v_buff_size size);
/**
* Check Case Insensitive string equality of data1 to data2.
* @param data1 - pointer to data1.
* @param data2 - pointer to data2.
* @return - `true` if equals.
*/
static bool equalsCI(const char* data1, const char* data2);
/**
* Check Case Insensitive string equality of str1 to str2.
* @param str1 - pointer to str1.
* @param str2 - pointer to str2.
* @return - `true` if equals.
*/
static bool equalsCI(StrBuffer* str1, StrBuffer* str2);
/**
* Check Case Insensitive string equality of data1 to data2. (ASCII only, correct compare if one of strings contains letters only)
* @param data1 - pointer to data1.
* @param data2 - pointer to data2.
* @param size - number of characters to compare.
* @return - `true` if equals.
*/
static bool equalsCI_FAST(const void* data1, const void* data2, v_buff_size size);
/**
* Check Case Insensitive string equality of data1 to data2. (ASCII only, correct compare if one of strings contains letters only)
* @param data1 - pointer to data1.
* @param data2 - pointer to data2.
* @return - `true` if equals.
*/
static bool equalsCI_FAST(const char* data1, const char* data2);
/**
* Check Case Insensitive string equality of str1 to str2. (ASCII only, correct compare if one of strings contains letters only)
* @param str1 - pointer to str1.
* @param str2 - pointer to str2.
* @return - `true` if equals.
*/
static bool equalsCI_FAST(StrBuffer* str1, StrBuffer* str2);
/**
* Check Case Insensitive string equality of str1 to str2. (ASCII only, correct compare if one of strings contains letters only)
* @param str1 - pointer to str1 as `StrBuffer`.
* @param str2 - pointer to str2 as `const char*`
* @return - `true` if equals.
*/
static bool equalsCI_FAST(StrBuffer* str1, const char* str2);
/**
* Change characters in data to lowercase.
* @param data - pointer to data.
* @param size - size of the data.
*/
static void lowerCase(const void* data, v_buff_size size);
/**
* Change characters in data to uppercase.
* @param data - pointer to data.
* @param size - size of the data.
*/
static void upperCase(const void* data, v_buff_size size);
};
}}
#endif /* oatpp_base_StrBuffer_hpp */

View File

@ -24,7 +24,9 @@
#include "IOBuffer.hpp"
namespace oatpp { namespace data{ namespace buffer {
namespace oatpp { namespace data { namespace buffer {
const v_buff_size IOBuffer::BUFFER_SIZE = 4096;
IOBuffer::IOBuffer()
: m_entry(getBufferPool().obtain())

View File

@ -42,7 +42,7 @@ public:
/**
* Buffer size constant.
*/
static constexpr v_buff_size BUFFER_SIZE = 4096;
static const v_buff_size BUFFER_SIZE;
private:
static oatpp::base::memory::ThreadDistributedMemoryPool& getBufferPool() {
static auto pool = new oatpp::base::memory::ThreadDistributedMemoryPool("IOBuffer_Buffer_Pool", BUFFER_SIZE, 16);

View File

@ -24,12 +24,13 @@
#include "./Primitive.hpp"
#include "oatpp/core/data/stream/BufferStream.hpp"
#include "oatpp/core/utils/ConversionUtils.hpp"
namespace oatpp { namespace data { namespace mapping { namespace type {
String::String(const std::shared_ptr<oatpp::base::StrBuffer>& ptr, const type::Type* const valueType)
: oatpp::data::mapping::type::ObjectWrapper<oatpp::base::StrBuffer, __class::String>(ptr)
String::String(const std::shared_ptr<std::string>& ptr, const type::Type* const valueType)
: oatpp::data::mapping::type::ObjectWrapper<std::string, __class::String>(ptr)
{
if(type::__class::String::getType() != valueType) {
throw std::runtime_error("Value type does not match");
@ -37,15 +38,21 @@ String::String(const std::shared_ptr<oatpp::base::StrBuffer>& ptr, const type::T
}
String operator + (const char* a, const String& b) {
return oatpp::base::StrBuffer::createSharedConcatenated(a, (v_int32) std::strlen(a), b->getData(), b->getSize());
data::stream::BufferOutputStream stream;
stream << a << b;
return stream.toString();
}
String operator + (const String& b, const char* a) {
return oatpp::base::StrBuffer::createSharedConcatenated(b->getData(), b->getSize(), a, (v_int32) std::strlen(a));
String operator + (const String& a, const char* b) {
data::stream::BufferOutputStream stream;
stream << a << b;
return stream.toString();
}
String operator + (const String& a, const String& b) {
return oatpp::base::StrBuffer::createSharedConcatenated(a->getData(), a->getSize(), b->getData(), b->getSize());
data::stream::BufferOutputStream stream;
stream << a << b;
return stream.toString();
}
namespace __class {

View File

@ -29,7 +29,6 @@
#include "oatpp/core/base/memory/ObjectPool.hpp"
#include "oatpp/core/base/Countable.hpp"
#include "oatpp/core/base/StrBuffer.hpp"
namespace oatpp { namespace data { namespace mapping { namespace type {
@ -57,56 +56,102 @@ namespace __class {
}
/**
* Mapping-enables String is &id:type::ObjectWrapper; over &id:oatpp::base::StrBuffer;
* Mapping-enables String is &id:type::ObjectWrapper; over `std::string`;
*/
class String : public type::ObjectWrapper<base::StrBuffer, __class::String> {
class String : public type::ObjectWrapper<std::string, __class::String> {
public:
String(const std::shared_ptr<base::StrBuffer>& ptr, const type::Type* const valueType);
String(const std::shared_ptr<std::string>& ptr, const type::Type* const valueType);
public:
String() {}
String(std::nullptr_t) {}
explicit String(v_buff_size size)
: type::ObjectWrapper<base::StrBuffer, __class::String>(base::StrBuffer::createShared(size))
: type::ObjectWrapper<std::string, __class::String>(std::make_shared<std::string>(size, 0))
{}
String(const char* data, v_buff_size size, bool copyAsOwnData = true)
: type::ObjectWrapper<base::StrBuffer, __class::String>(base::StrBuffer::createShared(data, size, copyAsOwnData))
String(const char* data, v_buff_size size)
: type::ObjectWrapper<std::string, __class::String>(std::make_shared<std::string>(data, size))
{}
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, std::nullptr_t>::value, void>::type
>
String(T) {}
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, char>::value, void>::type
>
String(const T* data)
: type::ObjectWrapper<std::string, __class::String>(
data == nullptr ? nullptr : std::make_shared<std::string>(data)
)
{}
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, std::string>::value, void>::type
>
String(const T& str)
: type::ObjectWrapper<std::string, __class::String>(std::make_shared<std::string>(str))
{}
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, std::string>::value, void>::type
>
String(T&& str)
: type::ObjectWrapper<std::string, __class::String>(
std::make_shared<std::string>(std::forward<std::string>(str))
)
{}
String(const char* data1, v_buff_size size1, const char* data2, v_buff_size size2)
: type::ObjectWrapper<base::StrBuffer, __class::String>(base::StrBuffer::createSharedConcatenated(data1, size1, data2, size2))
String(const std::shared_ptr<std::string>& ptr)
: type::ObjectWrapper<std::string, __class::String>(ptr)
{}
String(const char* data, bool copyAsOwnData = true)
: type::ObjectWrapper<base::StrBuffer, __class::String>(base::StrBuffer::createFromCString(data, copyAsOwnData))
{}
String(const std::shared_ptr<base::StrBuffer>& ptr)
: type::ObjectWrapper<base::StrBuffer, __class::String>(ptr)
{}
String(std::shared_ptr<base::StrBuffer>&& ptr)
: type::ObjectWrapper<base::StrBuffer, __class::String>(std::forward<std::shared_ptr<base::StrBuffer>>(ptr))
String(std::shared_ptr<std::string>&& ptr)
: type::ObjectWrapper<std::string, __class::String>(std::forward<std::shared_ptr<std::string>>(ptr))
{}
String(const String& other)
: type::ObjectWrapper<base::StrBuffer, __class::String>(other)
: type::ObjectWrapper<std::string, __class::String>(other)
{}
String(String&& other)
: type::ObjectWrapper<base::StrBuffer, __class::String>(std::forward<String>(other))
: type::ObjectWrapper<std::string, __class::String>(std::forward<String>(other))
{}
const std::string& operator*() const {
return this->m_ptr.operator*();
}
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, std::nullptr_t>::value, void>::type
>
inline String& operator = (std::nullptr_t) {
m_ptr.reset();
return *this;
}
inline String& operator = (const char* str) {
m_ptr = base::StrBuffer::createFromCString(str);
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, char>::value, void>::type
>
inline String& operator = (const T* str) {
m_ptr = std::make_shared<std::string>(str);
return *this;
}
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, std::string>::value, void>::type
>
inline String& operator = (const T& str) {
m_ptr = std::make_shared<std::string>(str);
return *this;
}
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, std::string>::value, void>::type
>
inline String& operator = (T&& str) {
m_ptr = std::make_shared<std::string>(std::forward<std::string>(str));
return *this;
}
@ -115,46 +160,70 @@ public:
return *this;
}
inline String& operator = (String&& other){
m_ptr = std::forward<std::shared_ptr<base::StrBuffer>>(other.m_ptr);
inline String& operator = (String&& other) noexcept {
m_ptr = std::move(other.m_ptr);
return *this;
}
inline bool operator == (std::nullptr_t) const {
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, std::nullptr_t>::value, void>::type
>
inline bool operator == (T) const {
return m_ptr.get() == nullptr;
}
inline bool operator != (std::nullptr_t) const {
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, std::nullptr_t>::value, void>::type
>
inline bool operator != (T) const {
return m_ptr.get() != nullptr;
}
inline bool operator == (const char* str) const {
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, char>::value, void>::type
>
inline bool operator == (const T* str) const {
if(!m_ptr) return str == nullptr;
if(str == nullptr) return false;
if(m_ptr->getSize() != v_buff_size(std::strlen(str))) return false;
return base::StrBuffer::equals(m_ptr->getData(), str, m_ptr->getSize());
return *m_ptr == str;
}
inline bool operator != (const char* str) const {
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, char>::value, void>::type
>
inline bool operator != (const T* str) const {
return !operator == (str);
}
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, std::string>::value, void>::type
>
inline bool operator == (const T& str) const {
if(!m_ptr) return false;
return *m_ptr == str;
}
template<typename T,
typename enabled = typename std::enable_if<std::is_same<T, std::string>::value, void>::type
>
inline bool operator != (const T& str) const {
return !operator == (str);
}
inline bool operator == (const String &other) const {
return base::StrBuffer::equals(m_ptr.get(), other.m_ptr.get());
if(!m_ptr) return !other.m_ptr;
if(!other.m_ptr) return false;
return *m_ptr == *other.m_ptr;
}
inline bool operator != (const String &other) const {
return !operator == (other);
}
inline explicit operator bool() const {
return m_ptr.operator bool();
}
};
String operator + (const char* a, const String& b);
String operator + (const String& b, const char* a);
String operator + (const String& a, const char* b);
String operator + (const String& a, const String& b);
/**
@ -551,16 +620,7 @@ namespace std {
result_type operator()(argument_type const& s) const noexcept {
if(s.get() == nullptr) return 0;
p_char8 data = s->getData();
result_type result = 0;
for(v_buff_size i = 0; i < s->getSize(); i++) {
v_char8 c = data[i] | 32;
result = (31 * result) + c;
}
return result;
return hash<std::string> {} (*s);
}
};

View File

@ -37,7 +37,7 @@ namespace oatpp { namespace data { namespace share {
* Lazy String Map keeps keys, and values as memory label.
* Once value is requested by user, the new memory block is allocated and value is copied to be stored permanently.
* @tparam Key - one of: &id:oatpp::data::share::MemoryLabel;, &id:oatpp::data::share::StringKeyLabel;, &id:oatpp::data::share::StringKeyLabelCI;,
* &id:oatpp::data::share::StringKeyLabelCI_FAST;.
* &id:oatpp::data::share::StringKeyLabelCI;.
*/
template<typename Key, typename MapType>
class LazyStringMapTemplate {
@ -202,8 +202,7 @@ public:
/**
* Get value as a memory label.
* @tparam T - one of: &id:oatpp::data::share::MemoryLabel;, &id:oatpp::data::share::StringKeyLabel;, &id:oatpp::data::share::StringKeyLabelCI;,
* &id:oatpp::data::share::StringKeyLabelCI_FAST;.
* @tparam T - one of: &id:oatpp::data::share::MemoryLabel;, &id:oatpp::data::share::StringKeyLabel;, &id:oatpp::data::share::StringKeyLabelCI;.
* @param key
* @return
*/
@ -217,7 +216,7 @@ public:
if(it != m_map.end()) {
it->second.captureToOwnMemory();
const auto& label = it->second;
return T(label.getMemoryHandle(), label.getData(), label.getSize());
return T(label.getMemoryHandle(), (const char*) label.getData(), label.getSize());
}
return T(nullptr, nullptr, 0);
@ -227,7 +226,7 @@ public:
/**
* Get value as a memory label without allocating memory for value.
* @tparam T - one of: &id:oatpp::data::share::MemoryLabel;, &id:oatpp::data::share::StringKeyLabel;, &id:oatpp::data::share::StringKeyLabelCI;,
* * &id:oatpp::data::share::StringKeyLabelCI_FAST;.
* * &id:oatpp::data::share::StringKeyLabelCI;.
* @param key
* @return
*/
@ -240,7 +239,7 @@ public:
if(it != m_map.end()) {
const auto& label = it->second;
return T(label.getMemoryHandle(), label.getData(), label.getSize());
return T(label.getMemoryHandle(), (const char*)label.getData(), label.getSize());
}
return T(nullptr, nullptr, 0);

View File

@ -28,46 +28,34 @@
namespace oatpp { namespace data { namespace share {
MemoryLabel::MemoryLabel(const std::shared_ptr<base::StrBuffer>& memHandle, p_char8 data, v_buff_size size)
MemoryLabel::MemoryLabel(const std::shared_ptr<std::string>& memHandle, const void* data, v_buff_size size)
: m_memoryHandle(memHandle)
, m_data(data)
, m_size(size)
{}
StringKeyLabel::StringKeyLabel(const std::shared_ptr<base::StrBuffer>& memHandle, p_char8 data, v_buff_size size)
StringKeyLabel::StringKeyLabel(const std::shared_ptr<std::string>& memHandle, const char* data, v_buff_size size)
: oatpp::data::share::MemoryLabel(memHandle, data, size)
{}
StringKeyLabel::StringKeyLabel(const char* constText)
: oatpp::data::share::MemoryLabel(nullptr, (p_char8)constText, std::strlen(constText))
: oatpp::data::share::MemoryLabel(nullptr, constText, std::strlen(constText))
{}
StringKeyLabel::StringKeyLabel(const String& str)
: oatpp::data::share::MemoryLabel(str.getPtr(), str->getData(), str->getSize())
: oatpp::data::share::MemoryLabel(str.getPtr(), str->data(), str->size())
{}
StringKeyLabelCI::StringKeyLabelCI(const std::shared_ptr<base::StrBuffer>& memHandle, p_char8 data, v_buff_size size)
StringKeyLabelCI::StringKeyLabelCI(const std::shared_ptr<std::string>& memHandle, const char* data, v_buff_size size)
: oatpp::data::share::MemoryLabel(memHandle, data, size)
{}
StringKeyLabelCI::StringKeyLabelCI(const char* constText)
: oatpp::data::share::MemoryLabel(nullptr, (p_char8)constText, std::strlen(constText))
: oatpp::data::share::MemoryLabel(nullptr, constText, std::strlen(constText))
{}
StringKeyLabelCI::StringKeyLabelCI(const String& str)
: oatpp::data::share::MemoryLabel(str.getPtr(), str->getData(), str->getSize())
{}
StringKeyLabelCI_FAST::StringKeyLabelCI_FAST(const std::shared_ptr<base::StrBuffer>& memHandle, p_char8 data, v_buff_size size)
: oatpp::data::share::MemoryLabel(memHandle, data, size)
{}
StringKeyLabelCI_FAST::StringKeyLabelCI_FAST(const char* constText)
: oatpp::data::share::MemoryLabel(nullptr, (p_char8)constText, std::strlen(constText))
{}
StringKeyLabelCI_FAST::StringKeyLabelCI_FAST(const String& str)
: oatpp::data::share::MemoryLabel(str.getPtr(), str->getData(), str->getSize())
: oatpp::data::share::MemoryLabel(str.getPtr(), str->data(), str->size())
{}
}}}

View File

@ -25,8 +25,8 @@
#ifndef oatpp_data_share_MemoryLabel_hpp
#define oatpp_data_share_MemoryLabel_hpp
#include "oatpp/core/base/StrBuffer.hpp"
#include "oatpp/core/data/mapping/type/Primitive.hpp"
#include "oatpp/core/utils/String.hpp"
namespace oatpp { namespace data { namespace share {
@ -39,8 +39,8 @@ class MemoryLabel {
public:
typedef oatpp::data::mapping::type::String String;
protected:
mutable std::shared_ptr<base::StrBuffer> m_memoryHandle;
mutable p_char8 m_data;
mutable std::shared_ptr<std::string> m_memoryHandle;
mutable const void* m_data;
v_buff_size m_size;
public:
@ -66,7 +66,7 @@ public:
* Constructor.
* @param str
*/
MemoryLabel(const std::shared_ptr<base::StrBuffer>& str) : MemoryLabel(str, str->getData(), str->getSize()) {}
MemoryLabel(const std::shared_ptr<std::string>& str) : MemoryLabel(str, str->data(), (v_buff_size) str->size()) {}
/**
* Constructor.
@ -74,13 +74,13 @@ public:
* @param data - pointer to data.
* @param size - size of the data in bytes.
*/
MemoryLabel(const std::shared_ptr<base::StrBuffer>& memHandle, p_char8 data, v_buff_size size);
MemoryLabel(const std::shared_ptr<std::string>& memHandle, const void* data, v_buff_size size);
/**
* Get pointer to labeled data.
* @return - pointer to data.
*/
p_char8 getData() const {
const void* getData() const {
return m_data;
}
@ -94,9 +94,9 @@ public:
/**
* Get memory handle which this memory label holds.
* @return - `std::shared_ptr` to &id:oatpp::base::StrBuffer;.
* @return - `std::shared_ptr` to `std::string`.
*/
std::shared_ptr<base::StrBuffer> getMemoryHandle() const {
std::shared_ptr<std::string> getMemoryHandle() const {
return m_memoryHandle;
}
@ -104,32 +104,31 @@ public:
* Capture data referenced by memory label to its own memory.
*/
void captureToOwnMemory() const {
if(!m_memoryHandle || m_memoryHandle->getData() != m_data || m_memoryHandle->getSize() != m_size) {
m_memoryHandle.reset(new base::StrBuffer(m_data, m_size, true));
m_data = m_memoryHandle->getData();
if(!m_memoryHandle || m_memoryHandle->data() != (const char*)m_data || m_memoryHandle->size() != m_size) {
m_memoryHandle.reset(new std::string((const char*) m_data, m_size));
m_data = (p_char8) m_memoryHandle->data();
}
}
/**
* Check if labeled data equals to data specified.
* Data is compared using &id:oatpp::base::StrBuffer::equals;.
* Data is compared using &id:oatpp::urils::String::compare;.
* @param data - data to compare with labeled data.
* @return - `true` if equals.
*/
bool equals(const char* data) const {
v_buff_size size = std::strlen(data);
return m_size == size && base::StrBuffer::equals(m_data, data, m_size);
return utils::String::compare(m_data, m_size, data, std::strlen(data)) == 0;
}
/**
* Check if labeled data equals to data specified.
* Data is compared using &id:oatpp::base::StrBuffer::equals;.
* Data is compared using &id:oatpp::urils::String::compare;.
* @param data - data to compare with labeled data.
* @param size - data size.
* @return - `true` if equals.
*/
bool equals(const void* data, v_buff_size size) const {
return m_size == size && base::StrBuffer::equals(m_data, data, m_size);
return utils::String::compare(m_data, m_size, data, size) == 0;
}
/**
@ -137,7 +136,7 @@ public:
* @return oatpp::String(data, size)
*/
String toString() const {
return String((const char*) m_data, m_size, true);
return String((const char*) m_data, m_size);
}
/**
@ -172,7 +171,7 @@ public:
StringKeyLabel(std::nullptr_t) : MemoryLabel() {}
StringKeyLabel(const std::shared_ptr<base::StrBuffer>& memHandle, p_char8 data, v_buff_size size);
StringKeyLabel(const std::shared_ptr<std::string>& memoryHandle, const char* data, v_buff_size size);
StringKeyLabel(const char* constText);
StringKeyLabel(const String& str);
@ -185,10 +184,7 @@ public:
}
inline bool operator==(const char* str) const {
if(m_data == nullptr) return str == nullptr;
if(str == nullptr) return false;
if(m_size != v_buff_size(std::strlen(str))) return false;
return base::StrBuffer::equals(m_data, str, m_size);
return equals(str);
}
inline bool operator!=(const char* str) const {
@ -198,8 +194,7 @@ public:
inline bool operator==(const String& str) const {
if(m_data == nullptr) return str == nullptr;
if(str == nullptr) return false;
if(m_size != str->getSize()) return false;
return base::StrBuffer::equals(m_data, str->getData(), m_size);
return equals(str->data(), str->size());
}
inline bool operator!=(const String& str) const {
@ -207,19 +202,19 @@ public:
}
inline bool operator==(const StringKeyLabel &other) const {
return m_size == other.m_size && base::StrBuffer::equals(m_data, other.m_data, m_size);
return utils::String::compare(m_data, m_size, other.m_data, other.m_size) == 0;
}
inline bool operator!=(const StringKeyLabel &other) const {
return !(m_size == other.m_size && base::StrBuffer::equals(m_data, other.m_data, m_size));
return !operator==(other);
}
inline bool operator < (const StringKeyLabel &other) const {
return base::StrBuffer::compare(m_data, m_size, other.m_data, other.m_size) < 0;
return utils::String::compare(m_data, m_size, other.m_data, other.m_size) < 0;
}
inline bool operator > (const StringKeyLabel &other) const {
return base::StrBuffer::compare(m_data, m_size, other.m_data, other.m_size) > 0;
return utils::String::compare(m_data, m_size, other.m_data, other.m_size) > 0;
}
};
@ -234,7 +229,7 @@ public:
StringKeyLabelCI(std::nullptr_t) : MemoryLabel() {}
StringKeyLabelCI(const std::shared_ptr<base::StrBuffer>& memHandle, p_char8 data, v_buff_size size);
StringKeyLabelCI(const std::shared_ptr<std::string>& memoryHandle, const char* data, v_buff_size size);
StringKeyLabelCI(const char* constText);
StringKeyLabelCI(const String& str);
@ -247,10 +242,7 @@ public:
}
inline bool operator==(const char* str) const {
if(m_data == nullptr) return str == nullptr;
if(str == nullptr) return false;
if(m_size != v_buff_size(std::strlen(str))) return false;
return base::StrBuffer::equalsCI(m_data, str, m_size);
return utils::String::compareCI(m_data, m_size, str, std::strlen(str)) == 0;
}
inline bool operator!=(const char* str) const {
@ -260,8 +252,7 @@ public:
inline bool operator==(const String& str) const {
if(m_data == nullptr) return str == nullptr;
if(str == nullptr) return false;
if(m_size != str->getSize()) return false;
return base::StrBuffer::equalsCI(m_data, str->getData(), m_size);
return utils::String::compareCI(m_data, m_size, str->data(), str->size()) == 0;
}
inline bool operator!=(const String& str) const {
@ -269,86 +260,22 @@ public:
}
inline bool operator==(const StringKeyLabelCI &other) const {
return m_size == other.m_size && base::StrBuffer::equalsCI(m_data, other.m_data, m_size);
return utils::String::compareCI(m_data, m_size, other.m_data, other.m_size) == 0;
}
inline bool operator!=(const StringKeyLabelCI &other) const {
return !(m_size == other.m_size && base::StrBuffer::equalsCI(m_data, other.m_data, m_size));
return !operator==(other);
}
inline bool operator < (const StringKeyLabelCI &other) const {
return base::StrBuffer::compareCI(m_data, m_size, other.m_data, other.m_size) < 0;
return utils::String::compareCI(m_data, m_size, other.m_data, other.m_size) < 0;
}
inline bool operator > (const StringKeyLabelCI &other) const {
return base::StrBuffer::compareCI(m_data, m_size, other.m_data, other.m_size) > 0;
return utils::String::compareCI(m_data, m_size, other.m_data, other.m_size) > 0;
}
};
/**
* MemoryLabel which can be used as a case-insensitive-fast key in unordered_map.
* CI_FAST - is appropriate for strings consisting of [a..z] + [A..Z] only.
* for other symbols undefined collisions may occur.
*/
class StringKeyLabelCI_FAST : public MemoryLabel {
public:
StringKeyLabelCI_FAST() : MemoryLabel() {};
StringKeyLabelCI_FAST(std::nullptr_t) : MemoryLabel() {}
StringKeyLabelCI_FAST(const std::shared_ptr<base::StrBuffer>& memHandle, p_char8 data, v_buff_size size);
StringKeyLabelCI_FAST(const char* constText);
StringKeyLabelCI_FAST(const String& str);
inline bool operator==(std::nullptr_t) const {
return m_data == nullptr;
}
inline bool operator!=(std::nullptr_t) const {
return m_data != nullptr;
}
inline bool operator==(const char* str) const {
if(m_data == nullptr) return str == nullptr;
if(str == nullptr) return false;
if(m_size != v_buff_size(std::strlen(str))) return false;
return base::StrBuffer::equalsCI_FAST(m_data, str, m_size);
}
inline bool operator!=(const char* str) const {
return !operator==(str);
}
inline bool operator==(const String& str) const {
if(m_data == nullptr) return str == nullptr;
if(str == nullptr) return false;
if(m_size != str->getSize()) return false;
return base::StrBuffer::equalsCI_FAST(m_data, str->getData(), m_size);
}
inline bool operator!=(const String& str) const {
return !operator==(str);
}
inline bool operator==(const StringKeyLabelCI_FAST &other) const {
return m_size == other.m_size && base::StrBuffer::equalsCI_FAST(m_data, other.m_data, m_size);
}
inline bool operator!=(const StringKeyLabelCI_FAST &other) const {
return !(m_size == other.m_size && base::StrBuffer::equalsCI_FAST(m_data, other.m_data, m_size));
}
inline bool operator < (const StringKeyLabelCI_FAST &other) const {
return base::StrBuffer::compareCI_FAST(m_data, m_size, other.m_data, other.m_size) < 0;
}
inline bool operator > (const StringKeyLabelCI_FAST &other) const {
return base::StrBuffer::compareCI_FAST(m_data, m_size, other.m_data, other.m_size) > 0;
}
};
}}}
@ -362,7 +289,7 @@ namespace std {
result_type operator()(oatpp::data::share::StringKeyLabel const& s) const noexcept {
p_char8 data = s.getData();
p_char8 data = (p_char8) s.getData();
result_type result = 0;
for(v_buff_size i = 0; i < s.getSize(); i++) {
v_char8 c = data[i];
@ -382,27 +309,7 @@ namespace std {
result_type operator()(oatpp::data::share::StringKeyLabelCI const& s) const noexcept {
p_char8 data = s.getData();
result_type result = 0;
for(v_buff_size i = 0; i < s.getSize(); i++) {
v_char8 c = data[i] | 32;
result = (31 * result) + c;
}
return result;
}
};
template<>
struct hash<oatpp::data::share::StringKeyLabelCI_FAST> {
typedef oatpp::data::share::StringKeyLabelCI_FAST argument_type;
typedef v_uint64 result_type;
result_type operator()(oatpp::data::share::StringKeyLabelCI_FAST const& s) const noexcept {
p_char8 data = s.getData();
p_char8 data = (p_char8) s.getData();
result_type result = 0;
for(v_buff_size i = 0; i < s.getSize(); i++) {
v_char8 c = data[i] | 32;

View File

@ -76,7 +76,7 @@ StringTemplate::StringTemplate(const oatpp::String& text, std::vector<Variable>&
throw std::runtime_error("[oatpp::data::share::StringTemplate::StringTemplate()]: Error. The template variable can't have a negative size.");
}
if(var.posEnd >= m_text->getSize()) {
if(var.posEnd >= m_text->size()) {
throw std::runtime_error("[oatpp::data::share::StringTemplate::StringTemplate()]: Error. The template variable can't out-bound the template text.");
}
}
@ -92,21 +92,21 @@ void StringTemplate::format(stream::ConsistentOutputStream* stream, ValueProvide
if(!value) {
throw std::runtime_error("[oatpp::data::share::StringTemplate::format()]: "
"Error. No value provided for the parameter name=" + var.name->std_str());
"Error. No value provided for the parameter name=" + *var.name);
}
if(prevPos < var.posStart) {
stream->writeSimple(m_text->getData() + prevPos, var.posStart - prevPos);
stream->writeSimple(m_text->data() + prevPos, var.posStart - prevPos);
}
stream->writeSimple(value->getData(), value->getSize());
stream->writeSimple(value->data(), value->size());
prevPos = var.posEnd + 1;
}
if(prevPos < m_text->getSize()) {
stream->writeSimple(m_text->getData() + prevPos, m_text->getSize() - prevPos);
if(prevPos < m_text->size()) {
stream->writeSimple(m_text->data() + prevPos, m_text->size() - prevPos);
}
}

View File

@ -117,14 +117,14 @@ void BufferOutputStream::setCurrentPosition(v_buff_size position) {
}
oatpp::String BufferOutputStream::toString() {
return oatpp::String((const char*)m_data, m_position, true);
return oatpp::String((const char*) m_data, m_position);
}
oatpp::String BufferOutputStream::getSubstring(v_buff_size pos, v_buff_size count) {
if(pos + count <= m_position) {
return oatpp::String((const char *) (m_data + pos), count, true);
return oatpp::String((const char *) (m_data + pos), count);
} else {
return oatpp::String((const char *) (m_data + pos), m_position - pos, true);
return oatpp::String((const char *) (m_data + pos), m_position - pos);
}
}
@ -167,19 +167,19 @@ oatpp::async::CoroutineStarter BufferOutputStream::flushToStreamAsync(const std:
data::stream::DefaultInitializedContext BufferInputStream::DEFAULT_CONTEXT(data::stream::StreamType::STREAM_FINITE);
BufferInputStream::BufferInputStream(const std::shared_ptr<base::StrBuffer>& memoryHandle, p_char8 data, v_buff_size size)
BufferInputStream::BufferInputStream(const std::shared_ptr<std::string>& memoryHandle, const void* data, v_buff_size size)
: m_memoryHandle(memoryHandle)
, m_data(data)
, m_data((p_char8) data)
, m_size(size)
, m_position(0)
, m_ioMode(IOMode::ASYNCHRONOUS)
{}
BufferInputStream::BufferInputStream(const oatpp::String& data)
: BufferInputStream(data.getPtr(), data->getData(), data->getSize())
: BufferInputStream(data.getPtr(), (p_char8) data->data(), data->size())
{}
void BufferInputStream::reset(const std::shared_ptr<base::StrBuffer>& memoryHandle, p_char8 data, v_buff_size size) {
void BufferInputStream::reset(const std::shared_ptr<std::string>& memoryHandle, p_char8 data, v_buff_size size) {
m_memoryHandle = memoryHandle;
m_data = data;
m_size = size;
@ -218,7 +218,7 @@ Context& BufferInputStream::getInputStreamContext() {
return DEFAULT_CONTEXT;
}
std::shared_ptr<base::StrBuffer> BufferInputStream::getDataMemoryHandle() {
std::shared_ptr<std::string> BufferInputStream::getDataMemoryHandle() {
return m_memoryHandle;
}

View File

@ -150,7 +150,7 @@ class BufferInputStream : public InputStream {
public:
static data::stream::DefaultInitializedContext DEFAULT_CONTEXT;
private:
std::shared_ptr<base::StrBuffer> m_memoryHandle;
std::shared_ptr<std::string> m_memoryHandle;
p_char8 m_data;
v_buff_size m_size;
v_buff_size m_position;
@ -163,7 +163,7 @@ public:
* @param data - pointer to buffer data.
* @param size - size of the buffer.
*/
BufferInputStream(const std::shared_ptr<base::StrBuffer>& memoryHandle, p_char8 data, v_buff_size size);
BufferInputStream(const std::shared_ptr<std::string>& memoryHandle, const void* data, v_buff_size size);
/**
* Constructor.
@ -177,7 +177,7 @@ public:
* @param data - pointer to buffer data.
* @param size - size of the buffer.
*/
void reset(const std::shared_ptr<base::StrBuffer>& memoryHandle, p_char8 data, v_buff_size size);
void reset(const std::shared_ptr<std::string>& memoryHandle, p_char8 data, v_buff_size size);
/**
@ -219,7 +219,7 @@ public:
* Get data memory handle.
* @return - data memory handle.
*/
std::shared_ptr<base::StrBuffer> getDataMemoryHandle();
std::shared_ptr<std::string> getDataMemoryHandle();
/**
* Get pointer to data.

View File

@ -165,8 +165,8 @@ Context& ChunkedBuffer::getOutputStreamContext() {
}
v_io_size ChunkedBuffer::readSubstring(void *buffer,
v_buff_size pos,
v_buff_size count)
v_buff_size pos,
v_buff_size count)
{
if(pos < 0 || pos >= m_size){
@ -215,7 +215,7 @@ v_io_size ChunkedBuffer::readSubstring(void *buffer,
oatpp::String ChunkedBuffer::getSubstring(v_buff_size pos, v_buff_size count){
auto str = oatpp::String((v_int32) count);
readSubstring(str->getData(), pos, count);
readSubstring((p_char8)str->data(), pos, count);
return str;
}

View File

@ -239,7 +239,7 @@ public:
* @return - actual number of bytes written. &id:oatpp::v_io_size;.
*/
v_io_size writeSimple(const oatpp::String& str){
return writeSimple(str->getData(), str->getSize());
return writeSimple(str->data(), str->size());
}
/**

View File

@ -45,7 +45,7 @@ public:
const oatpp::data::share::MemoryLabel& memoryLabel)
: m_outputStream(outputStream)
, m_memoryLabel(memoryLabel)
, m_buffer(memoryLabel.getData(), memoryLabel.getSize())
, m_buffer((void *) memoryLabel.getData(), memoryLabel.getSize())
{}
public:
@ -98,7 +98,7 @@ public:
bool bufferCanRead)
: m_inputStream(inputStream)
, m_memoryLabel(memoryLabel)
, m_buffer(memoryLabel.getData(), memoryLabel.getSize(), bufferReadPosition, bufferWritePosition, bufferCanRead)
, m_buffer((void*) memoryLabel.getData(), memoryLabel.getSize(), bufferReadPosition, bufferWritePosition, bufferCanRead)
{}
public:

View File

@ -54,7 +54,7 @@ namespace oatpp { namespace parser {
m_end = m_caret->m_pos;
}
p_char8 Caret::Label::getData(){
const char* Caret::Label::getData(){
return &m_caret->m_data[m_start];
}
@ -73,16 +73,12 @@ namespace oatpp { namespace parser {
return m_end;
};
oatpp::String Caret::Label::toString(bool saveAsOwnData){
oatpp::String Caret::Label::toString(){
v_buff_size end = m_end;
if(end == -1){
end = m_caret->m_pos;
}
return oatpp::String((const char*)&m_caret->m_data[m_start], end - m_start, saveAsOwnData);
}
oatpp::String Caret::Label::toString(){
return toString(true);
return oatpp::String((const char*)&m_caret->m_data[m_start], end - m_start);
}
std::string Caret::Label::std_str(){
@ -129,10 +125,10 @@ v_int64 Caret::StateSaveGuard::getSavedErrorCode() {
// Caret
Caret::Caret(const char* text)
: Caret((p_char8)text, std::strlen(text))
: Caret(text, std::strlen(text))
{}
Caret::Caret(p_char8 parseData, v_buff_size dataSize)
Caret::Caret(const char* parseData, v_buff_size dataSize)
: m_data(parseData)
, m_size(dataSize)
, m_pos(0)
@ -141,7 +137,7 @@ v_int64 Caret::StateSaveGuard::getSavedErrorCode() {
{}
Caret::Caret(const oatpp::String& str)
: Caret(str->getData(), str->getSize())
: Caret(str->data(), str->size())
{
m_dataMemoryHandle = str.getPtr();
}
@ -150,22 +146,22 @@ v_int64 Caret::StateSaveGuard::getSavedErrorCode() {
return std::make_shared<Caret>(text);
}
std::shared_ptr<Caret> Caret::createShared(p_char8 parseData, v_buff_size dataSize){
std::shared_ptr<Caret> Caret::createShared(const char* parseData, v_buff_size dataSize){
return std::make_shared<Caret>(parseData, dataSize);
}
std::shared_ptr<Caret> Caret::createShared(const oatpp::String& str){
return std::make_shared<Caret>(str->getData(), str->getSize());
return std::make_shared<Caret>(str->data(), str->size());
}
Caret::~Caret(){
}
p_char8 Caret::getData(){
const char* Caret::getData(){
return m_data;
}
p_char8 Caret::getCurrData(){
const char* Caret::getCurrData(){
return &m_data[m_pos];
}
@ -173,7 +169,7 @@ v_int64 Caret::StateSaveGuard::getSavedErrorCode() {
return m_size;
}
std::shared_ptr<oatpp::base::StrBuffer> Caret::getDataMemoryHandle() {
std::shared_ptr<std::string> Caret::getDataMemoryHandle() {
return m_dataMemoryHandle;
}
@ -252,10 +248,10 @@ v_int64 Caret::StateSaveGuard::getSavedErrorCode() {
}
bool Caret::skipCharsFromSet(const char* set){
return skipCharsFromSet((p_char8)set, std::strlen(set));
return skipCharsFromSet(set, std::strlen(set));
}
bool Caret::skipCharsFromSet(p_char8 set, v_buff_size setSize){
bool Caret::skipCharsFromSet(const char* set, v_buff_size setSize){
while(m_pos < m_size){
if(!isAtCharFromSet(set, setSize)){
@ -269,10 +265,10 @@ v_int64 Caret::StateSaveGuard::getSavedErrorCode() {
}
v_buff_size Caret::findCharFromSet(const char* set){
return findCharFromSet((p_char8) set, std::strlen(set));
return findCharFromSet(set, std::strlen(set));
}
v_buff_size Caret::findCharFromSet(p_char8 set, v_buff_size setSize){
v_buff_size Caret::findCharFromSet(const char* set, v_buff_size setSize){
while(m_pos < m_size){
@ -399,10 +395,10 @@ v_int64 Caret::StateSaveGuard::getSavedErrorCode() {
}
bool Caret::isAtText(const char* text, bool skipIfTrue){
return isAtText((p_char8)text, std::strlen(text), skipIfTrue);
return isAtText(text, std::strlen(text), skipIfTrue);
}
bool Caret::isAtText(p_char8 text, v_buff_size textSize, bool skipIfTrue){
bool Caret::isAtText(const char* text, v_buff_size textSize, bool skipIfTrue){
if(textSize <= m_size - m_pos){
@ -427,10 +423,10 @@ v_int64 Caret::StateSaveGuard::getSavedErrorCode() {
}
bool Caret::isAtTextNCS(const char* text, bool skipIfTrue){
return isAtTextNCS((p_char8)text, std::strlen(text), skipIfTrue);
return isAtTextNCS(text, std::strlen(text), skipIfTrue);
}
bool Caret::isAtTextNCS(p_char8 text, v_buff_size textSize, bool skipIfTrue){
bool Caret::isAtTextNCS(const char* text, v_buff_size textSize, bool skipIfTrue){
if(textSize <= m_size - m_pos){
@ -496,19 +492,19 @@ v_int64 Caret::StateSaveGuard::getSavedErrorCode() {
}
bool Caret::findText(const char* text) {
return findText((p_char8) text, std::strlen(text));
return findText(text, std::strlen(text));
}
bool Caret::findText(p_char8 text, v_buff_size textSize) {
bool Caret::findText(const char* text, v_buff_size textSize) {
m_pos = (std::search(&m_data[m_pos], &m_data[m_size], text, text + textSize) - m_data);
return m_pos != m_size;
}
bool Caret::isAtCharFromSet(const char* set) const{
return isAtCharFromSet((p_char8)set, std::strlen(set));
return isAtCharFromSet(set, std::strlen(set));
}
bool Caret::isAtCharFromSet(p_char8 set, v_buff_size setSize) const{
bool Caret::isAtCharFromSet(const char* set, v_buff_size setSize) const{
v_char8 a = m_data[m_pos];

View File

@ -72,7 +72,7 @@ public:
* Get pointer to a labeled data.
* @return
*/
p_char8 getData();
const char* getData();
/**
* Get size of labeled data.
@ -92,13 +92,6 @@ public:
*/
v_buff_size getEndPosition();
/**
* Create &id:oatpp::String; from labeled data.
* @param saveAsOwnData - `true` - allocate new memory block for string. `false` - string will point to the same data as label.
* @return - &id:oatpp::String;.
*/
oatpp::String toString(bool saveAsOwnData);
/**
* Same as`toString(true).`
* @return - &id:oatpp::String;.
@ -158,20 +151,20 @@ public:
};
private:
p_char8 m_data;
const char* m_data;
v_buff_size m_size;
v_buff_size m_pos;
const char* m_errorMessage;
v_int64 m_errorCode;
std::shared_ptr<oatpp::base::StrBuffer> m_dataMemoryHandle;
std::shared_ptr<std::string> m_dataMemoryHandle;
public:
Caret(const char* text);
Caret(p_char8 parseData, v_buff_size dataSize);
Caret(const char* parseData, v_buff_size dataSize);
Caret(const oatpp::String& str);
public:
static std::shared_ptr<Caret> createShared(const char* text);
static std::shared_ptr<Caret> createShared(p_char8 parseData, v_buff_size dataSize);
static std::shared_ptr<Caret> createShared(const char* parseData, v_buff_size dataSize);
static std::shared_ptr<Caret> createShared(const oatpp::String& str);
virtual ~Caret();
@ -180,13 +173,13 @@ public:
* Get pointer to a data, passed to Caret constructor
* @return
*/
p_char8 getData();
const char* getData();
/**
* Same as &getData()[position]
* @return
*/
p_char8 getCurrData();
const char* getCurrData();
/**
* Get size of a data
@ -198,7 +191,7 @@ public:
* Get data memoryHandle.
* @return
*/
std::shared_ptr<oatpp::base::StrBuffer> getDataMemoryHandle();
std::shared_ptr<std::string> getDataMemoryHandle();
/**
* Set caret position relative to data
@ -296,7 +289,7 @@ public:
* @param setSize
* @return true if other char found
*/
bool skipCharsFromSet(p_char8 set, v_buff_size setSize);
bool skipCharsFromSet(const char* set, v_buff_size setSize);
/**
* Find one of chars defined by set.
@ -311,7 +304,7 @@ public:
* @param setSize
* @return char found or -1 if no char found
*/
v_buff_size findCharFromSet(p_char8 set, v_buff_size setSize);
v_buff_size findCharFromSet(const char* set, v_buff_size setSize);
/**
* Find "\r\n" chars
@ -407,7 +400,7 @@ public:
* @param skipIfTrue - increase position if true
* @return
*/
bool isAtText(p_char8 text, v_buff_size textSize, bool skipIfTrue = false);
bool isAtText(const char* text, v_buff_size textSize, bool skipIfTrue = false);
/**
* Check if follows text (Not Case Sensitive)
@ -424,7 +417,7 @@ public:
* @param skipIfTrue - increase position if true
* @return
*/
bool isAtTextNCS(p_char8 text, v_buff_size textSize, bool skipIfTrue = false);
bool isAtTextNCS(const char* text, v_buff_size textSize, bool skipIfTrue = false);
/**
* Parse enclosed string.
@ -450,7 +443,7 @@ public:
* @param textSize
* @return true if found
*/
bool findText(p_char8 text, v_buff_size textSize);
bool findText(const char* text, v_buff_size textSize);
/**
* Check if caret is at char defined by set
@ -467,7 +460,7 @@ public:
* @param setSize
* @return
*/
bool isAtCharFromSet(p_char8 set, v_buff_size setSize) const;
bool isAtCharFromSet(const char* set, v_buff_size setSize) const;
/**
* Check if caret is at char

View File

@ -27,7 +27,7 @@
namespace oatpp { namespace parser {
ParsingError::ParsingError(const oatpp::String &message, v_int64 code, v_buff_size position)
:std::runtime_error(message->std_str())
:std::runtime_error(*message)
, m_message(message)
, m_code(code)
, m_position(position)

View File

@ -35,8 +35,8 @@ namespace oatpp { namespace utils { namespace conversion {
v_int32 strToInt32(const oatpp::String& str, bool& success){
char* end;
v_int32 result = (v_int32) std::strtol((const char*)str->getData(), &end, 10);
success = (((v_buff_size)end - (v_buff_size)str->getData()) == str->getSize());
v_int32 result = (v_int32) std::strtol(str->data(), &end, 10);
success = (((v_buff_size)end - (v_buff_size)str->data()) == str->size());
return result;
}
@ -47,8 +47,8 @@ namespace oatpp { namespace utils { namespace conversion {
v_uint32 strToUInt32(const oatpp::String& str, bool& success){
char* end;
v_uint32 result = (v_uint32) std::strtoul((const char*)str->getData(), &end, 10);
success = (((v_buff_size)end - (v_buff_size)str->getData()) == str->getSize());
v_uint32 result = (v_uint32) std::strtoul(str->data(), &end, 10);
success = (((v_buff_size)end - (v_buff_size)str->data()) == str->size());
return result;
}
@ -59,8 +59,8 @@ namespace oatpp { namespace utils { namespace conversion {
v_int64 strToInt64(const oatpp::String& str, bool& success){
char* end;
v_int64 result = std::strtoll((const char*)str->getData(), &end, 10);
success = (((v_buff_size)end - (v_buff_size)str->getData()) == str->getSize());
v_int64 result = std::strtoll(str->data(), &end, 10);
success = (((v_buff_size)end - (v_buff_size)str->data()) == str->size());
return result;
}
@ -71,8 +71,8 @@ namespace oatpp { namespace utils { namespace conversion {
v_uint64 strToUInt64(const oatpp::String& str, bool& success){
char* end;
v_uint64 result = std::strtoull((const char*)str->getData(), &end, 10);
success = (((v_buff_size)end - (v_buff_size)str->getData()) == str->getSize());
v_uint64 result = std::strtoull(str->data(), &end, 10);
success = (((v_buff_size)end - (v_buff_size)str->data()) == str->size());
return result;
}
@ -96,7 +96,7 @@ namespace oatpp { namespace utils { namespace conversion {
v_char8 buff [16]; // Max 10 digits with 1 sign. 16 is plenty enough.
auto size = int32ToCharSequence(value, &buff[0], 16);
if(size > 0){
return oatpp::String((const char*)&buff[0], size, true);
return oatpp::String((const char*)&buff[0], size);
}
return nullptr;
}
@ -105,7 +105,7 @@ namespace oatpp { namespace utils { namespace conversion {
v_char8 buff [16]; // Max 10 digits. 16 is plenty enough.
auto size = uint32ToCharSequence(value, &buff[0], 16);
if(size > 0){
return oatpp::String((const char*)&buff[0], size, true);
return oatpp::String((const char*)&buff[0], size);
}
return nullptr;
}
@ -114,7 +114,7 @@ namespace oatpp { namespace utils { namespace conversion {
v_char8 buff [32]; // Max 20 digits unsigned, 19 digits +1 sign signed.
auto size = int64ToCharSequence(value, &buff[0], 32);
if(size > 0){
return oatpp::String((const char*)&buff[0], size, true);
return oatpp::String((const char*)&buff[0], size);
}
return nullptr;
}
@ -123,7 +123,7 @@ namespace oatpp { namespace utils { namespace conversion {
v_char8 buff [32]; // Max 20 digits.
auto size = uint64ToCharSequence(value, &buff[0], 32);
if(size > 0){
return oatpp::String((const char*)&buff[0], size, true);
return oatpp::String((const char*)&buff[0], size);
}
return nullptr;
}
@ -171,8 +171,8 @@ namespace oatpp { namespace utils { namespace conversion {
v_float32 strToFloat32(const oatpp::String& str, bool& success) {
char* end;
v_float32 result = std::strtof((const char*)str->getData(), &end);
success = (((v_buff_size)end - (v_buff_size)str->getData()) == str->getSize());
v_float32 result = std::strtof(str->data(), &end);
success = (((v_buff_size)end - (v_buff_size)str->data()) == str->size());
return result;
}
@ -183,8 +183,8 @@ namespace oatpp { namespace utils { namespace conversion {
v_float64 strToFloat64(const oatpp::String& str, bool& success) {
char* end;
v_float64 result = std::strtod((const char*)str->getData(), &end);
success = (((v_buff_size)end - (v_buff_size)str->getData()) == str->getSize());
v_float64 result = std::strtod(str->data(), &end);
success = (((v_buff_size)end - (v_buff_size)str->data()) == str->size());
return result;
}
@ -200,7 +200,7 @@ v_buff_size float64ToCharSequence(v_float64 value, p_char8 data, v_buff_size n,
v_char8 buff [100];
auto size = float32ToCharSequence(value, &buff[0], 100, format);
if(size > 0){
return oatpp::String((const char*)&buff[0], size, true);
return oatpp::String((const char*)&buff[0], size);
}
return nullptr;
}
@ -209,24 +209,24 @@ v_buff_size float64ToCharSequence(v_float64 value, p_char8 data, v_buff_size n,
v_char8 buff [100];
auto size = float64ToCharSequence(value, &buff[0], 100, format);
if(size > 0){
return oatpp::String((const char*)&buff[0], size, true);
return oatpp::String((const char*)&buff[0], size);
}
return nullptr;
}
oatpp::String boolToStr(bool value) {
if(value){
return oatpp::String("true", 4, false);
return oatpp::String("true", 4);
} else {
return oatpp::String("false", 5, false);
return oatpp::String("false", 5);
}
}
bool strToBool(const oatpp::String& str, bool& success) {
if(str->equals((p_char8)"true", 4)){
if(str == "true"){
success = true;
return true;
} else if(str->equals((p_char8)"false", 5)){
} else if(str == "false"){
success = true;
return false;
}

View File

@ -214,7 +214,7 @@ namespace oatpp { namespace utils { namespace conversion {
v_char8 buff [100];
auto size = primitiveToCharSequence(value, &buff[0], 100, pattern);
if(size > 0){
return oatpp::String((const char*)&buff[0], size, true);
return oatpp::String((const char*)&buff[0], size);
}
return nullptr;
}

View File

@ -0,0 +1,118 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#include "String.hpp"
#include <fstream>
namespace oatpp { namespace utils {
data::mapping::type::String String::loadFromFile(const char* filename) {
std::ifstream file (filename, std::ios::in|std::ios::binary|std::ios::ate);
if (file.is_open()) {
auto result = data::mapping::type::String(file.tellg());
file.seekg(0, std::ios::beg);
file.read((char*) result->data(), result->size());
file.close();
return result;
}
return nullptr;
}
void String::saveToFile(const data::mapping::type::String& data, const char* filename) {
std::ofstream fs(filename, std::ios::out | std::ios::binary);
fs.write(data->data(), data->size());
fs.close();
}
v_buff_size String::compare(const void* data1, v_buff_size size1, const void* data2, v_buff_size size2) {
if(data1 == data2) return 0;
if(data1 == nullptr) return -1;
if(data2 == nullptr) return 1;
if(size1 < size2) {
auto res = std::memcmp(data1, data2, size1);
if(res == 0) return -1;
return res;
}
if(size1 > size2) {
auto res = std::memcmp(data1, data2, size2);
if(res == 0) return 1;
return res;
}
return std::memcmp(data1, data2, size1);
}
v_buff_size String::compareCI(const void* data1, v_buff_size size1, const void* data2, v_buff_size size2) {
if(data1 == data2) return 0;
if(data1 == nullptr) return -1;
if(data2 == nullptr) return 1;
auto d1 = (p_char8) data1;
auto d2 = (p_char8) data2;
v_buff_size size = size1;
if(size2 < size1) size = size2;
for(v_buff_size i = 0; i < size; i ++) {
v_char8 a = d1[i];
v_char8 b = d2[i];
if(a >= 'A' && a <= 'Z') a |= 32;
if(b >= 'A' && b <= 'Z') b |= 32;
if(a != b) {
return (int) a - (int) b;
}
}
if(size1 < size2) return -1;
if(size1 > size2) return 1;
return 0;
}
void String::lowerCaseASCII(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) {
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

@ -0,0 +1,96 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#ifndef oatpp_utils_String_hpp
#define oatpp_utils_String_hpp
#include "oatpp/core/data/mapping/type/Primitive.hpp"
#include "oatpp/core/base/Environment.hpp"
namespace oatpp { namespace utils {
/**
* Utility class for Strings
*/
class String {
public:
/**
* Load data from file and store in &id:oatpp::String;.
* @param filename - name of the file.
* @return - &id:oatpp::String;.
*/
static data::mapping::type::String loadFromFile(const char* filename);
/**
* Save content of the buffer to file.
* @param filename - name of the file.
*/
static void saveToFile(const data::mapping::type::String& data, const char* filename);
/**
* Compare data1, data2 using `std::memcmp`.
* *It's safe to pass nullptr for data1/data2*
* @param data1 - pointer to data1.
* @param size1 - size of data1.
* @param data2 - pointer to data2.
* @param size2 - size of data2.
* @return - Negative value if the first differing byte (reinterpreted as unsigned char) in data1 is less than the corresponding byte in data2.<br>
* 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 compare(const void* data1, v_buff_size size1, const void* data2, v_buff_size size2);
/**
* Compare data1, data2 - case insensitive.
* *It's safe to pass nullptr for data1/data2*
* @param data1 - pointer to data1.
* @param size1 - size of data1.
* @param data2 - pointer to data2.
* @param size2 - size of data2.
* @return - Negative value if the first differing byte (reinterpreted as unsigned char) in data1 is less than the corresponding byte in data2.<br>
* 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);
/**
* 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);
/**
* 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);
};
}}
#endif // oatpp_utils_String_hpp

View File

@ -110,7 +110,7 @@ oatpp::String Base64::encode(const void* data, v_buff_size size, const char* alp
auto result = oatpp::String(resultSize);
p_char8 bdata = (p_char8) data;
p_char8 resultData = result->getData();
p_char8 resultData = (p_char8) result->data();
v_buff_size pos = 0;
while (pos + 2 < size) {
@ -147,7 +147,7 @@ oatpp::String Base64::encode(const void* data, v_buff_size size, const char* alp
}
oatpp::String Base64::encode(const oatpp::String& data, const char* alphabet) {
return encode(data->getData(), data->getSize(), alphabet);
return encode(data->data(), data->size(), alphabet);
}
oatpp::String Base64::decode(const char* data, v_buff_size size, const char* auxiliaryChars) {
@ -159,7 +159,7 @@ oatpp::String Base64::decode(const char* data, v_buff_size size, const char* aux
}
auto result = oatpp::String(resultSize);
p_char8 resultData = result->getData();
p_char8 resultData = (p_char8) result->data();
v_buff_size pos = 0;
while (pos + 3 < base64StrLength) {
v_char8 b0 = getAlphabetCharIndex(data[pos], auxiliaryChars);
@ -193,7 +193,7 @@ oatpp::String Base64::decode(const char* data, v_buff_size size, const char* aux
}
oatpp::String Base64::decode(const oatpp::String& data, const char* auxiliaryChars) {
return decode((const char*)data->getData(), data->getSize(), auxiliaryChars);
return decode((const char*)data->data(), data->size(), auxiliaryChars);
}
}}

View File

@ -48,7 +48,7 @@ void Hex::writeUInt32(v_uint32 value, p_char8 buffer){
writeUInt16(v_uint16(value), buffer + 4);
}
v_int32 Hex::readUInt16(p_char8 buffer, v_uint16& value) {
v_int32 Hex::readUInt16(const char* buffer, v_uint16& value) {
value = 0;
for(v_int32 i = 0; i < 4; i++){
v_char8 a = buffer[i];
@ -65,7 +65,7 @@ v_int32 Hex::readUInt16(p_char8 buffer, v_uint16& value) {
return 0;
}
v_int32 Hex::readUInt32(p_char8 buffer, v_uint32& value) {
v_int32 Hex::readUInt32(const char* buffer, v_uint32& value) {
value = 0;
for(v_int32 i = 0; i < 8; i++){
v_char8 a = buffer[i];

View File

@ -82,7 +82,7 @@ public:
* @param value - out parameter. Resultant value.
* @return - 0 on success. Negative value on failure.
*/
static v_int32 readUInt16(p_char8 buffer, v_uint16& value);
static v_int32 readUInt16(const char* buffer, v_uint16& value);
/**
* Parse 8-char hex string to int32.
@ -90,7 +90,7 @@ public:
* @param value - out parameter. Resultant value.
* @return - 0 on success. Negative value on failure.
*/
static v_int32 readUInt32(p_char8 buffer, v_uint32& value);
static v_int32 readUInt32(const char* buffer, v_uint32& value);
/**
* Write binary data as HEX string.

View File

@ -74,7 +74,7 @@ v_buff_size Unicode::getUtf8CharSequenceLengthForCode(v_uint32 code){
}
}
v_int32 Unicode::encodeUtf8Char(p_char8 sequence, v_buff_size& length){
v_int32 Unicode::encodeUtf8Char(const char* sequence, v_buff_size& length){
v_char8 byte = sequence[0];
if(byte > 127){
v_int32 code;

View File

@ -54,7 +54,7 @@ public:
* @param length - out parameter. Length in bytes of UTF-8 character.
* @return - code of UTF-8 character.
*/
static v_int32 encodeUtf8Char(p_char8 sequence, v_buff_size& length);
static v_int32 encodeUtf8Char(const char* sequence, v_buff_size& length);
/**
* Write UTF-8 character to buffer.

View File

@ -35,15 +35,15 @@ 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);
oatpp::base::StrBuffer::lowerCase(buff.get(), size);
return oatpp::String((const char*)buff.get(), size, true);
utils::String::lowerCaseASCII(buff.get(), size);
return oatpp::String((const char*)buff.get(), size);
}
return nullptr;
}
Url::Authority Url::Parser::parseAuthority(oatpp::parser::Caret& caret) {
p_char8 data = caret.getData();
const char* data = caret.getData();
v_buff_size pos0 = caret.getPosition();
v_buff_size pos = pos0;
@ -75,11 +75,11 @@ Url::Authority Url::Parser::parseAuthority(oatpp::parser::Caret& caret) {
Url::Authority result;
if(atPos > -1) {
result.userInfo = oatpp::String((const char*)&data[pos0], atPos - pos0, true);
result.userInfo = oatpp::String((const char*)&data[pos0], atPos - pos0);
}
if(portPos > hostPos) {
result.host = oatpp::String((const char*)&data[hostPos], portPos - 1 - hostPos, true);
result.host = oatpp::String((const char*)&data[hostPos], portPos - 1 - hostPos);
char* end;
result.port = std::strtol((const char*)&data[portPos], &end, 10);
bool success = (((v_buff_size)end - (v_buff_size)&data[portPos]) == pos - portPos);
@ -87,7 +87,7 @@ Url::Authority Url::Parser::parseAuthority(oatpp::parser::Caret& caret) {
caret.setError("Invalid port string");
}
} else {
result.host = oatpp::String((const char*)&data[hostPos], pos - pos0, true);
result.host = oatpp::String((const char*)&data[hostPos], pos - pos0);
}
return result;
@ -96,9 +96,9 @@ Url::Authority Url::Parser::parseAuthority(oatpp::parser::Caret& caret) {
oatpp::String Url::Parser::parsePath(oatpp::parser::Caret& caret) {
auto label = caret.putLabel();
caret.findCharFromSet((p_char8)"?#", 2);
caret.findCharFromSet("?#", 2);
if(label.getSize() > 0) {
return label.toString(true);
return label.toString();
}
return nullptr;
}
@ -156,7 +156,7 @@ Url Url::Parser::parseUrl(oatpp::parser::Caret& caret) {
caret.setPosition(0);
}
caret.isAtText((p_char8)"//", 2, true);
caret.isAtText("//", 2, true);
if(!caret.isAtChar('/')) {
result.authority = parseAuthority(caret);

View File

@ -52,7 +52,7 @@ void Interface::registerInterface(const std::shared_ptr<Interface>& interface) {
auto it = m_registry.find(interface->getName());
if(it != m_registry.end()) {
throw std::runtime_error
("[oatpp::network::virtual_::Interface::registerInterface()]: Error. Interface with such name already exists - '" + interface->getName()->std_str() + "'.");
("[oatpp::network::virtual_::Interface::registerInterface()]: Error. Interface with such name already exists - '" + *interface->getName() + "'.");
}
m_registry.insert({interface->getName(), interface});
@ -66,7 +66,7 @@ void Interface::unregisterInterface(const oatpp::String& name) {
auto it = m_registry.find(name);
if(it == m_registry.end()) {
throw std::runtime_error
("[oatpp::network::virtual_::Interface::unregisterInterface()]: Error. Interface NOT FOUND - '" + name->std_str() + "'.");
("[oatpp::network::virtual_::Interface::unregisterInterface()]: Error. Interface NOT FOUND - '" + *name + "'.");
}
m_registry.erase(it);
@ -166,7 +166,7 @@ std::shared_ptr<Interface::ListenerLock> Interface::bind() {
return std::shared_ptr<ListenerLock>(m_listenerLock.load());
}
throw std::runtime_error(
"[oatpp::network::virtual_::Interface::bind()]: Can't bind to interface '" + m_name->std_str() + "'. Listener lock is already acquired");
"[oatpp::network::virtual_::Interface::bind()]: Can't bind to interface '" + *m_name + "'. Listener lock is already acquired");
}
void Interface::unbindListener(ListenerLock* listenerLock) {

View File

@ -54,7 +54,7 @@ std::shared_ptr<data::stream::IOStream> ConnectionProvider::get() {
return socket;
}
}
throw std::runtime_error("[oatpp::network::virtual_::client::getConnection()]: Error. Can't connect. " + m_interface->getName()->std_str());
throw std::runtime_error("[oatpp::network::virtual_::client::getConnection()]: Error. Can't connect. " + *m_interface->getName());
}
oatpp::async::CoroutineStarterForResult<const std::shared_ptr<oatpp::data::stream::IOStream>&> ConnectionProvider::getAsync() {

View File

@ -72,7 +72,7 @@ void SchemaMigration::migrate() {
break;
case SOURCE_FILE:
script = base::StrBuffer::loadFromFile(source.param->c_str());
script = utils::String::loadFromFile(source.param->c_str());
break;
default:

View File

@ -36,7 +36,7 @@ Transaction::Transaction(const base::ObjectHandle<Executor>& executor, const std
} else {
m_open = false;
throw std::runtime_error("[oatpp::orm::Transaction::Transaction()]: "
"Error. Can't begin transaction - " + res->getErrorMessage()->std_str());
"Error. Can't begin transaction - " + *res->getErrorMessage());
}
}

View File

@ -39,9 +39,9 @@ Beautifier::Beautifier(ConsistentOutputStream* outputStream, const oatpp::String
{}
void Beautifier::writeIndent(ConsistentOutputStream* outputStream) {
outputStream->writeSimple(m_newLine->getData(), m_newLine->getSize());
outputStream->writeSimple(m_newLine->data(), m_newLine->size());
for(v_int32 i = 0; i < m_level; i ++ ) {
outputStream->writeSimple(m_indent->getData(), m_indent->getSize());
outputStream->writeSimple(m_indent->data(), m_indent->size());
}
}

View File

@ -29,7 +29,7 @@
namespace oatpp { namespace parser { namespace json{
v_buff_size Utils::calcEscapedStringSize(p_char8 data, v_buff_size size, v_buff_size& safeSize, v_uint32 flags) {
v_buff_size Utils::calcEscapedStringSize(const char* data, v_buff_size size, v_buff_size& safeSize, v_uint32 flags) {
v_buff_size result = 0;
v_buff_size i = 0;
safeSize = size;
@ -94,7 +94,7 @@ v_buff_size Utils::calcEscapedStringSize(p_char8 data, v_buff_size size, v_buff_
return result;
}
v_buff_size Utils::calcUnescapedStringSize(p_char8 data, v_buff_size size, v_int64& errorCode, v_buff_size& errorPosition) {
v_buff_size Utils::calcUnescapedStringSize(const char* data, v_buff_size size, v_int64& errorCode, v_buff_size& errorPosition) {
errorCode = 0;
v_buff_size result = 0;
v_buff_size i = 0;
@ -189,7 +189,7 @@ v_buff_size Utils::calcUnescapedStringSize(p_char8 data, v_buff_size size, v_int
return result;
}
v_buff_size Utils::escapeUtf8Char(p_char8 sequence, p_char8 buffer){
v_buff_size Utils::escapeUtf8Char(const char* sequence, p_char8 buffer){
v_buff_size length;
v_int32 code = oatpp::encoding::Unicode::encodeUtf8Char(sequence, length);
if(code < 0x00010000) {
@ -216,15 +216,15 @@ v_buff_size Utils::escapeUtf8Char(p_char8 sequence, p_char8 buffer){
return 11;
}
}
oatpp::String Utils::escapeString(p_char8 data, v_buff_size size, bool copyAsOwnData, v_uint32 flags) {
oatpp::String Utils::escapeString(const char* data, v_buff_size size, v_uint32 flags) {
v_buff_size safeSize;
v_buff_size escapedSize = calcEscapedStringSize(data, size, safeSize, flags);
if(escapedSize == size) {
return String((const char*)data, size, copyAsOwnData);
return String((const char*)data, size);
}
auto result = String(escapedSize);
p_char8 resultData = result->getData();
p_char8 resultData = (p_char8) result->data();
v_buff_size pos = 0;
{
@ -296,7 +296,7 @@ oatpp::String Utils::escapeString(p_char8 data, v_buff_size size, bool copyAsOwn
}
if(size > safeSize){
for(v_buff_size i = pos; i < result->getSize(); i ++){
for(v_buff_size i = pos; i < result->size(); i ++){
resultData[i] = '?';
}
}
@ -304,7 +304,7 @@ oatpp::String Utils::escapeString(p_char8 data, v_buff_size size, bool copyAsOwn
return result;
}
void Utils::unescapeStringToBuffer(p_char8 data, v_buff_size size, p_char8 resultData){
void Utils::unescapeStringToBuffer(const char* data, v_buff_size size, p_char8 resultData){
v_buff_size i = 0;
v_buff_size pos = 0;
@ -360,7 +360,7 @@ void Utils::unescapeStringToBuffer(p_char8 data, v_buff_size size, p_char8 resul
}
oatpp::String Utils::unescapeString(p_char8 data, v_buff_size size, v_int64& errorCode, v_buff_size& errorPosition) {
oatpp::String Utils::unescapeString(const char* data, v_buff_size size, v_int64& errorCode, v_buff_size& errorPosition) {
v_buff_size unescapedSize = calcUnescapedStringSize(data, size, errorCode, errorPosition);
if(errorCode != 0){
@ -368,15 +368,15 @@ oatpp::String Utils::unescapeString(p_char8 data, v_buff_size size, v_int64& err
}
auto result = String(unescapedSize);
if(unescapedSize == size) {
std::memcpy(result->getData(), data, size);
std::memcpy((void*) result->data(), data, size);
} else {
unescapeStringToBuffer(data, size, result->getData());
unescapeStringToBuffer(data, size, (p_char8) result->data());
}
return result;
}
std::string Utils::unescapeStringToStdString(p_char8 data, v_buff_size size, v_int64& errorCode, v_buff_size& errorPosition){
std::string Utils::unescapeStringToStdString(const char* data, v_buff_size size, v_int64& errorCode, v_buff_size& errorPosition){
v_buff_size unescapedSize = calcUnescapedStringSize(data, size, errorCode, errorPosition);
if(errorCode != 0){
@ -393,11 +393,11 @@ std::string Utils::unescapeStringToStdString(p_char8 data, v_buff_size size, v_i
}
p_char8 Utils::preparseString(ParsingCaret& caret, v_buff_size& size){
const char* Utils::preparseString(ParsingCaret& caret, v_buff_size& size){
if(caret.canContinueAtChar('"', 1)){
const p_char8 data = caret.getData();
const char* data = caret.getData();
v_buff_size pos = caret.getPosition();
v_buff_size pos0 = pos;
v_buff_size length = caret.getDataSize();
@ -426,7 +426,7 @@ p_char8 Utils::preparseString(ParsingCaret& caret, v_buff_size& size){
oatpp::String Utils::parseString(ParsingCaret& caret) {
v_buff_size size;
p_char8 data = preparseString(caret, size);
const char* data = preparseString(caret, size);
if(data != nullptr) {
@ -453,7 +453,7 @@ oatpp::String Utils::parseString(ParsingCaret& caret) {
std::string Utils::parseStringToStdString(ParsingCaret& caret){
v_buff_size size;
p_char8 data = preparseString(caret, size);
auto data = preparseString(caret, size);
if(data != nullptr) {

View File

@ -65,11 +65,11 @@ public:
typedef oatpp::String String;
typedef oatpp::parser::Caret ParsingCaret;
private:
static v_buff_size escapeUtf8Char(p_char8 sequence, p_char8 buffer);
static v_buff_size calcEscapedStringSize(p_char8 data, v_buff_size size, v_buff_size& safeSize, v_uint32 flags);
static v_buff_size calcUnescapedStringSize(p_char8 data, v_buff_size size, v_int64& errorCode, v_buff_size& errorPosition);
static void unescapeStringToBuffer(p_char8 data, v_buff_size size, p_char8 resultData);
static p_char8 preparseString(ParsingCaret& caret, v_buff_size& size);
static v_buff_size escapeUtf8Char(const char* sequence, p_char8 buffer);
static v_buff_size calcEscapedStringSize(const char* data, v_buff_size size, v_buff_size& safeSize, v_uint32 flags);
static v_buff_size calcUnescapedStringSize(const char* data, v_buff_size size, v_int64& errorCode, v_buff_size& errorPosition);
static void unescapeStringToBuffer(const char* data, v_buff_size size, p_char8 resultData);
static const char* preparseString(ParsingCaret& caret, v_buff_size& size);
public:
/**
@ -77,11 +77,10 @@ public:
* *Note:* if(copyAsOwnData == false && escapedString == initialString) then result string will point to initial data.
* @param data - pointer to string to escape.
* @param size - data size.
* @param copyAsOwnData - see &id:oatpp::base::StrBuffer::StrBuffer;.
* @param flags - escape flags.
* @return - &id:oatpp::String;.
*/
static String escapeString(p_char8 data, v_buff_size size, bool copyAsOwnData = true, v_uint32 flags = FLAG_ESCAPE_ALL);
static String escapeString(const char* data, v_buff_size size, v_uint32 flags = FLAG_ESCAPE_ALL);
/**
* Unescape string as for json standard.
@ -97,7 +96,7 @@ public:
* @param errorPosition - out parameter. Error position in data.
* @return - &id:oatpp::String;.
*/
static String unescapeString(p_char8 data, v_buff_size size, v_int64& errorCode, v_buff_size& errorPosition);
static String unescapeString(const char* data, v_buff_size size, v_int64& errorCode, v_buff_size& errorPosition);
/**
* Same as &l:Utils::unescapeString (); but return `std::string`.
@ -113,7 +112,7 @@ public:
* @param errorPosition - out parameter. Error position in data.
* @return - &id:oatpp::String;.
*/
static std::string unescapeStringToStdString(p_char8 data, v_buff_size size, v_int64& errorCode, v_buff_size& errorPosition);
static std::string unescapeStringToStdString(const char* data, v_buff_size size, v_int64& errorCode, v_buff_size& errorPosition);
/**
* Parse string enclosed in `"<string>"`.

View File

@ -76,7 +76,7 @@ void Deserializer::setDeserializerMethod(const data::mapping::type::ClassId& cla
void Deserializer::skipScope(oatpp::parser::Caret& caret, v_char8 charOpen, v_char8 charClose){
p_char8 data = caret.getData();
const char* data = caret.getData();
v_buff_size size = caret.getDataSize();
v_buff_size pos = caret.getPosition();
v_int32 scopeCounter = 0;
@ -109,7 +109,7 @@ void Deserializer::skipScope(oatpp::parser::Caret& caret, v_char8 charOpen, v_ch
}
void Deserializer::skipString(oatpp::parser::Caret& caret){
p_char8 data = caret.getData();
const char* data = caret.getData();
v_buff_size size = caret.getDataSize();
v_buff_size pos = caret.getPosition();
v_int32 scopeCounter = 0;
@ -129,7 +129,7 @@ void Deserializer::skipString(oatpp::parser::Caret& caret){
}
void Deserializer::skipToken(oatpp::parser::Caret& caret){
p_char8 data = caret.getData();
const char* data = caret.getData();
v_buff_size size = caret.getDataSize();
v_buff_size pos = caret.getPosition();
while(pos < size){

View File

@ -75,20 +75,16 @@ void Serializer::setSerializerMethod(const data::mapping::type::ClassId& classId
}
}
void Serializer::serializeString(data::stream::ConsistentOutputStream* stream,
p_char8 data,
v_buff_size size,
v_uint32 escapeFlags)
{
auto encodedValue = Utils::escapeString(data, size, false, escapeFlags);
void Serializer::serializeString(data::stream::ConsistentOutputStream* stream, const char* data, v_buff_size size, v_uint32 escapeFlags) {
auto encodedValue = Utils::escapeString(data, size, escapeFlags);
stream->writeCharSimple('\"');
stream->writeSimple(encodedValue);
stream->writeCharSimple('\"');
}
void Serializer::serializeString(Serializer* serializer,
data::stream::ConsistentOutputStream* stream,
const oatpp::Void& polymorph)
data::stream::ConsistentOutputStream* stream,
const oatpp::Void& polymorph)
{
if(!polymorph) {
@ -96,9 +92,9 @@ void Serializer::serializeString(Serializer* serializer,
return;
}
auto str = static_cast<oatpp::base::StrBuffer*>(polymorph.get());
auto str = static_cast<std::string*>(polymorph.get());
serializeString(stream, str->getData(), str->getSize(), serializer->m_config->escapeFlags);
serializeString(stream, str->data(), str->size(), serializer->m_config->escapeFlags);
}
@ -163,7 +159,7 @@ void Serializer::serializeObject(Serializer* serializer,
auto value = field->get(object);
if(value || serializer->m_config->includeNullFields) {
(first) ? first = false : stream->writeSimple(",", 1);
serializeString(stream, (p_char8)field->name, std::strlen(field->name), serializer->m_config->escapeFlags);
serializeString(stream, field->name, std::strlen(field->name), serializer->m_config->escapeFlags);
stream->writeSimple(":", 1);
serializer->serialize(stream, value);
}

View File

@ -164,7 +164,7 @@ private:
if(value || serializer->m_config->includeNullFields) {
(first) ? first = false : stream->writeSimple(",", 1);
const auto& key = pair.first;
serializeString(stream, key->getData(), key->getSize(), serializer->m_config->escapeFlags);
serializeString(stream, key->data(), key->size(), serializer->m_config->escapeFlags);
stream->writeSimple(":", 1);
serializer->serialize(stream, value);
}
@ -173,9 +173,9 @@ private:
stream->writeCharSimple('}');
}
static void serializeString(oatpp::data::stream::ConsistentOutputStream* stream,
p_char8 data,
const char* data,
v_buff_size size,
v_uint32 escapeFlags);

View File

@ -91,7 +91,7 @@ oatpp::String ApiClient::formatPath(const StringTemplate& pathTemplate,
bool first = !extra->hasQueryParams;
for(const auto& q : queryParams) {
oatpp::String value = q.second;
if(value && value->getSize() > 0) {
if(value && value->size() > 0) {
if (first) {
stream.writeCharSimple('?');
first = false;

View File

@ -225,11 +225,11 @@ public:
(void) parameter;
OATPP_LOGE("[oatpp::web::client::ApiClient::TypeInterpretation::toString()]",
"Error. No conversion from '%s' to '%s' is defined.", typeName->getData(), "oatpp::String");
"Error. No conversion from '%s' to '%s' is defined.", typeName->c_str(), "oatpp::String");
throw std::runtime_error(
"[oatpp::web::client::ApiClient::TypeInterpretation::toString()]: Error. "
"No conversion from '" + typeName->std_str() + "' to 'oatpp::String' is defined. "
"No conversion from '" + *typeName + "' to 'oatpp::String' is defined. "
"Please define type conversion."
);

View File

@ -28,6 +28,7 @@
#include "oatpp/web/protocol/http/outgoing/Request.hpp"
#include "oatpp/network/tcp/Connection.hpp"
#include "oatpp/core/data/stream/StreamBufferedProxy.hpp"
#if defined(WIN32) || defined(_WIN32)
@ -120,7 +121,7 @@ HttpRequestExecutor::executeOnce(const String& method,
request->putHeaderIfNotExists_Unsafe(oatpp::web::protocol::http::Header::HOST, m_connectionProvider->getProperty("host"));
request->putHeaderIfNotExists_Unsafe(oatpp::web::protocol::http::Header::CONNECTION, oatpp::web::protocol::http::Header::Value::CONNECTION_KEEP_ALIVE);
oatpp::data::share::MemoryLabel buffer(oatpp::base::StrBuffer::createShared(oatpp::data::buffer::IOBuffer::BUFFER_SIZE));
oatpp::data::share::MemoryLabel buffer(std::make_shared<std::string>(oatpp::data::buffer::IOBuffer::BUFFER_SIZE, 0));
oatpp::data::stream::OutputStreamBufferedProxy upStream(connection, buffer);
request->send(&upStream);
@ -201,7 +202,7 @@ HttpRequestExecutor::executeOnceAsync(const String& method,
, m_body(body)
, m_bodyDecoder(bodyDecoder)
, m_connectionHandle(connectionHandle)
, m_buffer(base::StrBuffer::createShared(oatpp::data::buffer::IOBuffer::BUFFER_SIZE))
, m_buffer(std::make_shared<std::string>(oatpp::data::buffer::IOBuffer::BUFFER_SIZE, 0))
, m_headersReader(m_buffer, 4096)
{}

View File

@ -48,7 +48,7 @@ void InMemoryPartReader::onNewPart(const std::shared_ptr<Part>& part) {
}
void InMemoryPartReader::onPartData(const std::shared_ptr<Part>& part, p_char8 data, oatpp::v_io_size size) {
void InMemoryPartReader::onPartData(const std::shared_ptr<Part>& part, const char* data, oatpp::v_io_size size) {
auto tag = part->getTagObject();
if(!tag) {
@ -75,8 +75,8 @@ void InMemoryPartReader::onPartData(const std::shared_ptr<Part>& part, p_char8 d
auto fullData = buffer->toString();
buffer->clear();
part->clearTag();
auto stream = std::make_shared<data::stream::BufferInputStream>(fullData.getPtr(), fullData->getData(), fullData->getSize());
part->setDataInfo(stream, fullData, fullData->getSize());
auto stream = std::make_shared<data::stream::BufferInputStream>(fullData.getPtr(), fullData->data(), fullData->size());
part->setDataInfo(stream, fullData, fullData->size());
}
}
@ -103,7 +103,7 @@ async::CoroutineStarter AsyncInMemoryPartReader::onNewPartAsync(const std::share
}
async::CoroutineStarter AsyncInMemoryPartReader::onPartDataAsync(const std::shared_ptr<Part>& part, p_char8 data, oatpp::v_io_size size) {
async::CoroutineStarter AsyncInMemoryPartReader::onPartDataAsync(const std::shared_ptr<Part>& part, const char* data, oatpp::v_io_size size) {
auto tag = part->getTagObject();
if(!tag) {
@ -130,8 +130,8 @@ async::CoroutineStarter AsyncInMemoryPartReader::onPartDataAsync(const std::shar
auto fullData = buffer->toString();
buffer->clear();
part->clearTag();
auto stream = std::make_shared<data::stream::BufferInputStream>(fullData.getPtr(), fullData->getData(), fullData->getSize());
part->setDataInfo(stream, fullData, fullData->getSize());
auto stream = std::make_shared<data::stream::BufferInputStream>(fullData.getPtr(), fullData->data(), fullData->size());
part->setDataInfo(stream, fullData, fullData->size());
}
return nullptr;
}

View File

@ -58,7 +58,7 @@ public:
* @param data - pointer to buffer containing chunk data.
* @param size - size of the buffer.
*/
void onPartData(const std::shared_ptr<Part>& part, p_char8 data, oatpp::v_io_size size) override;
void onPartData(const std::shared_ptr<Part>& part, const char* data, oatpp::v_io_size size) override;
};
@ -93,7 +93,7 @@ public:
* @param size - size of the buffer.
* @return - &id:oatpp::async::CoroutineStarter;.
*/
async::CoroutineStarter onPartDataAsync(const std::shared_ptr<Part>& part, p_char8 data, oatpp::v_io_size size) override;
async::CoroutineStarter onPartDataAsync(const std::shared_ptr<Part>& part, const char* data, oatpp::v_io_size size) override;
};

View File

@ -34,7 +34,7 @@ namespace oatpp { namespace web { namespace mime { namespace multipart {
* Typedef for headers map. Headers map key is case-insensitive.
* For more info see &id:oatpp::data::share::LazyStringMap;.
*/
typedef oatpp::data::share::LazyStringMultimap<oatpp::data::share::StringKeyLabelCI_FAST> Headers;
typedef oatpp::data::share::LazyStringMultimap<oatpp::data::share::StringKeyLabelCI> Headers;
/**
* Abstract Multipart.

View File

@ -88,15 +88,15 @@ const Part::Headers& Part::getHeaders() const {
return m_headers;
}
oatpp::String Part::getHeader(const oatpp::data::share::StringKeyLabelCI_FAST& headerName) const {
oatpp::String Part::getHeader(const oatpp::data::share::StringKeyLabelCI& headerName) const {
return m_headers.get(headerName);
}
void Part::putHeader(const oatpp::data::share::StringKeyLabelCI_FAST& key, const oatpp::data::share::StringKeyLabel& value) {
void Part::putHeader(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value) {
m_headers.put(key, value);
}
bool Part::putHeaderIfNotExists(const oatpp::data::share::StringKeyLabelCI_FAST& key, const oatpp::data::share::StringKeyLabel& value) {
bool Part::putHeaderIfNotExists(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value) {
return m_headers.putIfNotExists(key, value);
}

View File

@ -39,7 +39,7 @@ public:
* Typedef for headers map. Headers map key is case-insensitive.
* For more info see &id:oatpp::data::share::LazyStringMap;.
*/
typedef oatpp::data::share::LazyStringMultimap<oatpp::data::share::StringKeyLabelCI_FAST> Headers;
typedef oatpp::data::share::LazyStringMultimap<oatpp::data::share::StringKeyLabelCI> Headers;
private:
oatpp::String m_name;
oatpp::String m_filename;
@ -114,22 +114,22 @@ public:
* @param headerName
* @return header value
*/
oatpp::String getHeader(const oatpp::data::share::StringKeyLabelCI_FAST& headerName) const;
oatpp::String getHeader(const oatpp::data::share::StringKeyLabelCI& headerName) const;
/**
* Add http header.
* @param key - &id:oatpp::data::share::StringKeyLabelCI_FAST;.
* @param key - &id:oatpp::data::share::StringKeyLabelCI;.
* @param value - &id:oatpp::data::share::StringKeyLabel;.
*/
void putHeader(const oatpp::data::share::StringKeyLabelCI_FAST& key, const oatpp::data::share::StringKeyLabel& value);
void putHeader(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value);
/**
* Add http header if not already exists.
* @param key - &id:oatpp::data::share::StringKeyLabelCI_FAST;.
* @param key - &id:oatpp::data::share::StringKeyLabelCI;.
* @param value - &id:oatpp::data::share::StringKeyLabel;.
* @return - `true` if header was added.
*/
bool putHeaderIfNotExists(const oatpp::data::share::StringKeyLabelCI_FAST& key, const oatpp::data::share::StringKeyLabel& value);
bool putHeaderIfNotExists(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value);
/**
* Get input stream of the part data.

View File

@ -57,7 +57,7 @@ void PartsParser::onPartHeaders(const Headers& partHeaders) {
}
void PartsParser::onPartData(p_char8 data, v_buff_size size) {
void PartsParser::onPartData(const char* data, v_buff_size size) {
if(size > 0) {
if(m_currReader) {
m_currReader->onPartData(m_currPart, data, size);
@ -147,7 +147,7 @@ async::CoroutineStarter AsyncPartsParser::onPartDone(const std::shared_ptr<Part>
}
async::CoroutineStarter AsyncPartsParser::onPartDataAsync(p_char8 data, v_buff_size size) {
async::CoroutineStarter AsyncPartsParser::onPartDataAsync(const char* data, v_buff_size size) {
if(size > 0) {
if(m_currReader) {
return m_currReader->onPartDataAsync(m_currPart, data, size);

View File

@ -56,7 +56,7 @@ public:
* @param data - pointer to buffer containing chunk data.
* @param size - size of the buffer.
*/
virtual void onPartData(const std::shared_ptr<Part>& part, p_char8 data, oatpp::v_io_size size) = 0;
virtual void onPartData(const std::shared_ptr<Part>& part, const char* data, oatpp::v_io_size size) = 0;
};
@ -86,7 +86,7 @@ public:
* @param size - size of the buffer.
* @return - &id:oatpp::async::CoroutineStarter;.
*/
virtual async::CoroutineStarter onPartDataAsync(const std::shared_ptr<Part>& part, p_char8 data, oatpp::v_io_size size) = 0;
virtual async::CoroutineStarter onPartDataAsync(const std::shared_ptr<Part>& part, const char* data, oatpp::v_io_size size) = 0;
};
@ -121,7 +121,7 @@ public:
void onPartHeaders(const Headers& partHeaders) override;
void onPartData(p_char8 data, v_buff_size size) override;
void onPartData(const char* data, v_buff_size size) override;
void setPartReader(const oatpp::String& partName, const std::shared_ptr<PartReader>& reader);
@ -162,7 +162,7 @@ public:
async::CoroutineStarter onPartHeadersAsync(const Headers& partHeaders) override;
async::CoroutineStarter onPartDataAsync(p_char8 data, v_buff_size size) override;
async::CoroutineStarter onPartDataAsync(const char* data, v_buff_size size) override;
void setPartReader(const oatpp::String& partName, const std::shared_ptr<AsyncPartReader>& reader);

View File

@ -40,7 +40,7 @@ void StatefulParser::ListenerCall::setOnHeadersCall() {
size = 0;
}
void StatefulParser::ListenerCall::setOnDataCall(p_char8 pData, v_buff_size pSize) {
void StatefulParser::ListenerCall::setOnDataCall(const char* pData, v_buff_size pSize) {
callType = CALL_ON_DATA;
data = pData;
size = pSize;
@ -134,18 +134,18 @@ void StatefulParser::parseHeaders(Headers& headers) {
StatefulParser::ListenerCall StatefulParser::parseNext_Boundary(data::buffer::InlineWriteData& inlineData) {
ListenerCall result;
p_char8 data = (p_char8)inlineData.currBufferPtr;
auto data = inlineData.currBufferPtr;
auto size = inlineData.bytesLeft;
p_char8 sampleData = m_nextBoundarySample->getData();
v_io_size sampleSize = m_nextBoundarySample->getSize();
auto sampleData = m_nextBoundarySample->data();
v_io_size sampleSize = m_nextBoundarySample->size();
if (m_currPartIndex == 0) {
sampleData = m_firstBoundarySample->getData();
sampleSize = m_firstBoundarySample->getSize();
sampleData = m_firstBoundarySample->data();
sampleSize = m_firstBoundarySample->size();
} else {
sampleData = m_nextBoundarySample->getData();
sampleSize = m_nextBoundarySample->getSize();
sampleData = m_nextBoundarySample->data();
sampleSize = m_nextBoundarySample->size();
}
v_io_size checkSize = sampleSize - m_currBoundaryCharIndex;
@ -153,7 +153,7 @@ StatefulParser::ListenerCall StatefulParser::parseNext_Boundary(data::buffer::In
checkSize = size;
}
parser::Caret caret(data, size);
parser::Caret caret((const char*)data, size);
if(caret.isAtText(&sampleData[m_currBoundaryCharIndex], checkSize, true)) {
@ -280,7 +280,7 @@ StatefulParser::ListenerCall StatefulParser::parseNext_Data(data::buffer::Inline
ListenerCall result;
p_char8 data = (p_char8) inlineData.currBufferPtr;
const char* data = (const char*) inlineData.currBufferPtr;
auto size = inlineData.bytesLeft;
parser::Caret caret(data, size);

View File

@ -51,7 +51,7 @@ private:
* Typedef for headers map. Headers map key is case-insensitive.
* For more info see &id:oatpp::data::share::LazyStringMap;.
*/
typedef oatpp::data::share::LazyStringMultimap<oatpp::data::share::StringKeyLabelCI_FAST> Headers;
typedef oatpp::data::share::LazyStringMultimap<oatpp::data::share::StringKeyLabelCI> Headers;
public:
/**
@ -63,7 +63,7 @@ public:
* Typedef for headers map. Headers map key is case-insensitive.
* For more info see &id:oatpp::data::share::LazyStringMap;.
*/
typedef oatpp::data::share::LazyStringMultimap<oatpp::data::share::StringKeyLabelCI_FAST> Headers;
typedef oatpp::data::share::LazyStringMultimap<oatpp::data::share::StringKeyLabelCI> Headers;
public:
/**
@ -85,7 +85,7 @@ public:
* @param data - pointer to data.
* @param size - size of the data in bytes.
*/
virtual void onPartData(p_char8 data, v_buff_size size) = 0;
virtual void onPartData(const char* data, v_buff_size size) = 0;
};
@ -100,7 +100,7 @@ public:
* Typedef for headers map. Headers map key is case-insensitive.
* For more info see &id:oatpp::data::share::LazyStringMap;.
*/
typedef oatpp::data::share::LazyStringMultimap<oatpp::data::share::StringKeyLabelCI_FAST> Headers;
typedef oatpp::data::share::LazyStringMultimap<oatpp::data::share::StringKeyLabelCI> Headers;
public:
/**
@ -122,7 +122,7 @@ public:
* @param data - pointer to data.
* @param size - size of the data in bytes.
*/
virtual async::CoroutineStarter onPartDataAsync(p_char8 data, v_buff_size size) = 0;
virtual async::CoroutineStarter onPartDataAsync(const char* data, v_buff_size size) = 0;
};
@ -144,11 +144,11 @@ private:
{}
v_int32 callType;
p_char8 data;
const char* data;
v_io_size size;
void setOnHeadersCall();
void setOnDataCall(p_char8 pData, v_buff_size pSize);
void setOnDataCall(const char* pData, v_buff_size pSize);
void call(StatefulParser* parser);
async::CoroutineStarter callAsync(StatefulParser* parser);

View File

@ -53,7 +53,7 @@ void StreamPartReader::onNewPart(const std::shared_ptr<Part>& part) {
}
void StreamPartReader::onPartData(const std::shared_ptr<Part>& part, p_char8 data, oatpp::v_io_size size) {
void StreamPartReader::onPartData(const std::shared_ptr<Part>& part, const char* data, oatpp::v_io_size size) {
auto tag = part->getTagObject();
if(!tag) {
@ -142,7 +142,7 @@ async::CoroutineStarter AsyncStreamPartReader::onNewPartAsync(const std::shared_
}
async::CoroutineStarter AsyncStreamPartReader::onPartDataAsync(const std::shared_ptr<Part>& part, p_char8 data, oatpp::v_io_size size) {
async::CoroutineStarter AsyncStreamPartReader::onPartDataAsync(const std::shared_ptr<Part>& part, const char* data, oatpp::v_io_size size) {
auto tag = part->getTagObject();
if(!tag) {

View File

@ -151,7 +151,7 @@ public:
* @param data - pointer to buffer containing chunk data.
* @param size - size of the buffer.
*/
void onPartData(const std::shared_ptr<Part>& part, p_char8 data, oatpp::v_io_size size) override;
void onPartData(const std::shared_ptr<Part>& part, const char* data, oatpp::v_io_size size) override;
};
@ -199,7 +199,7 @@ public:
* @param size - size of the buffer.
* @return - &id:oatpp::async::CoroutineStarter;.
*/
async::CoroutineStarter onPartDataAsync(const std::shared_ptr<Part>& part, p_char8 data, oatpp::v_io_size size) override;
async::CoroutineStarter onPartDataAsync(const std::shared_ptr<Part>& part, const char* data, oatpp::v_io_size size) override;
};

View File

@ -27,7 +27,7 @@
namespace oatpp { namespace web { namespace protocol {
CommunicationError::CommunicationError(oatpp::v_io_size ioStatus, const oatpp::String& message)
:std::runtime_error(message->std_str())
:std::runtime_error(*message)
, m_ioStatus(ioStatus)
, m_message(message)
{}

View File

@ -135,7 +135,7 @@ const char* const ContentRange::UNIT_BYTES = "bytes";
oatpp::String Range::toString() const {
oatpp::data::stream::ChunkedBuffer stream;
stream.writeSimple(units->getData(), units->getSize());
stream.writeSimple(units->data(), units->size());
stream.writeSimple("=", 1);
stream.writeAsString(start);
stream.writeSimple("-", 1);
@ -169,7 +169,7 @@ Range Range::parse(oatpp::parser::Caret& caret) {
auto start = oatpp::utils::conversion::strToInt64((const char*) startLabel.getData());
auto end = oatpp::utils::conversion::strToInt64((const char*) endLabel.getData());
return Range(unitsLabel.toString(true), start, end);
return Range(unitsLabel.toString(), start, end);
}
@ -180,7 +180,7 @@ Range Range::parse(const oatpp::String& str) {
oatpp::String ContentRange::toString() const {
oatpp::data::stream::ChunkedBuffer stream;
stream.writeSimple(units->getData(), units->getSize());
stream.writeSimple(units->data(), units->size());
stream.writeSimple(" ", 1);
stream.writeAsString(start);
stream.writeSimple("-", 1);
@ -236,7 +236,7 @@ ContentRange ContentRange::parse(oatpp::parser::Caret& caret) {
size = oatpp::utils::conversion::strToInt64((const char*) sizeLabel.getData());
}
return ContentRange(unitsLabel.toString(true), start, end, size, isSizeKnown);
return ContentRange(unitsLabel.toString(), start, end, size, isSizeKnown);
}
@ -257,25 +257,25 @@ oatpp::String HeaderValueData::getTitleParamValue(const data::share::StringKeyLa
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Parser
oatpp::data::share::StringKeyLabelCI_FAST Parser::parseHeaderNameLabel(const std::shared_ptr<oatpp::base::StrBuffer>& headersText,
oatpp::parser::Caret& caret) {
p_char8 data = caret.getData();
oatpp::data::share::StringKeyLabelCI Parser::parseHeaderNameLabel(const std::shared_ptr<std::string>& headersText,
oatpp::parser::Caret& caret) {
const char* data = caret.getData();
for(v_buff_size i = caret.getPosition(); i < caret.getDataSize(); i++) {
v_char8 a = data[i];
if(a == ':' || a == ' '){
oatpp::data::share::StringKeyLabelCI_FAST label(headersText, &data[caret.getPosition()], i - caret.getPosition());
oatpp::data::share::StringKeyLabelCI label(headersText, &data[caret.getPosition()], i - caret.getPosition());
caret.setPosition(i);
return label;
}
}
return oatpp::data::share::StringKeyLabelCI_FAST(nullptr, nullptr, 0);
return oatpp::data::share::StringKeyLabelCI(nullptr, nullptr, 0);
}
void Parser::parseRequestStartingLine(RequestStartingLine& line,
const std::shared_ptr<oatpp::base::StrBuffer>& headersText,
oatpp::parser::Caret& caret,
Status& error) {
const std::shared_ptr<std::string>& headersText,
oatpp::parser::Caret& caret,
Status& error) {
auto methodLabel = caret.putLabel();
if(caret.findChar(' ')){
@ -307,9 +307,9 @@ void Parser::parseRequestStartingLine(RequestStartingLine& line,
}
void Parser::parseResponseStartingLine(ResponseStartingLine& line,
const std::shared_ptr<oatpp::base::StrBuffer>& headersText,
oatpp::parser::Caret& caret,
Status& error) {
const std::shared_ptr<std::string>& headersText,
oatpp::parser::Caret& caret,
Status& error) {
auto protocolLabel = caret.putLabel();
if(caret.findChar(' ')){
@ -334,7 +334,7 @@ void Parser::parseResponseStartingLine(ResponseStartingLine& line,
}
void Parser::parseOneHeader(Headers& headers,
const std::shared_ptr<oatpp::base::StrBuffer>& headersText,
const std::shared_ptr<std::string>& headersText,
oatpp::parser::Caret& caret,
Status& error)
{
@ -358,7 +358,7 @@ void Parser::parseOneHeader(Headers& headers,
}
void Parser::parseHeaders(Headers& headers,
const std::shared_ptr<oatpp::base::StrBuffer>& headersText,
const std::shared_ptr<std::string>& headersText,
oatpp::parser::Caret& caret,
Status& error)
{
@ -374,12 +374,12 @@ void Parser::parseHeaders(Headers& headers,
}
void Parser::parseHeaderValueData(HeaderValueData& data, const oatpp::data::share::StringKeyLabel& headerValue, v_char8 separator) {
void Parser::parseHeaderValueData(HeaderValueData& data, const oatpp::data::share::StringKeyLabel& headerValue, char separator) {
oatpp::parser::Caret caret(headerValue.getData(), headerValue.getSize());
oatpp::parser::Caret caret((const char*) headerValue.getData(), headerValue.getSize());
v_char8 charSet[5] = {' ', '=', separator, '\r', '\n'};
v_char8 charSet2[4] = {' ', separator, '\r', '\n'};
const char charSet[5] = {' ', '=', separator, '\r', '\n'};
const char charSet2[4] = {' ', separator, '\r', '\n'};
while (caret.canContinue()) {
@ -410,7 +410,7 @@ void Parser::parseHeaderValueData(HeaderValueData& data, const oatpp::data::shar
data::share::StringKeyLabelCI(headerValue.getMemoryHandle(), label.getData(), label.getSize()));
}
if (caret.isAtCharFromSet((p_char8) "\r\n", 2)) {
if (caret.isAtCharFromSet("\r\n", 2)) {
break;
} else if (caret.isAtChar(separator)) {
caret.inc();

View File

@ -42,7 +42,7 @@ namespace oatpp { namespace web { namespace protocol { namespace http {
* Typedef for headers map. Headers map key is case-insensitive.
* For more info see &id:oatpp::data::share::LazyStringMap;.
*/
typedef oatpp::data::share::LazyStringMultimap<oatpp::data::share::StringKeyLabelCI_FAST> Headers;
typedef oatpp::data::share::LazyStringMultimap<oatpp::data::share::StringKeyLabelCI> Headers;
/**
* Typedef for query parameters map.
@ -644,33 +644,33 @@ struct HeaderValueData {
*/
class Parser {
private:
static oatpp::data::share::StringKeyLabelCI_FAST parseHeaderNameLabel(const std::shared_ptr<oatpp::base::StrBuffer>& headersText,
oatpp::parser::Caret& caret);
static oatpp::data::share::StringKeyLabelCI parseHeaderNameLabel(const std::shared_ptr<std::string>& headersText,
oatpp::parser::Caret& caret);
public:
/**
* Parse &l:RequestStartingLine;.
* @param line - &l:RequestStartingLine;. Values will be set to line's fields.
* @param headersText - `std::shared_ptr` to &id:oatpp::base::StrBuffer; needed as a "memory handle" for
* @param headersText - `std::shared_ptr` to `std::string` needed as a "memory handle" for
* &l:RequestStartingLine; fields. See &id:oatpp::data::share::MemoryLabel;.
* @param caret - &id:oatpp::parser::Caret;.
* @param error - out parameter &l:Status;.
*/
static void parseRequestStartingLine(RequestStartingLine& line,
const std::shared_ptr<oatpp::base::StrBuffer>& headersText,
const std::shared_ptr<std::string>& headersText,
oatpp::parser::Caret& caret,
Status& error);
/**
* Parse &l:ResponseStartingLine;.
* @param line - &l:ResponseStartingLine;. Values will be set to line's fields.
* @param headersText - `std::shared_ptr` to &id:oatpp::base::StrBuffer; needed as a "memory handle" for
* @param headersText - `std::shared_ptr` to `std::string` needed as a "memory handle" for
* &l:ResponseStartingLine; fields. See &id:oatpp::data::share::MemoryLabel;.
* @param caret - &id:oatpp::parser::Caret;.
* @param error - out parameter &l:Status;.
*/
static void parseResponseStartingLine(ResponseStartingLine& line,
const std::shared_ptr<oatpp::base::StrBuffer>& headersText,
const std::shared_ptr<std::string>& headersText,
oatpp::parser::Caret& caret,
Status& error);
@ -678,26 +678,26 @@ public:
* Parse one header line. Example of the header line:
* `"Content-Type: application/json\r\n"`.
* @param headers - &l:Headers; map to put parsed header to.
* @param headersText - `std::shared_ptr` to &id:oatpp::base::StrBuffer; needed as a "memory handle" for
* @param headersText - `std::shared_ptr` to `std::string` needed as a "memory handle" for
* &l:Headers; values. See &id:oatpp::data::share::MemoryLabel;.
* @param caret - &id:oatpp::parser::Caret;.
* @param error - out parameter &l:Status;.
*/
static void parseOneHeader(Headers& headers,
const std::shared_ptr<oatpp::base::StrBuffer>& headersText,
const std::shared_ptr<std::string>& headersText,
oatpp::parser::Caret& caret,
Status& error);
/**
* Parse HTTP headers to &l:Headers; map.
* @param headers - &l:Headers; map to put parsed headers to.
* @param headersText - `std::shared_ptr` to &id:oatpp::base::StrBuffer; needed as a "memory handle" for
* @param headersText - `std::shared_ptr` to `std::string` needed as a "memory handle" for
* &l:Headers; values. See &id:oatpp::data::share::MemoryLabel;.
* @param caret - &id:oatpp::parser::Caret;.
* @param error - out parameter &l:Status;.
*/
static void parseHeaders(Headers& headers,
const std::shared_ptr<oatpp::base::StrBuffer>& headersText,
const std::shared_ptr<std::string>& headersText,
oatpp::parser::Caret& caret,
Status& error);
@ -707,7 +707,7 @@ public:
* @param headerValue - header value string.
* @param separator - subvalues separator.
*/
static void parseHeaderValueData(HeaderValueData& data, const oatpp::data::share::StringKeyLabel& headerValue, v_char8 separator);
static void parseHeaderValueData(HeaderValueData& data, const oatpp::data::share::StringKeyLabel& headerValue, char separator);
};

View File

@ -69,7 +69,7 @@ v_int32 EncoderChunked::iterate(data::buffer::InlineReadData& dataIn, data::buff
stream.write("\r\n", 2, action);
m_chunkHeader = stream.toString();
dataOut.set(m_chunkHeader->getData(), m_chunkHeader->getSize());
dataOut.set((p_char8) m_chunkHeader->data(), m_chunkHeader->size());
m_firstChunk = false;
m_writeChunkHeader = false;
@ -96,7 +96,7 @@ v_int32 EncoderChunked::iterate(data::buffer::InlineReadData& dataIn, data::buff
stream.write("0\r\n\r\n", 5, action);
m_chunkHeader = stream.toString();
dataOut.set(m_chunkHeader->getData(), m_chunkHeader->getSize());
dataOut.set((p_char8) m_chunkHeader->data(), m_chunkHeader->size());
m_firstChunk = false;
m_writeChunkHeader = false;

View File

@ -101,15 +101,15 @@ bool Request::putHeaderIfNotExists(const oatpp::String& key, const oatpp::String
return m_headers.putIfNotExists(key, value);
}
void Request::putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI_FAST& key, const oatpp::data::share::StringKeyLabel& value) {
void Request::putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value) {
m_headers.put(key, value);
}
bool Request::putHeaderIfNotExists_Unsafe(const oatpp::data::share::StringKeyLabelCI_FAST& key, const oatpp::data::share::StringKeyLabel& value) {
bool Request::putHeaderIfNotExists_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value) {
return m_headers.putIfNotExists(key, value);
}
oatpp::String Request::getHeader(const oatpp::data::share::StringKeyLabelCI_FAST& headerName) const{
oatpp::String Request::getHeader(const oatpp::data::share::StringKeyLabelCI& headerName) const{
return m_headers.get(headerName);
}

View File

@ -156,25 +156,25 @@ public:
/**
* Add http header.
* @param key - &id:oatpp::data::share::StringKeyLabelCI_FAST;.
* @param key - &id:oatpp::data::share::StringKeyLabelCI;.
* @param value - &id:oatpp::data::share::StringKeyLabel;.
*/
void putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI_FAST& key, const oatpp::data::share::StringKeyLabel& value);
void putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value);
/**
* Add http header if not already exists.
* @param key - &id:oatpp::data::share::StringKeyLabelCI_FAST;.
* @param key - &id:oatpp::data::share::StringKeyLabelCI;.
* @param value - &id:oatpp::data::share::StringKeyLabel;.
* @return - `true` if header was added.
*/
bool putHeaderIfNotExists_Unsafe(const oatpp::data::share::StringKeyLabelCI_FAST& key, const oatpp::data::share::StringKeyLabel& value);
bool putHeaderIfNotExists_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value);
/**
* Get header value
* @param headerName - &id:oatpp::data::share::StringKeyLabelCI_FAST;.
* @param headerName - &id:oatpp::data::share::StringKeyLabelCI;.
* @return - &id:oatpp::String;.
*/
oatpp::String getHeader(const oatpp::data::share::StringKeyLabelCI_FAST& headerName) const;
oatpp::String getHeader(const oatpp::data::share::StringKeyLabelCI& headerName) const;
/**
* Get path variable according to path-pattern

View File

@ -95,7 +95,7 @@ RequestHeadersReader::Result RequestHeadersReader::readHeaders(data::stream::Inp
}
if(error.ioStatus > 0) {
oatpp::parser::Caret caret (m_bufferStream->getData(), m_bufferStream->getCurrentPosition());
oatpp::parser::Caret caret ((const char*) m_bufferStream->getData(), m_bufferStream->getCurrentPosition());
http::Status status;
http::Parser::parseRequestStartingLine(result.startingLine, nullptr, caret, status);
if(status.code == 0) {
@ -155,7 +155,7 @@ RequestHeadersReader::readHeadersAsync(const std::shared_ptr<data::stream::Input
Action parseHeaders() {
oatpp::parser::Caret caret (m_this->m_bufferStream->getData(), m_this->m_bufferStream->getCurrentPosition());
oatpp::parser::Caret caret ((const char*) m_this->m_bufferStream->getData(), m_this->m_bufferStream->getCurrentPosition());
http::Status status;
http::Parser::parseRequestStartingLine(m_result.startingLine, nullptr, caret, status);
if(status.code == 0) {

View File

@ -66,15 +66,15 @@ bool Response::putHeaderIfNotExists(const oatpp::String& key, const oatpp::Strin
return m_headers.putIfNotExists(key, value);
}
void Response::putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI_FAST& key, const oatpp::data::share::StringKeyLabel& value) {
void Response::putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value) {
m_headers.put(key, value);
}
bool Response::putHeaderIfNotExists_Unsafe(const oatpp::data::share::StringKeyLabelCI_FAST& key, const oatpp::data::share::StringKeyLabel& value) {
bool Response::putHeaderIfNotExists_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value) {
return m_headers.putIfNotExists(key, value);
}
oatpp::String Response::getHeader(const oatpp::data::share::StringKeyLabelCI_FAST& headerName) const{
oatpp::String Response::getHeader(const oatpp::data::share::StringKeyLabelCI& headerName) const{
return m_headers.get(headerName);
}

View File

@ -118,25 +118,25 @@ public:
/**
* Add http header.
* @param key - &id:oatpp::data::share::StringKeyLabelCI_FAST;.
* @param key - &id:oatpp::data::share::StringKeyLabelCI;.
* @param value - &id:oatpp::data::share::StringKeyLabel;.
*/
void putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI_FAST& key, const oatpp::data::share::StringKeyLabel& value);
void putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value);
/**
* Add http header if not already exists.
* @param key - &id:oatpp::data::share::StringKeyLabelCI_FAST;.
* @param key - &id:oatpp::data::share::StringKeyLabelCI;.
* @param value - &id:oatpp::data::share::StringKeyLabel;.
* @return - `true` if header was added.
*/
bool putHeaderIfNotExists_Unsafe(const oatpp::data::share::StringKeyLabelCI_FAST& key, const oatpp::data::share::StringKeyLabel& value);
bool putHeaderIfNotExists_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value);
/**
* Get header value
* @param headerName - &id:oatpp::data::share::StringKeyLabelCI_FAST;.
* @param headerName - &id:oatpp::data::share::StringKeyLabelCI;.
* @return - &id:oatpp::String;.
*/
oatpp::String getHeader(const oatpp::data::share::StringKeyLabelCI_FAST& headerName) const;
oatpp::String getHeader(const oatpp::data::share::StringKeyLabelCI& headerName) const;
/**
* Get raw body stream.

View File

@ -43,7 +43,7 @@ v_io_size ResponseHeadersReader::readHeadersSectionIterative(ReadHeadersIteratio
}
}
auto bufferData = m_buffer.getData();
auto bufferData = (p_char8) m_buffer.getData();
auto res = connection->read(bufferData, desiredToRead, action);
if(res > 0) {

View File

@ -110,7 +110,7 @@ void SimpleBodyDecoder::decode(const Headers& headers,
} else {
auto connectionStr = headers.getAsMemoryLabel<data::share::StringKeyLabelCI_FAST>(Header::CONNECTION);
auto connectionStr = headers.getAsMemoryLabel<data::share::StringKeyLabelCI>(Header::CONNECTION);
if(connectionStr && connectionStr == "close") {
@ -161,7 +161,7 @@ async::CoroutineStarter SimpleBodyDecoder::decodeAsync(const Headers& headers,
} else {
auto connectionStr = headers.getAsMemoryLabel<data::share::StringKeyLabelCI_FAST>(Header::CONNECTION);
auto connectionStr = headers.getAsMemoryLabel<data::share::StringKeyLabelCI>(Header::CONNECTION);
if(connectionStr && connectionStr == "close") {

View File

@ -29,7 +29,7 @@ namespace oatpp { namespace web { namespace protocol { namespace http { namespac
BufferBody::BufferBody(const oatpp::String& buffer, const data::share::StringKeyLabel& contentType)
: m_buffer(buffer)
, m_contentType(contentType)
, m_inlineData(m_buffer->getData(), m_buffer->getSize())
, m_inlineData((void*) m_buffer->data(), m_buffer->size())
{}
std::shared_ptr<BufferBody> BufferBody::createShared(const oatpp::String& buffer, const data::share::StringKeyLabel& contentType) {
@ -66,11 +66,11 @@ void BufferBody::declareHeaders(Headers& headers) {
}
p_char8 BufferBody::getKnownData() {
return m_buffer->getData();
return (p_char8) m_buffer->data();
}
v_int64 BufferBody::getKnownSize() {
return m_buffer->getSize();
return m_buffer->size();
}
}}}}}

View File

@ -135,7 +135,7 @@ v_io_size MultipartBody::readBoundary(const std::shared_ptr<Multipart>& multipar
boundary = "\r\n--" + multipart->getBoundary() + "\r\n";
}
readStream.reset(boundary.getPtr(), boundary->getData(), boundary->getSize());
readStream.reset(boundary.getPtr(), (p_char8) boundary->data(), boundary->size());
}
@ -162,7 +162,7 @@ v_io_size MultipartBody::readHeaders(const std::shared_ptr<Multipart>& multipart
http::Utils::writeHeaders(part->getHeaders(), &stream);
stream.writeSimple("\r\n", 2);
auto str = stream.toString();
readStream.reset(str.getPtr(), str->getData(), str->getSize());
readStream.reset(str.getPtr(), (p_char8) str->data(), str->size());
}

View File

@ -68,15 +68,15 @@ bool Request::putHeaderIfNotExists(const oatpp::String& key, const oatpp::String
return m_headers.putIfNotExists(key, value);
}
void Request::putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI_FAST& key, const oatpp::data::share::StringKeyLabel& value) {
void Request::putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value) {
m_headers.put(key, value);
}
bool Request::putHeaderIfNotExists_Unsafe(const oatpp::data::share::StringKeyLabelCI_FAST& key, const oatpp::data::share::StringKeyLabel& value) {
bool Request::putHeaderIfNotExists_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value) {
return m_headers.putIfNotExists(key, value);
}
oatpp::String Request::getHeader(const oatpp::data::share::StringKeyLabelCI_FAST& headerName) const{
oatpp::String Request::getHeader(const oatpp::data::share::StringKeyLabelCI& headerName) const{
return m_headers.get(headerName);
}

View File

@ -111,25 +111,25 @@ public:
/**
* Add http header.
* @param key - &id:oatpp::data::share::StringKeyLabelCI_FAST;.
* @param key - &id:oatpp::data::share::StringKeyLabelCI;.
* @param value - &id:oatpp::data::share::StringKeyLabel;.
*/
void putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI_FAST& key, const oatpp::data::share::StringKeyLabel& value);
void putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value);
/**
* Add http header if not already exists.
* @param key - &id:oatpp::data::share::StringKeyLabelCI_FAST;.
* @param key - &id:oatpp::data::share::StringKeyLabelCI;.
* @param value - &id:oatpp::data::share::StringKeyLabel;.
* @return - `true` if header was added.
*/
bool putHeaderIfNotExists_Unsafe(const oatpp::data::share::StringKeyLabelCI_FAST& key, const oatpp::data::share::StringKeyLabel& value);
bool putHeaderIfNotExists_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value);
/**
* Get header value
* @param headerName - &id:oatpp::data::share::StringKeyLabelCI_FAST;.
* @param headerName - &id:oatpp::data::share::StringKeyLabelCI;.
* @return - &id:oatpp::String;.
*/
oatpp::String getHeader(const oatpp::data::share::StringKeyLabelCI_FAST& headerName) const;
oatpp::String getHeader(const oatpp::data::share::StringKeyLabelCI& headerName) const;
/**
* Get http body.

View File

@ -56,15 +56,15 @@ bool Response::putHeaderIfNotExists(const oatpp::String& key, const oatpp::Strin
return m_headers.putIfNotExists(key, value);
}
void Response::putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI_FAST& key, const oatpp::data::share::StringKeyLabel& value) {
void Response::putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value) {
m_headers.put(key, value);
}
bool Response::putHeaderIfNotExists_Unsafe(const oatpp::data::share::StringKeyLabelCI_FAST& key, const oatpp::data::share::StringKeyLabel& value) {
bool Response::putHeaderIfNotExists_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value) {
return m_headers.putIfNotExists(key, value);
}
oatpp::String Response::getHeader(const oatpp::data::share::StringKeyLabelCI_FAST& headerName) const {
oatpp::String Response::getHeader(const oatpp::data::share::StringKeyLabelCI& headerName) const {
return m_headers.get(headerName);
}

View File

@ -106,25 +106,25 @@ public:
/**
* Add http header.
* @param key - &id:oatpp::data::share::StringKeyLabelCI_FAST;.
* @param key - &id:oatpp::data::share::StringKeyLabelCI;.
* @param value - &id:oatpp::data::share::StringKeyLabel;.
*/
void putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI_FAST& key, const oatpp::data::share::StringKeyLabel& value);
void putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value);
/**
* Add http header if not already exists.
* @param key - &id:oatpp::data::share::StringKeyLabelCI_FAST;.
* @param key - &id:oatpp::data::share::StringKeyLabelCI;.
* @param value - &id:oatpp::data::share::StringKeyLabel;.
* @return - `true` if header was added.
*/
bool putHeaderIfNotExists_Unsafe(const oatpp::data::share::StringKeyLabelCI_FAST& key, const oatpp::data::share::StringKeyLabel& value);
bool putHeaderIfNotExists_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value);
/**
* Get header value
* @param headerName - &id:oatpp::data::share::StringKeyLabelCI_FAST;.
* @param headerName - &id:oatpp::data::share::StringKeyLabelCI;.
* @return - &id:oatpp::String;.
*/
oatpp::String getHeader(const oatpp::data::share::StringKeyLabelCI_FAST& headerName) const;
oatpp::String getHeader(const oatpp::data::share::StringKeyLabelCI& headerName) const;
/**
* Set connection upgreade header. <br>

View File

@ -26,11 +26,6 @@
namespace oatpp { namespace web { namespace protocol { namespace http { namespace utils {
bool CommunicationUtils::headerEqualsCI_FAST(const oatpp::data::share::MemoryLabel& headerValue, const char* value) {
v_int32 size = (v_int32) std::strlen(value);
return size == headerValue.getSize() && oatpp::base::StrBuffer::equalsCI_FAST(headerValue.getData(), value, size);
}
void CommunicationUtils::considerConnectionState(const std::shared_ptr<protocol::http::incoming::Request>& request,
const std::shared_ptr<protocol::http::outgoing::Response>& response,
ConnectionState& connectionState)
@ -40,7 +35,7 @@ void CommunicationUtils::considerConnectionState(const std::shared_ptr<protocol:
return;
}
auto outState = response->getHeaders().getAsMemoryLabel<oatpp::data::share::StringKeyLabelCI_FAST>(Header::CONNECTION);
auto outState = response->getHeaders().getAsMemoryLabel<oatpp::data::share::StringKeyLabelCI>(Header::CONNECTION);
if(outState && outState == Header::Value::CONNECTION_UPGRADE) {
connectionState = ConnectionState::DELEGATED;
return;
@ -48,7 +43,7 @@ void CommunicationUtils::considerConnectionState(const std::shared_ptr<protocol:
if(request) {
/* If the connection header is present in the request and its value isn't keep-alive, then close */
auto connection = request->getHeaders().getAsMemoryLabel<oatpp::data::share::StringKeyLabelCI_FAST>(Header::CONNECTION);
auto connection = request->getHeaders().getAsMemoryLabel<oatpp::data::share::StringKeyLabelCI>(Header::CONNECTION);
if(connection) {
if(connection != Header::Value::CONNECTION_KEEP_ALIVE) {
connectionState = ConnectionState::CLOSING;
@ -60,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 && headerEqualsCI_FAST(protocol, "HTTP/1.1")) {
if(protocol && oatpp::utils::String::compareCI(protocol.getData(), protocol.getSize(), "HTTP/1.1", 8) == 0) {
if(outState && outState != Header::Value::CONNECTION_KEEP_ALIVE) {
connectionState = ConnectionState::CLOSING;
}

View File

@ -44,8 +44,6 @@ public:
DEAD = 3 // Drop immediately
};
private:
static bool headerEqualsCI_FAST(const oatpp::data::share::MemoryLabel& headerValue, const char* value);
public:
/**

View File

@ -78,7 +78,7 @@ HttpProcessor::ProcessingResources::ProcessingResources(const std::shared_ptr<Co
, headersInBuffer(components->config->headersInBufferInitial)
, headersOutBuffer(components->config->headersOutBufferInitial)
, headersReader(&headersInBuffer, components->config->headersReaderChunkSize, components->config->headersReaderMaxSize)
, inStream(data::stream::InputStreamBufferedProxy::createShared(connection, base::StrBuffer::createShared(data::buffer::IOBuffer::BUFFER_SIZE)))
, inStream(data::stream::InputStreamBufferedProxy::createShared(connection, std::make_shared<std::string>(data::buffer::IOBuffer::BUFFER_SIZE, 0)))
{}
std::shared_ptr<protocol::http::outgoing::Response>
@ -300,7 +300,7 @@ HttpProcessor::Coroutine::Coroutine(const std::shared_ptr<Components>& component
, m_headersInBuffer(components->config->headersInBufferInitial)
, m_headersReader(&m_headersInBuffer, components->config->headersReaderChunkSize, components->config->headersReaderMaxSize)
, m_headersOutBuffer(std::make_shared<oatpp::data::stream::BufferOutputStream>(components->config->headersOutBufferInitial))
, m_inStream(data::stream::InputStreamBufferedProxy::createShared(m_connection, base::StrBuffer::createShared(data::buffer::IOBuffer::BUFFER_SIZE)))
, m_inStream(data::stream::InputStreamBufferedProxy::createShared(m_connection, std::make_shared<std::string>(data::buffer::IOBuffer::BUFFER_SIZE, 0)))
, m_connectionState(ConnectionState::ALIVE)
, m_counter(taskCounter)
{

View File

@ -460,9 +460,9 @@ public:
(void) text;
success = false;
OATPP_LOGE("[oatpp::web::server::api::ApiController::TypeInterpretation::fromString()]",
"Error. No conversion from '%s' to '%s' is defined.", "oatpp::String", typeName->getData());
"Error. No conversion from '%s' to '%s' is defined.", "oatpp::String", typeName->c_str());
throw std::runtime_error("[oatpp::web::server::api::ApiController::TypeInterpretation::fromString()]: Error. "
"No conversion from 'oatpp::String' to '" + typeName->std_str() + "' is defined. "
"No conversion from 'oatpp::String' to '" + *typeName + "' is defined. "
"Please define type conversion.");
}

View File

@ -62,15 +62,15 @@ BasicAuthorizationHandler::BasicAuthorizationHandler(const oatpp::String& realm)
std::shared_ptr<handler::AuthorizationObject> BasicAuthorizationHandler::handleAuthorization(const oatpp::String &header) {
if(header && header->getSize() > 6 && header->startsWith("Basic ")) {
if(header && header->size() > 6 && utils::String::compare(header->data(), 6, "Basic ", 6) == 0) {
oatpp::String auth = oatpp::encoding::Base64::decode(header->c_str() + 6, header->getSize() - 6);
oatpp::String auth = oatpp::encoding::Base64::decode(header->c_str() + 6, header->size() - 6);
parser::Caret caret(auth);
if (caret.findChar(':')) {
oatpp::String userId((const char *) &caret.getData()[0], caret.getPosition(), true /* copy as own data */);
oatpp::String userId((const char *) &caret.getData()[0], caret.getPosition());
oatpp::String password((const char *) &caret.getData()[caret.getPosition() + 1],
caret.getDataSize() - caret.getPosition() - 1, true /* copy as own data */);
caret.getDataSize() - caret.getPosition() - 1);
auto authResult = authorize(userId, password);
if(authResult) {
return authResult;
@ -108,9 +108,9 @@ BearerAuthorizationHandler::BearerAuthorizationHandler(const oatpp::String& real
std::shared_ptr<AuthorizationObject> BearerAuthorizationHandler::handleAuthorization(const oatpp::String &header) {
if(header && header->getSize() > 7 && header->startsWith("Bearer ")) {
if(header && header->size() > 7 && utils::String::compare(header->data(), 7, "Bearer ", 7) == 0) {
oatpp::String token = oatpp::String(header->c_str() + 7, header->getSize() - 7, true);
oatpp::String token = oatpp::String(header->c_str() + 7, header->size() - 7);
auto authResult = authorize(token);
if(authResult) {

View File

@ -50,7 +50,7 @@ std::shared_ptr<Pattern> Pattern::parse(p_char8 data, v_buff_size size){
if(a == '/'){
if(i - lastPos > 0){
auto part = Part::createShared(Part::FUNCTION_CONST, oatpp::String((const char*)&data[lastPos], i - lastPos, true));
auto part = Part::createShared(Part::FUNCTION_CONST, oatpp::String((const char*)&data[lastPos], i - lastPos));
result->m_parts->push_back(part);
}
@ -59,7 +59,7 @@ std::shared_ptr<Pattern> Pattern::parse(p_char8 data, v_buff_size size){
} else if(a == '*'){
lastPos = i + 1;
if(size > lastPos){
auto part = Part::createShared(Part::FUNCTION_ANY_END, oatpp::String((const char*)&data[lastPos], size - lastPos, true));
auto part = Part::createShared(Part::FUNCTION_ANY_END, oatpp::String((const char*)&data[lastPos], size - lastPos));
result->m_parts->push_back(part);
}else{
auto part = Part::createShared(Part::FUNCTION_ANY_END, oatpp::String((v_buff_size)0));
@ -75,7 +75,7 @@ std::shared_ptr<Pattern> Pattern::parse(p_char8 data, v_buff_size size){
}
if(i > lastPos){
auto part = Part::createShared(Part::FUNCTION_VAR, oatpp::String((const char*)&data[lastPos], i - lastPos, true));
auto part = Part::createShared(Part::FUNCTION_VAR, oatpp::String((const char*)&data[lastPos], i - lastPos));
result->m_parts->push_back(part);
}else{
auto part = Part::createShared(Part::FUNCTION_VAR, oatpp::String((v_buff_size)0));
@ -91,7 +91,7 @@ std::shared_ptr<Pattern> Pattern::parse(p_char8 data, v_buff_size size){
}
if(i - lastPos > 0){
auto part = Part::createShared(Part::FUNCTION_CONST, oatpp::String((const char*)&data[lastPos], i - lastPos, true));
auto part = Part::createShared(Part::FUNCTION_CONST, oatpp::String((const char*)&data[lastPos], i - lastPos));
result->m_parts->push_back(part);
}
@ -103,7 +103,7 @@ std::shared_ptr<Pattern> Pattern::parse(const char* data){
}
std::shared_ptr<Pattern> Pattern::parse(const oatpp::String& data){
return parse(data->getData(), data->getSize());
return parse((p_char8) data->data(), data->size());
}
v_char8 Pattern::findSysChar(oatpp::parser::Caret& caret) {
@ -121,7 +121,7 @@ v_char8 Pattern::findSysChar(oatpp::parser::Caret& caret) {
bool Pattern::match(const StringKeyLabel& url, MatchMap& matchMap) {
oatpp::parser::Caret caret(url.getData(), url.getSize());
oatpp::parser::Caret caret((const char*) url.getData(), url.getSize());
if (m_parts->empty()) {
return !caret.skipChar('/');
@ -136,7 +136,7 @@ bool Pattern::match(const StringKeyLabel& url, MatchMap& matchMap) {
if(part->function == Part::FUNCTION_CONST){
if(!caret.isAtText(part->text->getData(), part->text->getSize(), true)){
if(!caret.isAtText(part->text->data(), part->text->size(), true)) {
return false;
}

View File

@ -159,7 +159,7 @@ bool checkSymbol(char symbol, const char* data, v_buff_size size) {
}
bool checkSymbol(char symbol, const oatpp::String& str) {
return checkSymbol(symbol, (const char*)str->getData(), str->getSize());
return checkSymbol(symbol, str->data(), str->size());
}
}
@ -201,8 +201,8 @@ void LockTest::onRun() {
bool check = checkSymbol((char)c, result);
if(!check) {
v_int32 code = c;
auto str = oatpp::String((const char*)&c, 1, true);
OATPP_LOGE(TAG, "Failed for symbol %d, '%s'", code, str->getData());
auto str = oatpp::String((const char*)&c, 1);
OATPP_LOGE(TAG, "Failed for symbol %d, '%s'", code, str->data());
}
OATPP_ASSERT(check);
}

View File

@ -93,7 +93,7 @@ public:
ProcessorToUpper(v_int32 bufferSize) : BaseProcessor(bufferSize) {}
void process(p_char8 data, v_buff_size size) override {
oatpp::base::StrBuffer::upperCase(data, size);
utils::String::upperCaseASCII(data, size);
}
};
@ -104,7 +104,7 @@ public:
ProcessorToLower(v_int32 bufferSize) : BaseProcessor(bufferSize) {}
void process(p_char8 data, v_buff_size size) override {
oatpp::base::StrBuffer::lowerCase(data, size);
utils::String::lowerCaseASCII(data, size);
}
};
@ -213,7 +213,7 @@ void ProcessorTest::onRun() {
auto result = runTestCase(data, p1N, p2N, p3N, buffSize);
if (result != etalon) {
OATPP_LOGD(TAG, "error[%d, %d, %d, b=%d] result='%s'", p1N, p2N, p3N, buffSize, result->getData());
OATPP_LOGD(TAG, "error[%d, %d, %d, b=%d] result='%s'", p1N, p2N, p3N, buffSize, result->data());
}
OATPP_ASSERT(result == etalon);

View File

@ -55,6 +55,8 @@ class DtoA : public oatpp::DTO {
public:
DtoA() = default;
DtoA(const String& pId)
: id(pId)
{}

View File

@ -38,7 +38,7 @@ void ObjectWrapperTest::onRun() {
{
OATPP_LOGI(TAG, "Check default valueType is assigned (default tparam Clazz)...");
ObjectWrapper<base::StrBuffer> pw;
ObjectWrapper<std::string> pw;
OATPP_ASSERT(!pw);
OATPP_ASSERT(pw == nullptr);
OATPP_ASSERT(pw.valueType == oatpp::data::mapping::type::__class::Void::getType());
@ -47,7 +47,7 @@ void ObjectWrapperTest::onRun() {
{
OATPP_LOGI(TAG, "Check default valueType is assigned (specified tparam Clazz)...");
ObjectWrapper<base::StrBuffer, oatpp::data::mapping::type::__class::String> pw;
ObjectWrapper<std::string, oatpp::data::mapping::type::__class::String> pw;
OATPP_ASSERT(!pw);
OATPP_ASSERT(pw == nullptr);
OATPP_ASSERT(pw.valueType == oatpp::data::mapping::type::__class::String::getType());
@ -56,7 +56,7 @@ void ObjectWrapperTest::onRun() {
{
OATPP_LOGI(TAG, "Check valueType is assigned from constructor...");
ObjectWrapper<base::StrBuffer> pw(oatpp::data::mapping::type::__class::String::getType());
ObjectWrapper<std::string> pw(oatpp::data::mapping::type::__class::String::getType());
OATPP_ASSERT(!pw);
OATPP_ASSERT(pw == nullptr);
OATPP_ASSERT(pw.valueType == oatpp::data::mapping::type::__class::String::getType());
@ -65,24 +65,24 @@ void ObjectWrapperTest::onRun() {
{
OATPP_LOGI(TAG, "Check valueType is assigned from copy constructor...");
ObjectWrapper<base::StrBuffer> pw1(oatpp::data::mapping::type::__class::String::getType());
ObjectWrapper<base::StrBuffer> pw2(pw1);
ObjectWrapper<std::string> pw1(oatpp::data::mapping::type::__class::String::getType());
ObjectWrapper<std::string> pw2(pw1);
OATPP_ASSERT(pw2.valueType == oatpp::data::mapping::type::__class::String::getType());
OATPP_LOGI(TAG, "OK");
}
{
OATPP_LOGI(TAG, "Check valueType is assigned from move constructor...");
ObjectWrapper<base::StrBuffer> pw1(oatpp::data::mapping::type::__class::String::getType());
ObjectWrapper<base::StrBuffer> pw2(std::move(pw1));
ObjectWrapper<std::string> pw1(oatpp::data::mapping::type::__class::String::getType());
ObjectWrapper<std::string> pw2(std::move(pw1));
OATPP_ASSERT(pw2.valueType == oatpp::data::mapping::type::__class::String::getType());
OATPP_LOGI(TAG, "OK");
}
{
OATPP_LOGI(TAG, "Check valueType is NOT assigned from copy-assign operator...");
ObjectWrapper<base::StrBuffer> pw1(oatpp::data::mapping::type::__class::String::getType());
ObjectWrapper<base::StrBuffer> pw2;
ObjectWrapper<std::string> pw1(oatpp::data::mapping::type::__class::String::getType());
ObjectWrapper<std::string> pw2;
pw2 = pw1;
OATPP_ASSERT(pw2.valueType == oatpp::data::mapping::type::__class::Void::getType());
OATPP_LOGI(TAG, "OK");
@ -90,8 +90,8 @@ void ObjectWrapperTest::onRun() {
{
OATPP_LOGI(TAG, "Check valueType is NOT assigned from move-assign operator...");
ObjectWrapper<base::StrBuffer> pw1(oatpp::data::mapping::type::__class::String::getType());
ObjectWrapper<base::StrBuffer> pw2;
ObjectWrapper<std::string> pw1(oatpp::data::mapping::type::__class::String::getType());
ObjectWrapper<std::string> pw2;
pw2 = std::move(pw1);
OATPP_ASSERT(pw2.valueType == oatpp::data::mapping::type::__class::Void::getType());
OATPP_LOGI(TAG, "OK");
@ -99,12 +99,12 @@ void ObjectWrapperTest::onRun() {
{
OATPP_LOGI(TAG, "Check copy-assign operator. Check == operator...");
ObjectWrapper<base::StrBuffer> pw1;
ObjectWrapper<std::string> pw1;
OATPP_ASSERT(!pw1);
OATPP_ASSERT(pw1 == nullptr);
OATPP_ASSERT(pw1.valueType == oatpp::data::mapping::type::__class::Void::getType());
ObjectWrapper<base::StrBuffer> pw2 = base::StrBuffer::createShared("Hello!");
ObjectWrapper<std::string> pw2 = std::make_shared<std::string>("Hello!");
OATPP_ASSERT(pw2);
OATPP_ASSERT(pw2 != nullptr);
OATPP_ASSERT(pw2.valueType == oatpp::data::mapping::type::__class::Void::getType());
@ -124,12 +124,12 @@ void ObjectWrapperTest::onRun() {
{
OATPP_LOGI(TAG, "Check != operator...");
ObjectWrapper<base::StrBuffer, oatpp::data::mapping::type::__class::String> pw1(base::StrBuffer::createShared("Hello!"));
ObjectWrapper<std::string, oatpp::data::mapping::type::__class::String> pw1(std::make_shared<std::string>("Hello!"));
OATPP_ASSERT(pw1);
OATPP_ASSERT(pw1 != nullptr);
OATPP_ASSERT(pw1.valueType == oatpp::data::mapping::type::__class::String::getType());
ObjectWrapper<base::StrBuffer, oatpp::data::mapping::type::__class::String> pw2(base::StrBuffer::createShared("Hello!"));
ObjectWrapper<std::string, oatpp::data::mapping::type::__class::String> pw2(std::make_shared<std::string>("Hello!"));
OATPP_ASSERT(pw2);
OATPP_ASSERT(pw2 != nullptr);
OATPP_ASSERT(pw2.valueType == oatpp::data::mapping::type::__class::String::getType());
@ -141,12 +141,12 @@ void ObjectWrapperTest::onRun() {
{
OATPP_LOGI(TAG, "Check move-assign operator. Check != operator...");
ObjectWrapper<base::StrBuffer> pw1;
ObjectWrapper<std::string> pw1;
OATPP_ASSERT(!pw1);
OATPP_ASSERT(pw1 == nullptr);
OATPP_ASSERT(pw1.valueType == oatpp::data::mapping::type::__class::Void::getType());
ObjectWrapper<base::StrBuffer> pw2 = base::StrBuffer::createShared("Hello!");
ObjectWrapper<std::string> pw2 = std::make_shared<std::string>("Hello!");
OATPP_ASSERT(pw2);
OATPP_ASSERT(pw2 != nullptr);
OATPP_ASSERT(pw2.valueType == oatpp::data::mapping::type::__class::Void::getType());

View File

@ -47,13 +47,100 @@ void StringTest::onRun() {
OATPP_LOGI(TAG, "OK");
}
{
OATPP_LOGI(TAG, "test nullptr constructor");
oatpp::String s(nullptr);
OATPP_ASSERT(!s);
OATPP_ASSERT(s == nullptr);
OATPP_ASSERT(s == (const char*) nullptr);
OATPP_ASSERT(s.valueType == oatpp::String::Class::getType());
OATPP_LOGI(TAG, "OK");
}
{
OATPP_LOGI(TAG, "test const char* constructor");
oatpp::String s("");
oatpp::String s("abc\0xyz");
OATPP_ASSERT(s);
OATPP_ASSERT(s != nullptr);
OATPP_ASSERT(s != (const char*) nullptr)
OATPP_ASSERT(s->getSize() == 0);
OATPP_ASSERT(s->size() == 3);
OATPP_ASSERT(s == "abc");
OATPP_ASSERT(s == "abc\0xyz");
OATPP_LOGI(TAG, "OK");
}
{
OATPP_LOGI(TAG, "test std::string constructor");
std::string a("abc\0xyz", 7);
oatpp::String s(a);
OATPP_ASSERT(s);
OATPP_ASSERT(s != nullptr);
OATPP_ASSERT(s != (const char*) nullptr)
OATPP_ASSERT(s->size() == 7);
OATPP_ASSERT(s != "abc");
OATPP_ASSERT(s != "abc\0xyz");
OATPP_ASSERT(s == std::string("abc\0xyz", 7));
OATPP_ASSERT(s == a);
OATPP_LOGI(TAG, "OK");
}
{
OATPP_LOGI(TAG, "test std::string move constructor");
std::string a("abc\0xyz", 7);
oatpp::String s(std::move(a));
OATPP_ASSERT(s);
OATPP_ASSERT(s != nullptr);
OATPP_ASSERT(s != (const char*) nullptr)
OATPP_ASSERT(s->size() == 7);
OATPP_ASSERT(s != "abc");
OATPP_ASSERT(s != "abc\0xyz");
OATPP_ASSERT(s == std::string("abc\0xyz", 7));
OATPP_ASSERT(a == "");
OATPP_LOGI(TAG, "OK");
}
{
OATPP_LOGI(TAG, "test const char* assign operator");
oatpp::String s;
s = "abc\0xyz";
OATPP_ASSERT(s);
OATPP_ASSERT(s != nullptr);
OATPP_ASSERT(s != (const char*) nullptr)
OATPP_ASSERT(s->size() == 3);
OATPP_ASSERT(s == "abc");
OATPP_ASSERT(s == "abc\0xyz");
OATPP_LOGI(TAG, "OK");
}
{
OATPP_LOGI(TAG, "test std::string assign operator");
oatpp::String s;
std::string a = std::string("abc\0xyz", 7);
s = a;
OATPP_ASSERT(s);
OATPP_ASSERT(s != nullptr);
OATPP_ASSERT(s != (const char*) nullptr)
OATPP_ASSERT(s->size() == 7);
OATPP_ASSERT(s != "abc");
OATPP_ASSERT(s != "abc\0xyz");
OATPP_ASSERT(s == std::string("abc\0xyz", 7));
OATPP_ASSERT(s == a);
OATPP_LOGI(TAG, "OK");
}
{
OATPP_LOGI(TAG, "test std::string move assign operator");
oatpp::String s;
std::string a = std::string("abc\0xyz", 7);
s = std::move(a);
OATPP_ASSERT(s);
OATPP_ASSERT(s != nullptr);
OATPP_ASSERT(s != (const char*) nullptr)
OATPP_ASSERT(s->size() == 7);
OATPP_ASSERT(s != "abc");
OATPP_ASSERT(s != "abc\0xyz");
OATPP_ASSERT(s == std::string("abc\0xyz", 7));
OATPP_ASSERT(a == "");
OATPP_LOGI(TAG, "OK");
}
@ -63,7 +150,7 @@ void StringTest::onRun() {
OATPP_ASSERT(s);
OATPP_ASSERT(s != nullptr);
OATPP_ASSERT(s != (const char*) nullptr)
OATPP_ASSERT(s->getSize() == 0);
OATPP_ASSERT(s->size() == 0);
OATPP_LOGI(TAG, "OK");
}

View File

@ -41,7 +41,7 @@ namespace {
void LazyStringMapTest::onRun() {
p_char8 text = (p_char8) "Hello World!";
const char* text = "Hello World!";
{
@ -70,8 +70,8 @@ void LazyStringMapTest::onRun() {
auto s13 = all["key1"];
auto s23 = all["key2"];
OATPP_ASSERT(s13.getData() == s1->getData() && s13.getSize() == s1->getSize());
OATPP_ASSERT(s23.getData() == s2->getData() && s23.getSize() == s2->getSize());
OATPP_ASSERT(s13.getData() == s1->data() && s13.getSize() == s1->size());
OATPP_ASSERT(s23.getData() == s2->data() && s23.getSize() == s2->size());
OATPP_ASSERT(s1.get() == s13.getMemoryHandle().get());
OATPP_ASSERT(s2.get() == s23.getMemoryHandle().get());

View File

@ -37,7 +37,6 @@ namespace {
typedef oatpp::data::share::MemoryLabel MemoryLabel;
typedef oatpp::data::share::StringKeyLabel StringKeyLabel;
typedef oatpp::data::share::StringKeyLabelCI StringKeyLabelCI;
typedef oatpp::data::share::StringKeyLabelCI_FAST StringKeyLabelCI_FAST;
}
void MemoryLabelTest::onRun() {
@ -140,55 +139,6 @@ void MemoryLabelTest::onRun() {
OATPP_LOGI(TAG, "OK");
}
{
OATPP_LOGI(TAG, "StringKeyLabelCI_FAST default constructor...");
StringKeyLabelCI_FAST s;
StringKeyLabelCI_FAST s0;
OATPP_ASSERT(!s);
OATPP_ASSERT(s == nullptr);
OATPP_ASSERT(s == s0);
OATPP_ASSERT(s != "teXt");
OATPP_ASSERT(s != oatpp::String("teXt"));
OATPP_LOGI(TAG, "OK");
}
{
OATPP_LOGI(TAG, "StringKeyLabelCI_FAST nullptr constructor...");
StringKeyLabelCI_FAST s(nullptr);
OATPP_ASSERT(!s);
OATPP_ASSERT(s == nullptr);
OATPP_ASSERT(s != "teXt");
OATPP_ASSERT(s != oatpp::String("teXt"));
OATPP_LOGI(TAG, "OK");
}
{
OATPP_LOGI(TAG, "StringKeyLabelCI_FAST const char* constructor...");
StringKeyLabelCI_FAST s("hello");
StringKeyLabelCI_FAST s0;
OATPP_ASSERT(s);
OATPP_ASSERT(s != nullptr);
OATPP_ASSERT(s != s0);
OATPP_ASSERT(s0 != s);
OATPP_ASSERT(s == "helLO");
OATPP_ASSERT(s == oatpp::String("helLO"));
OATPP_ASSERT(s != "text");
OATPP_ASSERT(s != oatpp::String("teXt"));
OATPP_LOGI(TAG, "OK");
}
{
OATPP_LOGI(TAG, "StringKeyLabelCI_FAST oatpp::String constructor...");
StringKeyLabelCI_FAST s(oatpp::String("hello"));
OATPP_ASSERT(s);
OATPP_ASSERT(s != nullptr);
OATPP_ASSERT(s == "helLO");
OATPP_ASSERT(s == oatpp::String("helLO"));
OATPP_ASSERT(s != "text");
OATPP_ASSERT(s != oatpp::String("teXt"));
OATPP_LOGI(TAG, "OK");
}
{
OATPP_LOGI(TAG, "general test...");
@ -200,19 +150,18 @@ void MemoryLabelTest::onRun() {
std::unordered_map<StringKeyLabel, MemoryLabel> stringMap;
std::unordered_map<StringKeyLabelCI, MemoryLabel> stringMapCI;
std::unordered_map<StringKeyLabelCI_FAST, MemoryLabel> stringMapCI_FAST;
// Case-Sensitive
stringMap[key1] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[0], 3);
stringMap[key2] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[4], 4);
stringMap[key3] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[9], 4);
stringMap[key4] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[14], 4);
stringMap[key1] = MemoryLabel(sharedData.getPtr(), &sharedData->data()[0], 3);
stringMap[key2] = MemoryLabel(sharedData.getPtr(), &sharedData->data()[4], 4);
stringMap[key3] = MemoryLabel(sharedData.getPtr(), &sharedData->data()[9], 4);
stringMap[key4] = MemoryLabel(sharedData.getPtr(), &sharedData->data()[14], 4);
OATPP_ASSERT(oatpp::base::StrBuffer::equals("big", stringMap["key1"].getData(), 3));
OATPP_ASSERT(oatpp::base::StrBuffer::equals("text", stringMap["key2"].getData(), 4));
OATPP_ASSERT(oatpp::base::StrBuffer::equals("goes", stringMap["key3"].getData(), 4));
OATPP_ASSERT(oatpp::base::StrBuffer::equals("here", stringMap["key4"].getData(), 4));
OATPP_ASSERT(stringMap["key1"].equals("big"));
OATPP_ASSERT(stringMap["key2"].equals("text"));
OATPP_ASSERT(stringMap["key3"].equals("goes"));
OATPP_ASSERT(stringMap["key4"].equals("here"));
OATPP_ASSERT(stringMap.find("Key1") == stringMap.end());
OATPP_ASSERT(stringMap.find("Key2") == stringMap.end());
@ -222,38 +171,20 @@ void MemoryLabelTest::onRun() {
// CI
stringMapCI[key1] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[0], 3);
stringMapCI[key2] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[4], 4);
stringMapCI[key3] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[9], 4);
stringMapCI[key4] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[14], 4);
stringMapCI[key1] = MemoryLabel(sharedData.getPtr(), &sharedData->data()[0], 3);
stringMapCI[key2] = MemoryLabel(sharedData.getPtr(), &sharedData->data()[4], 4);
stringMapCI[key3] = MemoryLabel(sharedData.getPtr(), &sharedData->data()[9], 4);
stringMapCI[key4] = MemoryLabel(sharedData.getPtr(), &sharedData->data()[14], 4);
OATPP_ASSERT(oatpp::base::StrBuffer::equals("big", stringMapCI["key1"].getData(), 3));
OATPP_ASSERT(oatpp::base::StrBuffer::equals("text", stringMapCI["key2"].getData(), 4));
OATPP_ASSERT(oatpp::base::StrBuffer::equals("goes", stringMapCI["key3"].getData(), 4));
OATPP_ASSERT(oatpp::base::StrBuffer::equals("here", stringMapCI["key4"].getData(), 4));
OATPP_ASSERT(stringMapCI["key1"].equals("big"));
OATPP_ASSERT(stringMapCI["key2"].equals("text"));
OATPP_ASSERT(stringMapCI["key3"].equals("goes"));
OATPP_ASSERT(stringMapCI["key4"].equals("here"));
OATPP_ASSERT(oatpp::base::StrBuffer::equals("big", stringMapCI["KEY1"].getData(), 3));
OATPP_ASSERT(oatpp::base::StrBuffer::equals("text", stringMapCI["KEY2"].getData(), 4));
OATPP_ASSERT(oatpp::base::StrBuffer::equals("goes", stringMapCI["KEY3"].getData(), 4));
OATPP_ASSERT(oatpp::base::StrBuffer::equals("here", stringMapCI["KEY4"].getData(), 4));
// CI_FAST
stringMapCI_FAST[key1] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[0], 3);
stringMapCI_FAST[key2] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[4], 4);
stringMapCI_FAST[key3] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[9], 4);
stringMapCI_FAST[key4] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[14], 4);
OATPP_ASSERT(oatpp::base::StrBuffer::equals("big", stringMapCI_FAST["key1"].getData(), 3));
OATPP_ASSERT(oatpp::base::StrBuffer::equals("text", stringMapCI_FAST["key2"].getData(), 4));
OATPP_ASSERT(oatpp::base::StrBuffer::equals("goes", stringMapCI_FAST["key3"].getData(), 4));
OATPP_ASSERT(oatpp::base::StrBuffer::equals("here", stringMapCI_FAST["key4"].getData(), 4));
OATPP_ASSERT(oatpp::base::StrBuffer::equals("big", stringMapCI_FAST["KEY1"].getData(), 3));
OATPP_ASSERT(oatpp::base::StrBuffer::equals("text", stringMapCI_FAST["KEY2"].getData(), 4));
OATPP_ASSERT(oatpp::base::StrBuffer::equals("goes", stringMapCI_FAST["KEY3"].getData(), 4));
OATPP_ASSERT(oatpp::base::StrBuffer::equals("here", stringMapCI_FAST["KEY4"].getData(), 4));
OATPP_ASSERT(stringMapCI["KEY1"].equals("big"));
OATPP_ASSERT(stringMapCI["KEY2"].equals("text"));
OATPP_ASSERT(stringMapCI["KEY3"].equals("goes"));
OATPP_ASSERT(stringMapCI["KEY4"].equals("here"));
{

View File

@ -111,11 +111,11 @@ void BufferStreamTest::onRun() {
auto wholeText = stream.toString();
OATPP_ASSERT(wholeText->getSize() == fragmentsCount * 10);
OATPP_ASSERT(wholeText->size() == fragmentsCount * 10);
v_int32 substringSize = 10;
for(v_int32 i = 0; i < wholeText->getSize() - substringSize; i ++) {
OATPP_ASSERT(oatpp::String((const char*)&wholeText->getData()[i], substringSize, false) == stream.getSubstring(i, substringSize));
for(v_int32 i = 0; i < wholeText->size() - substringSize; i ++) {
OATPP_ASSERT(oatpp::String(&wholeText->data()[i], substringSize) == stream.getSubstring(i, substringSize));
}
}

View File

@ -109,16 +109,16 @@ void ChunkedBufferTest::onRun() {
auto wholeText = stream.toString();
OATPP_ASSERT(wholeText->getSize() == ChunkedBuffer::CHUNK_ENTRY_SIZE * 10 * 10);
OATPP_ASSERT(wholeText->size() == ChunkedBuffer::CHUNK_ENTRY_SIZE * 10 * 10);
v_int32 substringSize = 10;
for(v_int32 i = 0; i < wholeText->getSize() - substringSize; i ++) {
OATPP_ASSERT(oatpp::String((const char*)&wholeText->getData()[i], substringSize, false) == stream.getSubstring(i, substringSize));
for(v_int32 i = 0; i < wholeText->size() - substringSize; i ++) {
OATPP_ASSERT(oatpp::String(&wholeText->data()[i], substringSize) == stream.getSubstring(i, substringSize));
}
substringSize = (v_int32) ChunkedBuffer::CHUNK_ENTRY_SIZE * 2;
for(v_int32 i = 0; i < wholeText->getSize() - substringSize; i ++) {
OATPP_ASSERT(oatpp::String((const char*)&wholeText->getData()[i], substringSize, false) == stream.getSubstring(i, substringSize));
for(v_int32 i = 0; i < wholeText->size() - substringSize; i ++) {
OATPP_ASSERT(oatpp::String(&wholeText->data()[i], substringSize) == stream.getSubstring(i, substringSize));
}
}

View File

@ -36,16 +36,16 @@ void Base64Test::onRun() {
{
oatpp::String encoded = oatpp::encoding::Base64::encode(message);
OATPP_LOGV(TAG, "encoded='%s'", encoded->c_str());
OATPP_ASSERT(encoded->equals(messageEncoded.get()));
OATPP_ASSERT(encoded == messageEncoded);
oatpp::String decoded = oatpp::encoding::Base64::decode(encoded);
OATPP_ASSERT(message->equals(decoded.get()));
OATPP_ASSERT(message == decoded);
}
{
oatpp::String encoded = oatpp::encoding::Base64::encode(message, oatpp::encoding::Base64::ALPHABET_BASE64_URL_SAFE);
OATPP_LOGV(TAG, "encoded='%s'", encoded->c_str());
oatpp::String decoded = oatpp::encoding::Base64::decode(encoded, oatpp::encoding::Base64::ALPHABET_BASE64_URL_SAFE_AUXILIARY_CHARS);
OATPP_ASSERT(message->equals(decoded.get()));
OATPP_ASSERT(message == decoded);
}
}

View File

@ -68,7 +68,7 @@ void UnicodeTest::onRun(){
for(v_int32 c = 128; c < 2048; c ++){
auto size = oatpp::encoding::Unicode::decodeUtf8Char(c, buff);
OATPP_ASSERT(size == 2);
auto code = oatpp::encoding::Unicode::encodeUtf8Char(buff, cnt);
auto code = oatpp::encoding::Unicode::encodeUtf8Char((const char*) buff, cnt);
OATPP_ASSERT(cnt == 2);
OATPP_ASSERT(code == c);
}
@ -78,7 +78,7 @@ void UnicodeTest::onRun(){
for(v_int32 c = 2048; c < 65536; c ++){
auto size = oatpp::encoding::Unicode::decodeUtf8Char(c, buff);
OATPP_ASSERT(size == 3);
auto code = oatpp::encoding::Unicode::encodeUtf8Char(buff, cnt);
auto code = oatpp::encoding::Unicode::encodeUtf8Char((const char*) buff, cnt);
OATPP_ASSERT(cnt == 3);
OATPP_ASSERT(code == c);
}
@ -88,7 +88,7 @@ void UnicodeTest::onRun(){
for(v_int32 c = 65536; c < 2097152; c ++){
auto size = oatpp::encoding::Unicode::decodeUtf8Char(c, buff);
OATPP_ASSERT(size == 4);
auto code = oatpp::encoding::Unicode::encodeUtf8Char(buff, cnt);
auto code = oatpp::encoding::Unicode::encodeUtf8Char((const char*) buff, cnt);
OATPP_ASSERT(cnt == 4);
OATPP_ASSERT(code == c);
}
@ -98,7 +98,7 @@ void UnicodeTest::onRun(){
for(v_int32 c = 2097152; c < 67108864; c ++){
auto size = oatpp::encoding::Unicode::decodeUtf8Char(c, buff);
OATPP_ASSERT(size == 5);
auto code = oatpp::encoding::Unicode::encodeUtf8Char(buff, cnt);
auto code = oatpp::encoding::Unicode::encodeUtf8Char((const char*) buff, cnt);
OATPP_ASSERT(cnt == 5);
OATPP_ASSERT(code == c);
}
@ -108,14 +108,14 @@ void UnicodeTest::onRun(){
for (v_int64 c = 67108864; c < 2147483647; c = c + 100) {
auto size = oatpp::encoding::Unicode::decodeUtf8Char((v_int32) c, buff);
OATPP_ASSERT(size == 6);
auto code = oatpp::encoding::Unicode::encodeUtf8Char(buff, cnt);
auto code = oatpp::encoding::Unicode::encodeUtf8Char((const char*) buff, cnt);
OATPP_ASSERT(cnt == 6);
OATPP_ASSERT(code == c);
}
// */
p_char8 sequence = (p_char8)"𐐷";
const char* sequence = "𐐷";
auto code = oatpp::encoding::Unicode::encodeUtf8Char(sequence, cnt);
v_int16 high;

View File

@ -55,8 +55,8 @@ namespace {
auto submission = m_interface->connect();
auto socket = submission->getSocket();
auto res = socket->writeExactSizeDataSimple(m_dataSample->getData(), m_dataSample->getSize());
OATPP_ASSERT(res == m_dataSample->getSize());
auto res = socket->writeExactSizeDataSimple(m_dataSample->data(), m_dataSample->size());
OATPP_ASSERT(res == m_dataSample->size());
v_char8 buffer[100];
oatpp::data::stream::ChunkedBuffer stream;
@ -87,9 +87,9 @@ namespace {
void run() {
v_char8 buffer[100];
oatpp::data::stream::ChunkedBuffer stream;
auto res = oatpp::data::stream::transfer(m_socket.get(), &stream, m_dataSample->getSize(), buffer, 100);
auto res = oatpp::data::stream::transfer(m_socket.get(), &stream, m_dataSample->size(), buffer, 100);
OATPP_ASSERT(res == m_dataSample->getSize());
OATPP_ASSERT(res == m_dataSample->size());
OATPP_ASSERT(stream.getSize() == res);
OATPP_ASSERT(stream.toString() == m_dataSample);

View File

@ -78,7 +78,7 @@ void DTOMapperPerfTest::onRun() {
auto test1 = Test1::createTestInstance();
auto test1_Text = mapper->writeToString(test1);
OATPP_LOGV(TAG, "json='%s'", (const char*) test1_Text->getData());
OATPP_LOGV(TAG, "json='%s'", test1_Text->c_str());
{
PerformanceChecker checker("Serializer");

View File

@ -49,6 +49,8 @@ class TestChild : public oatpp::DTO {
public:
TestChild() = default;
TestChild(const char* pName, const char* pSecondName)
: name(pName)
, secondName(pSecondName)
@ -213,7 +215,7 @@ void DTOMapperTest::onRun(){
auto result = mapper->writeToString(test1);
OATPP_LOGV(TAG, "json='%s'", (const char*) result->getData());
OATPP_LOGV(TAG, "json='%s'", result->c_str());
OATPP_LOGV(TAG, "...");
OATPP_LOGV(TAG, "...");
@ -266,7 +268,7 @@ void DTOMapperTest::onRun(){
result = mapper->writeToString(obj);
OATPP_LOGV(TAG, "json='%s'", (const char*) result->getData());
OATPP_LOGV(TAG, "json='%s'", result->c_str());
{
@ -288,12 +290,12 @@ void DTOMapperTest::onRun(){
obj->anyList->push_back(map);
auto json = mapper->writeToString(obj);
OATPP_LOGV(TAG, "any json='%s'", (const char*) json->getData());
OATPP_LOGV(TAG, "any json='%s'", json->c_str());
auto deserializedAny = mapper->readFromString<oatpp::Fields<oatpp::Any>>(json);
auto json2 = mapper->writeToString(deserializedAny);
OATPP_LOGV(TAG, "any json='%s'", (const char*) json2->getData());
OATPP_LOGV(TAG, "any json='%s'", json2->c_str());
}

View File

@ -94,13 +94,13 @@ void DeserializerTest::onRun(){
OATPP_ASSERT(obj1);
OATPP_ASSERT(obj1->strF);
OATPP_ASSERT(obj1->strF->equals("value1"));
OATPP_ASSERT(obj1->strF == "value1");
obj1 = mapper->readFromString<oatpp::Object<Test1>>("{\n\r\t\f\"strF\"\n\r\t\f:\n\r\t\f\"value1\"\n\r\t\f}");
OATPP_ASSERT(obj1);
OATPP_ASSERT(obj1->strF);
OATPP_ASSERT(obj1->strF->equals("value1"));
OATPP_ASSERT(obj1->strF == "value1");
auto obj2 = mapper->readFromString<oatpp::Object<Test2>>("{\"int32F\": null}");

View File

@ -216,7 +216,7 @@ void FullAsyncTest::onRun() {
v_int32 numIterations = 10;
oatpp::data::stream::ChunkedBuffer stream;
for(v_int32 i = 0; i < numIterations; i++) {
stream.writeSimple(sample->getData(), sample->getSize());
stream.writeSimple(sample->data(), sample->size());
}
auto data = stream.toString();
auto response = client->getChunked(sample, numIterations, connection);

View File

@ -403,7 +403,7 @@ void FullTest::onRun() {
// should also add the WWW-Authenticate header when Authorization is missing or wrong
auto header = response->getHeader(oatpp::web::protocol::http::Header::WWW_AUTHENTICATE);
OATPP_ASSERT(header);
OATPP_ASSERT(header->startsWith("Basic realm=\"custom-test-realm\""));
OATPP_ASSERT(header == "Basic realm=\"custom-test-realm\"");
}
{ // test custom authorization handler with custom authorization method
@ -434,7 +434,7 @@ void FullTest::onRun() {
v_int32 numIterations = 10;
oatpp::data::stream::ChunkedBuffer stream;
for(v_int32 i = 0; i < numIterations; i++) {
stream.writeSimple(sample->getData(), sample->getSize());
stream.writeSimple(sample->data(), sample->size());
}
auto data = stream.toString();
auto response = client->getChunked(sample, numIterations, connection);

View File

@ -163,11 +163,11 @@ void PipelineAsyncTest::onRun() {
oatpp::data::stream::ChunkedBuffer receiveStream;
oatpp::data::buffer::IOBuffer ioBuffer;
auto res = oatpp::data::stream::transfer(connection.get(), &receiveStream, sample->getSize() * m_pipelineSize, ioBuffer.getData(), ioBuffer.getSize());
auto res = oatpp::data::stream::transfer(connection.get(), &receiveStream, sample->size() * m_pipelineSize, ioBuffer.getData(), ioBuffer.getSize());
auto result = receiveStream.toString();
OATPP_ASSERT(result->getSize() == sample->getSize() * m_pipelineSize);
OATPP_ASSERT(result->size() == sample->size() * m_pipelineSize);
//OATPP_ASSERT(result == wantedResult); // headers may come in different order on different OSs
});

View File

@ -145,7 +145,7 @@ void PipelineTest::onRun() {
}
auto dataToSend = pipelineStream.toString();
OATPP_LOGD(TAG, "Sending %d bytes", dataToSend->getSize());
OATPP_LOGD(TAG, "Sending %d bytes", dataToSend->size());
oatpp::data::stream::BufferInputStream inputStream(dataToSend);
@ -161,14 +161,14 @@ void PipelineTest::onRun() {
oatpp::data::stream::BufferOutputStream receiveStream;
oatpp::data::buffer::IOBuffer ioBuffer;
v_io_size transferSize = sample->getSize() * m_pipelineSize;
v_io_size transferSize = sample->size() * m_pipelineSize;
OATPP_LOGD(TAG, "want to Receive %d bytes", transferSize);
auto res = oatpp::data::stream::transfer(connection.get(), &receiveStream, transferSize, ioBuffer.getData(), ioBuffer.getSize());
auto result = receiveStream.toString();
OATPP_ASSERT(result->getSize() == sample->getSize() * m_pipelineSize);
OATPP_ASSERT(result->size() == sample->size() * m_pipelineSize);
//OATPP_ASSERT(result == wantedResult); // headers may come in different order on different OSs
});

View File

@ -179,14 +179,14 @@ public:
oatpp::String m_text;
v_int32 m_counter;
v_int32 m_iterations;
data::buffer::InlineReadData m_inlineData;
data::buffer::InlineWriteData m_inlineData;
public:
ReadCallback(const oatpp::String& text, v_int32 iterations)
: m_text(text)
, m_counter(0)
, m_iterations(iterations)
, m_inlineData(text->getData(), text->getSize())
, m_inlineData(text->data(), text->size())
{}
v_io_size read(void *buffer, v_buff_size count, async::Action& action) override {
@ -205,7 +205,7 @@ public:
m_inlineData.inc(desiredToRead);
if (m_inlineData.bytesLeft == 0) {
m_inlineData.set(m_text->getData(), m_text->getSize());
m_inlineData.set(m_text->data(), m_text->size());
m_counter++;
}

View File

@ -145,14 +145,14 @@ public:
oatpp::String m_text;
v_int32 m_counter;
v_int32 m_iterations;
data::buffer::InlineReadData m_inlineData;
data::buffer::InlineWriteData m_inlineData;
public:
ReadCallback(const oatpp::String& text, v_int32 iterations)
: m_text(text)
, m_counter(0)
, m_iterations(iterations)
, m_inlineData(text->getData(), text->getSize())
, m_inlineData(text->data(), text->size())
{}
v_io_size read(void *buffer, v_buff_size count, async::Action& action) override {
@ -171,7 +171,7 @@ public:
m_inlineData.inc(desiredToRead);
if (m_inlineData.bytesLeft == 0) {
m_inlineData.set(m_text->getData(), m_text->getSize());
m_inlineData.set(m_text->data(), m_text->size());
m_counter++;
}

View File

@ -64,7 +64,7 @@ namespace {
oatpp::web::mime::multipart::StatefulParser parser(boundary, listener, nullptr);
oatpp::data::stream::BufferInputStream stream(text.getPtr(), text->getData(), text->getSize());
oatpp::data::stream::BufferInputStream stream(text.getPtr(), text->data(), text->size());
std::unique_ptr<v_char8[]> buffer(new v_char8[step]);
v_io_size size;
while((size = stream.readSimple(buffer.get(), step)) != 0) {
@ -101,7 +101,7 @@ void StatefulParserTest::onRun() {
oatpp::String text = TEST_DATA_1;
for(v_int32 i = 1; i < text->getSize(); i++) {
for(v_int32 i = 1; i < text->size(); i++) {
oatpp::web::mime::multipart::PartList multipart("12345");

Some files were not shown because too many files have changed in this diff Show More