partial parser::Caret refactoring

This commit is contained in:
lganzzzo 2019-02-17 17:14:04 +02:00
parent 75eaa09263
commit 896719cbd7
22 changed files with 442 additions and 415 deletions

View File

@ -76,8 +76,8 @@ add_library(oatpp
oatpp/core/macro/basic.hpp
oatpp/core/macro/codegen.hpp
oatpp/core/macro/component.hpp
oatpp/core/parser/ParsingCaret.cpp
oatpp/core/parser/ParsingCaret.hpp
oatpp/core/parser/Caret.cpp
oatpp/core/parser/Caret.hpp
oatpp/core/utils/ConversionUtils.cpp
oatpp/core/utils/ConversionUtils.hpp
oatpp/encoding/Base64.cpp

View File

@ -32,7 +32,7 @@
#include "oatpp/core/data/stream/ChunkedBuffer.hpp"
#include "oatpp/core/data/stream/Stream.hpp"
#include "oatpp/core/parser/ParsingCaret.hpp"
#include "oatpp/core/parser/Caret.hpp"
#include "oatpp/core/parser/ParsingError.hpp"
namespace oatpp { namespace data { namespace mapping {
@ -61,7 +61,7 @@ public:
virtual void write(const std::shared_ptr<oatpp::data::stream::OutputStream>& stream,
const type::AbstractObjectWrapper& variant) const = 0;
virtual type::AbstractObjectWrapper read(oatpp::parser::ParsingCaret& caret,
virtual type::AbstractObjectWrapper read(oatpp::parser::Caret& caret,
const type::Type* const type) const = 0;
oatpp::String writeToString(const type::AbstractObjectWrapper& variant) const {
@ -77,7 +77,7 @@ public:
* @return
*/
template<class Class>
typename Class::ObjectWrapper readFromCaret(oatpp::parser::ParsingCaret& caret) const {
typename Class::ObjectWrapper readFromCaret(oatpp::parser::Caret& caret) const {
auto type = Class::ObjectWrapper::Class::getType();
return oatpp::data::mapping::type::static_wrapper_cast<typename Class::ObjectWrapper::ObjectType>(read(caret, type));
}
@ -91,7 +91,7 @@ public:
template<class Class>
typename Class::ObjectWrapper readFromString(const oatpp::String& str) const {
auto type = Class::ObjectWrapper::Class::getType();
oatpp::parser::ParsingCaret caret(str);
oatpp::parser::Caret caret(str);
auto result = oatpp::data::mapping::type::static_wrapper_cast<typename Class::ObjectWrapper::ObjectType>(read(caret, type));
if(!result) {
throw oatpp::parser::ParsingError(caret.getErrorMessage(), caret.getErrorCode(), caret.getPosition());

View File

@ -22,7 +22,7 @@
*
***************************************************************************/
#include "ParsingCaret.hpp"
#include "Caret.hpp"
#include <stdlib.h>
#include <cstdlib>
@ -30,35 +30,74 @@
namespace oatpp { namespace parser {
const char* const ParsingCaret::ERROR_INVALID_INTEGER = "ERROR_INVALID_INTEGER";
const char* const ParsingCaret::ERROR_INVALID_FLOAT = "ERROR_INVALID_FLOAT";
const char* const ParsingCaret::ERROR_INVALID_BOOLEAN = "ERROR_INVALID_BOOLEAN";
const char* const ParsingCaret::ERROR_NO_OPEN_TAG = "ERROR_NO_OPEN_TAG";
const char* const ParsingCaret::ERROR_NO_CLOSE_TAG = "ERROR_NO_CLOSE_TAG";
const char* const ParsingCaret::ERROR_NAME_EXPECTED = "ERROR_NAME_EXPECTED";
const char* const Caret::ERROR_INVALID_INTEGER = "ERROR_INVALID_INTEGER";
const char* const Caret::ERROR_INVALID_FLOAT = "ERROR_INVALID_FLOAT";
const char* const Caret::ERROR_INVALID_BOOLEAN = "ERROR_INVALID_BOOLEAN";
const char* const Caret::ERROR_NO_OPEN_TAG = "ERROR_NO_OPEN_TAG";
const char* const Caret::ERROR_NO_CLOSE_TAG = "ERROR_NO_CLOSE_TAG";
const char* const Caret::ERROR_NAME_EXPECTED = "ERROR_NAME_EXPECTED";
/////////////////////////////////////////////////////////////////////////////////
// Caret::Label
void ParsingCaret::Label::start() {
Caret::Label::Label(Caret& caret)
: m_caret(&caret)
, m_start(caret.m_pos)
, m_end(-1)
{}
void Caret::Label::start() {
m_start = m_caret->m_pos;
m_end = -1;
}
void ParsingCaret::Label::end() {
void Caret::Label::end() {
m_end = m_caret->m_pos;
}
p_char8 ParsingCaret::Label::getData(){
p_char8 Caret::Label::getData(){
return &m_caret->m_data[m_start];
}
v_int32 ParsingCaret::Label::getSize(){
v_int32 Caret::Label::getSize(){
if(m_end == -1) {
return m_caret->m_pos - m_start;
}
return m_end - m_start;
}
oatpp::String ParsingCaret::Label::toString(bool saveAsOwnData){
/////////////////////////////////////////////////////////////////////////////////
// Caret::StateSaveGuard
Caret::StateSaveGuard::StateSaveGuard(Caret& caret)
: m_caret(caret)
, m_savedPosition(caret.m_pos)
, m_savedErrorMessage(caret.m_errorMessage)
, m_savedErrorCode(caret.m_errorCode)
{}
Caret::StateSaveGuard::~StateSaveGuard() {
m_caret.m_pos = m_savedPosition;
m_caret.m_errorMessage = m_savedErrorMessage;
m_caret.m_errorCode = m_savedErrorCode;
}
v_int32 Caret::StateSaveGuard::getSavedPosition() {
return m_savedPosition;
}
const char* Caret::StateSaveGuard::getSavedErrorMessage() {
return m_savedErrorMessage;
}
v_int32 Caret::StateSaveGuard::getSavedErrorCode() {
return m_savedErrorCode;
}
/////////////////////////////////////////////////////////////////////////////////
// Caret
oatpp::String Caret::Label::toString(bool saveAsOwnData){
v_int32 end = m_end;
if(end == -1){
end = m_caret->m_pos;
@ -66,11 +105,11 @@ namespace oatpp { namespace parser {
return oatpp::String((const char*)&m_caret->m_data[m_start], end - m_start, saveAsOwnData);
}
oatpp::String ParsingCaret::Label::toString(){
oatpp::String Caret::Label::toString(){
return toString(true);
}
std::string ParsingCaret::Label::std_str(){
std::string Caret::Label::std_str(){
v_int32 end = m_end;
if(end == -1){
end = m_caret->m_pos;
@ -79,11 +118,11 @@ namespace oatpp { namespace parser {
}
ParsingCaret::ParsingCaret(const char* text)
: ParsingCaret((p_char8)text, (v_int32) std::strlen(text))
Caret::Caret(const char* text)
: Caret((p_char8)text, (v_int32) std::strlen(text))
{}
ParsingCaret::ParsingCaret(p_char8 parseData, v_int32 dataSize)
Caret::Caret(p_char8 parseData, v_int32 dataSize)
: m_data(parseData)
, m_size(dataSize)
, m_pos(0)
@ -91,76 +130,76 @@ namespace oatpp { namespace parser {
, m_errorCode(0)
{}
ParsingCaret::ParsingCaret(const oatpp::String& str)
: ParsingCaret(str->getData(), str->getSize())
Caret::Caret(const oatpp::String& str)
: Caret(str->getData(), str->getSize())
{}
std::shared_ptr<ParsingCaret> ParsingCaret::createShared(const char* text){
return std::make_shared<ParsingCaret>(text);
std::shared_ptr<Caret> Caret::createShared(const char* text){
return std::make_shared<Caret>(text);
}
std::shared_ptr<ParsingCaret> ParsingCaret::createShared(p_char8 parseData, v_int32 dataSize){
return std::make_shared<ParsingCaret>(parseData, dataSize);
std::shared_ptr<Caret> Caret::createShared(p_char8 parseData, v_int32 dataSize){
return std::make_shared<Caret>(parseData, dataSize);
}
std::shared_ptr<ParsingCaret> ParsingCaret::createShared(const oatpp::String& str){
return std::make_shared<ParsingCaret>(str->getData(), str->getSize());
std::shared_ptr<Caret> Caret::createShared(const oatpp::String& str){
return std::make_shared<Caret>(str->getData(), str->getSize());
}
ParsingCaret::~ParsingCaret(){
Caret::~Caret(){
}
p_char8 ParsingCaret::getData(){
p_char8 Caret::getData(){
return m_data;
}
p_char8 ParsingCaret::getCurrData(){
p_char8 Caret::getCurrData(){
return &m_data[m_pos];
}
v_int32 ParsingCaret::getSize(){
v_int32 Caret::getSize(){
return m_size;
}
void ParsingCaret::setPosition(v_int32 position){
void Caret::setPosition(v_int32 position){
m_pos = position;
}
v_int32 ParsingCaret::getPosition(){
v_int32 Caret::getPosition(){
return m_pos;
}
void ParsingCaret::setError(const char* errorMessage, v_int32 errorCode){
void Caret::setError(const char* errorMessage, v_int32 errorCode){
m_errorMessage = errorMessage;
m_errorCode = errorCode;
}
const char* ParsingCaret::getErrorMessage() {
const char* Caret::getErrorMessage() {
return m_errorMessage;
}
v_int32 ParsingCaret::getErrorCode() {
v_int32 Caret::getErrorCode() {
return m_errorCode;
}
bool ParsingCaret::hasError(){
bool Caret::hasError(){
return m_errorMessage != nullptr;
}
void ParsingCaret::clearError(){
void Caret::clearError(){
m_errorMessage = nullptr;
m_errorCode = 0;
}
void ParsingCaret::inc(){
void Caret::inc(){
m_pos ++;
}
void ParsingCaret::inc(v_int32 amount){
void Caret::inc(v_int32 amount){
m_pos+= amount;
}
bool ParsingCaret::findNotBlankChar(){
bool Caret::skipBlankChars(){
while(m_pos < m_size){
v_char8 a = m_data[m_pos];
@ -172,16 +211,7 @@ namespace oatpp { namespace parser {
return false;
}
bool ParsingCaret::findNotSpaceChar(){
while(m_pos < m_size){
if(m_data[m_pos] != ' ')
return true;
m_pos ++;
}
return false;
}
bool ParsingCaret::skipChar(v_char8 c) {
bool Caret::skipChar(v_char8 c) {
while(m_pos < m_size){
if(m_data[m_pos] != c)
return true;
@ -190,7 +220,7 @@ namespace oatpp { namespace parser {
return false;
}
bool ParsingCaret::findChar(v_char8 c){
bool Caret::findChar(v_char8 c){
while(m_pos < m_size){
if(m_data[m_pos] == c)
@ -201,11 +231,11 @@ namespace oatpp { namespace parser {
return false;
}
bool ParsingCaret::findCharNotFromSet(const char* set){
bool Caret::findCharNotFromSet(const char* set){
return findCharNotFromSet((p_char8)set, (v_int32) std::strlen(set));
}
bool ParsingCaret::findCharNotFromSet(p_char8 set, v_int32 setSize){
bool Caret::findCharNotFromSet(p_char8 set, v_int32 setSize){
while(m_pos < m_size){
if(notAtCharFromSet(set, setSize)){
@ -218,11 +248,11 @@ namespace oatpp { namespace parser {
}
v_int32 ParsingCaret::findCharFromSet(const char* set){
v_int32 Caret::findCharFromSet(const char* set){
return findCharFromSet((p_char8) set, (v_int32) std::strlen(set));
}
v_int32 ParsingCaret::findCharFromSet(p_char8 set, v_int32 setSize){
v_int32 Caret::findCharFromSet(p_char8 set, v_int32 setSize){
while(m_pos < m_size){
@ -240,34 +270,7 @@ namespace oatpp { namespace parser {
}
bool ParsingCaret::findNextLine(){
bool nlFound = false;
while(m_pos < m_size){
if(nlFound){
if(m_data[m_pos] != '\n' && m_data[m_pos] != '\r'){
return true;
}
}else{
if(m_data[m_pos] == '\n' || m_data[m_pos] == '\r'){
nlFound = true;
}
}
m_pos ++;
}
return false;
}
bool ParsingCaret::findRN() {
bool Caret::findRN() {
while(m_pos < m_size){
if(m_data[m_pos] == '\r'){
@ -281,7 +284,7 @@ namespace oatpp { namespace parser {
return false;
}
bool ParsingCaret::skipRN() {
bool Caret::skipRN() {
if(m_pos + 1 < m_size && m_data[m_pos] == '\r' && m_data[m_pos + 1] == '\n'){
m_pos += 2;
return true;
@ -289,58 +292,63 @@ namespace oatpp { namespace parser {
return false;
}
bool ParsingCaret::isAtRN() {
bool Caret::isAtRN() {
return (m_pos + 1 < m_size && m_data[m_pos] == '\r' && m_data[m_pos + 1] == '\n');
}
v_int32 ParsingCaret::parseInteger(bool allowNegative){
bool negative = m_data[m_pos] == '-';
if(negative){
if(!allowNegative){
m_errorMessage = ERROR_INVALID_INTEGER;
return 0;
bool Caret::findROrN() {
while(m_pos < m_size) {
v_char8 a = m_data[m_pos];
if(a == '\r' || a == '\n') {
return true;
}
inc();
if(findNotSpaceChar() == false){
m_errorMessage = ERROR_INVALID_INTEGER;
return 0;
}
}
v_int32 ipos = m_pos;
while(m_pos < m_size && m_data[m_pos] >= '0' && m_data[m_pos] <= '9'){
m_pos ++;
}
v_int32 len = m_pos - ipos;
if(len > 0){
auto str = oatpp::String((const char*)&m_data[ipos], len, true);
v_int32 result = atoi((const char*)str->getData());
if(negative){
result = - result;
return false;
}
bool Caret::skipRNOrN() {
if(m_pos < m_size - 1 && m_data[m_pos] == '\r' && m_data[m_pos + 1] == '\n') {
m_pos += 2;
return true;
}
if(m_pos < m_size && m_data[m_pos] == '\n') {
m_pos ++;
return true;
}
return false;
}
bool Caret::skipAllRsAndNs() {
bool skipped = false;
while(m_pos < m_size) {
v_char8 a = m_data[m_pos];
if(a == '\r' || a == '\n') {
m_pos ++;
skipped = true;
} else {
break;
}
return result;
}else{
m_errorMessage = ERROR_INVALID_INTEGER;
return 0;
}
return skipped;
}
v_int32 ParsingCaret::parseInt32(){
long int Caret::parseInt(int base) {
char* end;
char* start = (char*)&m_data[m_pos];
v_int32 result = (v_float32) std::strtol(start, &end, 10);
long int result = std::strtol(start, &end, base);
if(start == end){
m_errorMessage = ERROR_INVALID_INTEGER;
}
m_pos = (v_int32)((v_int64) end - (v_int64) m_data);
return result;
}
unsigned long int Caret::parseUnsignedInt(int base) {
char* end;
char* start = (char*)&m_data[m_pos];
long int result = std::strtoul(start, &end, base);
if(start == end){
m_errorMessage = ERROR_INVALID_INTEGER;
}
@ -348,18 +356,7 @@ namespace oatpp { namespace parser {
return result;
}
v_int64 ParsingCaret::parseInt64(){
char* end;
char* start = (char*)&m_data[m_pos];
v_int64 result = std::strtol(start, &end, 10);
if(start == end){
m_errorMessage = ERROR_INVALID_INTEGER;
}
m_pos = (v_int32)((v_int64) end - (v_int64) m_data);
return result;
}
v_float32 ParsingCaret::parseFloat32(){
v_float32 Caret::parseFloat32(){
char* end;
char* start = (char*)&m_data[m_pos];
v_float32 result = std::strtof(start , &end);
@ -370,7 +367,7 @@ namespace oatpp { namespace parser {
return result;
}
v_float64 ParsingCaret::parseFloat64(){
v_float64 Caret::parseFloat64(){
char* end;
char* start = (char*)&m_data[m_pos];
v_float64 result = std::strtod(start , &end);
@ -381,21 +378,11 @@ namespace oatpp { namespace parser {
return result;
}
bool ParsingCaret::parseBoolean(const char* trueText, const char* falseText){
if(proceedIfFollowsText(trueText)){
return true;
} else if(proceedIfFollowsText(falseText)){
return false;
}
setError(ERROR_INVALID_BOOLEAN);
return false;
bool Caret::isAtText(const char* text, bool skipIfTrue){
return isAtText((p_char8)text, (v_int32) std::strlen(text), skipIfTrue);
}
bool ParsingCaret::proceedIfFollowsText(const char* text){
return proceedIfFollowsText((p_char8)text, (v_int32) std::strlen(text));
}
bool ParsingCaret::proceedIfFollowsText(p_char8 text, v_int32 textSize){
bool Caret::isAtText(p_char8 text, v_int32 textSize, bool skipIfTrue){
if(textSize <= m_size - m_pos){
@ -406,8 +393,10 @@ namespace oatpp { namespace parser {
}
}
m_pos = m_pos + textSize;
if(skipIfTrue) {
m_pos = m_pos + textSize;
}
return true;
@ -417,11 +406,11 @@ namespace oatpp { namespace parser {
}
bool ParsingCaret::proceedIfFollowsTextNCS(const char* text){
return proceedIfFollowsTextNCS((p_char8)text, (v_int32) std::strlen(text));
bool Caret::isAtTextNCS(const char* text, bool skipIfTrue){
return isAtTextNCS((p_char8)text, (v_int32) std::strlen(text), skipIfTrue);
}
bool ParsingCaret::proceedIfFollowsTextNCS(p_char8 text, v_int32 textSize){
bool Caret::isAtTextNCS(p_char8 text, v_int32 textSize, bool skipIfTrue){
if(textSize <= m_size - m_pos){
@ -443,8 +432,10 @@ namespace oatpp { namespace parser {
}
}
m_pos = m_pos + textSize;
if(skipIfTrue) {
m_pos = m_pos + textSize;
}
return true;
@ -454,39 +445,7 @@ namespace oatpp { namespace parser {
}
bool ParsingCaret::proceedIfFollowsWord(const char* text){
return proceedIfFollowsWord((p_char8)text, (v_int32) std::strlen(text));
}
bool ParsingCaret::proceedIfFollowsWord(p_char8 text, v_int32 textSize){
if(textSize <= m_size - m_pos){
for(v_int32 i = 0; i < textSize; i++){
if(text[i] != m_data[m_pos + i]){
return false;
}
}
v_char8 a = m_data[m_pos + textSize];
if(!(a >= '0' && a <= '9') && !(a >= 'a' && a <= 'z') &&
!(a >= 'A' && a <= 'Z') && a != '_'){
m_pos = m_pos + textSize;
return true;
}
}
return false;
}
oatpp::String ParsingCaret::parseStringEnclosed(char openChar, char closeChar, char escapeChar, bool saveAsOwnData){
oatpp::String Caret::parseStringEnclosed(char openChar, char closeChar, char escapeChar, bool saveAsOwnData){
if(m_data[m_pos] == openChar){
@ -517,7 +476,7 @@ namespace oatpp { namespace parser {
}
oatpp::String ParsingCaret::parseName(bool saveAsOwnData){
oatpp::String Caret::parseName(bool saveAsOwnData){
v_int32 ipos = m_pos;
while(m_pos < m_size){
@ -551,36 +510,16 @@ namespace oatpp { namespace parser {
}
bool ParsingCaret::findText(p_char8 text, v_int32 textSize) {
bool Caret::findText(p_char8 text, v_int32 textSize) {
m_pos = (v_int32)(std::search(&m_data[m_pos], &m_data[m_size], text, text + textSize) - m_data);
return m_pos != m_size;
}
oatpp::String ParsingCaret::findTextFromList(const std::shared_ptr<oatpp::collection::LinkedList<oatpp::String>>& list){
while(m_pos < m_size){
auto currNode = list->getFirstNode();
while(currNode != nullptr){
auto str = currNode->getData();
if(proceedIfFollowsText(str->getData(), str->getSize())){
return str;
}
currNode = currNode->getNext();
}
m_pos++;
}
return nullptr;
}
bool ParsingCaret::notAtCharFromSet(const char* set) const{
bool Caret::notAtCharFromSet(const char* set) const{
return notAtCharFromSet((p_char8)set, (v_int32) std::strlen(set));
}
bool ParsingCaret::notAtCharFromSet(p_char8 set, v_int32 setSize) const{
bool Caret::notAtCharFromSet(p_char8 set, v_int32 setSize) const{
v_char8 a = m_data[m_pos];
@ -594,25 +533,25 @@ namespace oatpp { namespace parser {
}
bool ParsingCaret::isAtChar(v_char8 c) const{
bool Caret::isAtChar(v_char8 c) const{
return m_data[m_pos] == c;
}
bool ParsingCaret::isAtBlankChar() const{
bool Caret::isAtBlankChar() const{
v_char8 a = m_data[m_pos];
return (a == ' ' || a == '\t' || a == '\n' || a == '\r' || a == '\b' || a == '\f');
}
bool ParsingCaret::isAtDigitChar() const{
bool Caret::isAtDigitChar() const{
v_char8 a = m_data[m_pos];
return (a >= '0' && a <= '9');
}
bool ParsingCaret::canContinueAtChar(v_char8 c) const{
bool Caret::canContinueAtChar(v_char8 c) const{
return m_pos < m_size && m_errorMessage == nullptr && m_data[m_pos] == c;
}
bool ParsingCaret::canContinueAtChar(v_char8 c, v_int32 skipChars){
bool Caret::canContinueAtChar(v_char8 c, v_int32 skipChars){
if(m_pos < m_size && m_errorMessage == nullptr && m_data[m_pos] == c){
m_pos = m_pos + skipChars;
@ -621,11 +560,11 @@ namespace oatpp { namespace parser {
return false;
}
bool ParsingCaret::canContinue() const{
bool Caret::canContinue() const{
return m_pos < m_size && m_errorMessage == nullptr;
}
bool ParsingCaret::isEnd() const{
bool Caret::isEnd() const{
return m_pos >= m_size;
}

View File

@ -22,15 +22,18 @@
*
***************************************************************************/
#ifndef oatpp_parser_ParsingCaret_hpp
#define oatpp_parser_ParsingCaret_hpp
#ifndef oatpp_parser_Caret_hpp
#define oatpp_parser_Caret_hpp
#include "oatpp/core/collection/LinkedList.hpp"
#include "oatpp/core/Types.hpp"
namespace oatpp { namespace parser {
class ParsingCaret : public base::Controllable{
/**
* Helper class to do parsing operations
*/
class Caret {
public:
static const char* const ERROR_INVALID_INTEGER;
static const char* const ERROR_INVALID_FLOAT;
@ -39,18 +42,15 @@ public:
static const char* const ERROR_NO_CLOSE_TAG;
static const char* const ERROR_NAME_EXPECTED;
public:
class Label {
private:
ParsingCaret* m_caret;
Caret* m_caret;
v_int32 m_start;
v_int32 m_end;
public:
Label(ParsingCaret& caret)
: m_caret(&caret)
, m_start(caret.m_pos)
, m_end(-1)
{}
Label(Caret& caret);
void start();
void end();
@ -62,37 +62,40 @@ public:
};
class PositionSaveGuard {
class StateSaveGuard {
private:
ParsingCaret& m_caret;
Caret& m_caret;
v_int32 m_savedPosition;
const char* m_savedErrorMessage;
v_int32 m_savedErrorCode;
public:
PositionSaveGuard(ParsingCaret& caret)
: m_caret(caret)
, m_savedPosition(caret.m_pos)
{}
~PositionSaveGuard() {
m_caret.m_pos = m_savedPosition;
}
StateSaveGuard(Caret& caret);
~StateSaveGuard();
v_int32 getSavedPosition();
const char* getSavedErrorMessage();
v_int32 getSavedErrorCode();
};
private:
p_char8 m_data;
v_int32 m_size;
v_int32 m_pos;
p_char8 m_data;
v_int32 m_size;
v_int32 m_pos;
const char* m_errorMessage;
v_int32 m_errorCode; // optional
v_int32 m_errorCode;
public:
ParsingCaret(const char* text);
ParsingCaret(p_char8 parseData, v_int32 dataSize);
ParsingCaret(const oatpp::String& str);
Caret(const char* text);
Caret(p_char8 parseData, v_int32 dataSize);
Caret(const oatpp::String& str);
public:
static std::shared_ptr<ParsingCaret> createShared(const char* text);
static std::shared_ptr<ParsingCaret> createShared(p_char8 parseData, v_int32 dataSize);
static std::shared_ptr<ParsingCaret> createShared(const oatpp::String& str);
static std::shared_ptr<Caret> createShared(const char* text);
static std::shared_ptr<Caret> createShared(p_char8 parseData, v_int32 dataSize);
static std::shared_ptr<Caret> createShared(const oatpp::String& str);
virtual ~ParsingCaret();
virtual ~Caret();
p_char8 getData();
p_char8 getCurrData();
@ -111,10 +114,9 @@ public:
void inc();
void inc(v_int32 amount);
bool findNotBlankChar(); // findCharNotFromSet(" \n\r\t");
bool skipBlankChars();
bool skipChar(v_char8 c);
bool findNotSpaceChar();
bool findChar(v_char8 c);
bool findCharNotFromSet(const char* set);
@ -122,36 +124,110 @@ public:
v_int32 findCharFromSet(const char* set);
v_int32 findCharFromSet(p_char8 set, v_int32 setSize);
bool findNextLine();
bool findRN();
bool skipRN();
bool isAtRN();
v_int32 parseInteger(bool allowNegative); // Will setError if error
v_int32 parseInt32();
v_int64 parseInt64();
/**
* Find '\r' char of '\n' char
* @return true if found '\r' or '\n'
*/
bool findROrN();
/**
* if at "\r\n" - skip.
* if at "\n" - skip.
* @return true if position changed
*/
bool skipRNOrN();
/**
* skip any sequence of '\r' and '\n'
* @return true if position changed
*/
bool skipAllRsAndNs();
/**
* parse integer value starting from the current position.
* Using function std::strtol()
*
* Warning: position may go out of @Caret::getSize() bound.
*
* @param base - base is passed to std::strtol function
* @return parsed value
*/
long int parseInt(int base = 10);
/**
* parse integer value starting from the current position.
* Using function std::strtoul()
*
* Warning: position may go out of @Caret::getSize() bound.
*
* @param base - base is passed to std::strtoul function
* @return parsed value
*/
unsigned long int parseUnsignedInt(int base = 10);
/**
* parse float value starting from the current position.
* Using function std::strtof()
*
* Warning: position may go out of @Caret::getSize() bound.
*
* @return parsed value
*/
v_float32 parseFloat32();
/**
* parse float value starting from the current position.
* Using function std::strtod()
*
* Warning: position may go out of @Caret::getSize() bound.
*
* @return parsed value
*/
v_float64 parseFloat64();
bool parseBoolean(const char* trueText, const char* falseText); // will setError if error
bool proceedIfFollowsText(const char* text); // not increases pos if false
bool proceedIfFollowsText(p_char8 text, v_int32 textSize); // not increases pos if false
bool proceedIfFollowsTextNCS(const char* text); // NotCaseSensative
bool proceedIfFollowsTextNCS(p_char8 text, v_int32 textSize); // not increases pos if false
bool proceedIfFollowsWord(const char* text); // not increases pos if false
bool proceedIfFollowsWord(p_char8 text, v_int32 textSize); // not increases pos if false
/**
* Check if follows text
* @param text
* @param skipIfTrue - increase position if true
* @return
*/
bool isAtText(const char* text, bool skipIfTrue = false);
/**
* Check if follows text
* @param text
* @param textSize
* @param skipIfTrue - increase position if true
* @return
*/
bool isAtText(p_char8 text, v_int32 textSize, bool skipIfTrue = false);
/**
* Check if follows text (Not Case Sensitive)
* @param text
* @param skipIfTrue - increase position if true
* @return
*/
bool isAtTextNCS(const char* text, bool skipIfTrue = false);
/**
* Check if follows text (Not Case Sensitive)
* @param text
* @param textSize
* @param skipIfTrue - increase position if true
* @return
*/
bool isAtTextNCS(p_char8 text, v_int32 textSize, bool skipIfTrue = false);
oatpp::String parseStringEnclosed(char openChar, char closeChar, char escapeChar, bool saveAsOwnData);
oatpp::String parseName(bool saveAsOwnData);
bool findText(p_char8 text, v_int32 textSize);
oatpp::String findTextFromList(const std::shared_ptr<oatpp::collection::LinkedList<oatpp::String>>& list);
bool notAtCharFromSet(const char* set) const;
bool notAtCharFromSet(p_char8 set, v_int32 setSize) const;
@ -170,4 +246,4 @@ public:
#endif /* oatpp_parser_ParsingCaret_hpp */
#endif /* oatpp_parser_Caret_hpp */

View File

@ -28,7 +28,7 @@
namespace oatpp { namespace network {
oatpp::String Url::Parser::parseScheme(oatpp::parser::ParsingCaret& caret) {
oatpp::String Url::Parser::parseScheme(oatpp::parser::Caret& caret) {
v_int32 pos0 = caret.getPosition();
caret.findChar(':');
v_int32 size = caret.getPosition() - pos0;
@ -41,7 +41,7 @@ oatpp::String Url::Parser::parseScheme(oatpp::parser::ParsingCaret& caret) {
return nullptr;
}
Url::Authority Url::Parser::parseAuthority(oatpp::parser::ParsingCaret& caret) {
Url::Authority Url::Parser::parseAuthority(oatpp::parser::Caret& caret) {
p_char8 data = caret.getData();
v_int32 pos0 = caret.getPosition();
@ -94,8 +94,8 @@ Url::Authority Url::Parser::parseAuthority(oatpp::parser::ParsingCaret& caret) {
}
oatpp::String Url::Parser::parsePath(oatpp::parser::ParsingCaret& caret) {
oatpp::parser::ParsingCaret::Label label(caret);
oatpp::String Url::Parser::parsePath(oatpp::parser::Caret& caret) {
oatpp::parser::Caret::Label label(caret);
caret.findCharFromSet((p_char8)"?#", 2);
if(label.getSize() > 0) {
return label.toString(true);
@ -103,17 +103,17 @@ oatpp::String Url::Parser::parsePath(oatpp::parser::ParsingCaret& caret) {
return nullptr;
}
void Url::Parser::parseQueryParamsToMap(Url::Parameters& params, oatpp::parser::ParsingCaret& caret) {
void Url::Parser::parseQueryParamsToMap(Url::Parameters& params, oatpp::parser::Caret& caret) {
if(caret.findChar('?')) {
do {
caret.inc();
oatpp::parser::ParsingCaret::Label nameLabel(caret);
oatpp::parser::Caret::Label nameLabel(caret);
if(caret.findChar('=')) {
nameLabel.end();
caret.inc();
oatpp::parser::ParsingCaret::Label valueLabel(caret);
oatpp::parser::Caret::Label valueLabel(caret);
caret.findChar('&');
params.put(nameLabel.toString(), valueLabel.toString());
}
@ -124,11 +124,11 @@ void Url::Parser::parseQueryParamsToMap(Url::Parameters& params, oatpp::parser::
}
void Url::Parser::parseQueryParamsToMap(Url::Parameters& params, const oatpp::String& str) {
oatpp::parser::ParsingCaret caret(str.getPtr());
oatpp::parser::Caret caret(str.getPtr());
parseQueryParamsToMap(params, caret);
}
std::shared_ptr<Url::Parameters> Url::Parser::parseQueryParams(oatpp::parser::ParsingCaret& caret) {
std::shared_ptr<Url::Parameters> Url::Parser::parseQueryParams(oatpp::parser::Caret& caret) {
auto params = Url::Parameters::createShared();
parseQueryParamsToMap(*params, caret);
return params;
@ -140,11 +140,11 @@ std::shared_ptr<Url::Parameters> Url::Parser::parseQueryParams(const oatpp::Stri
return params;
}
Url Url::Parser::parseUrl(oatpp::parser::ParsingCaret& caret) {
Url Url::Parser::parseUrl(oatpp::parser::Caret& caret) {
Url result;
result.scheme = parseScheme(caret);
if(caret.canContinueAtChar(':', 1)) {
if(caret.proceedIfFollowsText((p_char8)"//", 2)) {
if(caret.isAtText((p_char8)"//", 2, true)) {
if(!caret.isAtChar('/')) {
result.authority = parseAuthority(caret);
}

View File

@ -25,7 +25,7 @@
#ifndef oatpp_network_Url_hpp
#define oatpp_network_Url_hpp
#include "oatpp/core/parser/ParsingCaret.hpp"
#include "oatpp/core/parser/Caret.hpp"
#include "oatpp/core/collection/ListMap.hpp"
#include "oatpp/core/Types.hpp"
@ -53,7 +53,7 @@ public:
* returns lowercase string before ':' char
* caret should be at the first char of the scheme
*/
static oatpp::String parseScheme(oatpp::parser::ParsingCaret& caret);
static oatpp::String parseScheme(oatpp::parser::Caret& caret);
/**
* parse utl authority components.
@ -61,19 +61,19 @@ public:
* inclusion of password in userinfo is deprecated and ignored here
* caret should be at the first char of the authority (not at "//")
*/
static Url::Authority parseAuthority(oatpp::parser::ParsingCaret& caret);
static Url::Authority parseAuthority(oatpp::parser::Caret& caret);
/**
* parse path of the url
* caret should be at the first char of the path
*/
static oatpp::String parsePath(oatpp::parser::ParsingCaret& caret);
static oatpp::String parsePath(oatpp::parser::Caret& caret);
/**
* parse query params in form of "?<paramName>=<paramValue>&<paramName>=<paramValue>..." referred by ParsingCaret
* and put that params to Parameters map
*/
static void parseQueryParamsToMap(Url::Parameters& params, oatpp::parser::ParsingCaret& caret);
static void parseQueryParamsToMap(Url::Parameters& params, oatpp::parser::Caret& caret);
/**
* parse query params in form of "?<paramName>=<paramValue>&<paramName>=<paramValue>..." referred by str
@ -84,7 +84,7 @@ public:
/**
* parse query params in form of "?<paramName>=<paramValue>&<paramName>=<paramValue>..." referred by ParsingCaret
*/
static std::shared_ptr<Url::Parameters> parseQueryParams(oatpp::parser::ParsingCaret& caret);
static std::shared_ptr<Url::Parameters> parseQueryParams(oatpp::parser::Caret& caret);
/**
* parse query params in form of "?<paramName>=<paramValue>&<paramName>=<paramValue>..." referred by str
@ -94,7 +94,7 @@ public:
/**
* parse Url
*/
static Url parseUrl(oatpp::parser::ParsingCaret& caret);
static Url parseUrl(oatpp::parser::Caret& caret);
};

View File

@ -25,7 +25,7 @@
#ifndef oatpp_parser_json_Utils_hpp
#define oatpp_parser_json_Utils_hpp
#include "oatpp/core/parser/ParsingCaret.hpp"
#include "oatpp/core/parser/Caret.hpp"
#include "oatpp/core/Types.hpp"
#include <string>
@ -68,7 +68,7 @@ public:
public:
typedef oatpp::String String;
typedef oatpp::parser::ParsingCaret ParsingCaret;
typedef oatpp::parser::Caret ParsingCaret;
private:
static v_int32 escapeUtf8Char(p_char8 sequence, p_char8 buffer);
static v_int32 calcEscapedStringSize(p_char8 data, v_int32 size, v_int32& safeSize);

View File

@ -29,7 +29,7 @@
namespace oatpp { namespace parser { namespace json { namespace mapping {
void Deserializer::skipScope(oatpp::parser::ParsingCaret& caret, v_char8 charOpen, v_char8 charClose){
void Deserializer::skipScope(oatpp::parser::Caret& caret, v_char8 charOpen, v_char8 charClose){
p_char8 data = caret.getData();
v_int32 size = caret.getSize();
@ -63,7 +63,7 @@ void Deserializer::skipScope(oatpp::parser::ParsingCaret& caret, v_char8 charOpe
}
}
void Deserializer::skipString(oatpp::parser::ParsingCaret& caret){
void Deserializer::skipString(oatpp::parser::Caret& caret){
p_char8 data = caret.getData();
v_int32 size = caret.getSize();
v_int32 pos = caret.getPosition();
@ -83,7 +83,7 @@ void Deserializer::skipString(oatpp::parser::ParsingCaret& caret){
}
}
void Deserializer::skipToken(oatpp::parser::ParsingCaret& caret){
void Deserializer::skipToken(oatpp::parser::Caret& caret){
p_char8 data = caret.getData();
v_int32 size = caret.getSize();
v_int32 pos = caret.getPosition();
@ -98,7 +98,7 @@ void Deserializer::skipToken(oatpp::parser::ParsingCaret& caret){
}
}
void Deserializer::skipValue(oatpp::parser::ParsingCaret& caret){
void Deserializer::skipValue(oatpp::parser::Caret& caret){
if(caret.isAtChar('{')){
skipScope(caret, '{', '}');
} else if(caret.isAtChar('[')){
@ -110,58 +110,65 @@ void Deserializer::skipValue(oatpp::parser::ParsingCaret& caret){
}
}
Deserializer::AbstractObjectWrapper Deserializer::readStringValue(oatpp::parser::ParsingCaret& caret){
if(caret.proceedIfFollowsText("null")){
Deserializer::AbstractObjectWrapper Deserializer::readStringValue(oatpp::parser::Caret& caret){
if(caret.isAtText("null", true)){
return AbstractObjectWrapper(String::Class::getType());
} else {
return AbstractObjectWrapper(oatpp::parser::json::Utils::parseString(caret).getPtr(), String::Class::getType());
}
}
Deserializer::AbstractObjectWrapper Deserializer::readInt32Value(oatpp::parser::ParsingCaret& caret){
if(caret.proceedIfFollowsText("null")){
Deserializer::AbstractObjectWrapper Deserializer::readInt32Value(oatpp::parser::Caret& caret){
if(caret.isAtText("null", true)){
return AbstractObjectWrapper(Int32::ObjectWrapper::Class::getType());
} else {
return AbstractObjectWrapper(Int32::ObjectType::createAbstract(caret.parseInt32()), Int32::ObjectWrapper::Class::getType());
return AbstractObjectWrapper(Int32::ObjectType::createAbstract(caret.parseInt()), Int32::ObjectWrapper::Class::getType());
}
}
Deserializer::AbstractObjectWrapper Deserializer::readInt64Value(oatpp::parser::ParsingCaret& caret){
if(caret.proceedIfFollowsText("null")){
Deserializer::AbstractObjectWrapper Deserializer::readInt64Value(oatpp::parser::Caret& caret){
if(caret.isAtText("null", true)){
return AbstractObjectWrapper(Int64::ObjectWrapper::Class::getType());
} else {
return AbstractObjectWrapper(Int64::ObjectType::createAbstract(caret.parseInt64()), Int64::ObjectWrapper::Class::getType());
return AbstractObjectWrapper(Int64::ObjectType::createAbstract(caret.parseInt()), Int64::ObjectWrapper::Class::getType());
}
}
Deserializer::AbstractObjectWrapper Deserializer::readFloat32Value(oatpp::parser::ParsingCaret& caret){
if(caret.proceedIfFollowsText("null")){
Deserializer::AbstractObjectWrapper Deserializer::readFloat32Value(oatpp::parser::Caret& caret){
if(caret.isAtText("null", true)){
return AbstractObjectWrapper(Float32::ObjectWrapper::Class::getType());
} else {
return AbstractObjectWrapper(Float32::ObjectType::createAbstract(caret.parseFloat32()), Float32::ObjectWrapper::Class::getType());
}
}
Deserializer::AbstractObjectWrapper Deserializer::readFloat64Value(oatpp::parser::ParsingCaret& caret){
if(caret.proceedIfFollowsText("null")){
Deserializer::AbstractObjectWrapper Deserializer::readFloat64Value(oatpp::parser::Caret& caret){
if(caret.isAtText("null", true)){
return AbstractObjectWrapper(Float64::ObjectWrapper::Class::getType());
} else {
return AbstractObjectWrapper(Float64::ObjectType::createAbstract(caret.parseFloat64()), Float64::ObjectWrapper::Class::getType());
}
}
Deserializer::AbstractObjectWrapper Deserializer::readBooleanValue(oatpp::parser::ParsingCaret& caret){
if(caret.proceedIfFollowsText("null")){
Deserializer::AbstractObjectWrapper Deserializer::readBooleanValue(oatpp::parser::Caret& caret){
if(caret.isAtText("null", true)){
return AbstractObjectWrapper(Boolean::ObjectWrapper::Class::getType());
} else {
return AbstractObjectWrapper(Boolean::ObjectType::createAbstract(caret.parseBoolean("true", "false")), Boolean::ObjectWrapper::Class::getType());
if(caret.isAtText("true", true)) {
return AbstractObjectWrapper(Boolean::ObjectType::createAbstract(true), Boolean::ObjectWrapper::Class::getType());
} else if(caret.isAtText("false", true)) {
return AbstractObjectWrapper(Boolean::ObjectType::createAbstract(false), Boolean::ObjectWrapper::Class::getType());
} else {
caret.setError("[oatpp::parser::json::mapping::Deserializer::readBooleanValue()]: Error. 'true' or 'false' - expected.", ERROR_CODE_VALUE_BOOLEAN);
return AbstractObjectWrapper(Boolean::ObjectWrapper::Class::getType());
}
}
}
Deserializer::AbstractObjectWrapper Deserializer::readObjectValue(const Type* const type,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
const std::shared_ptr<Config>& config){
if(caret.proceedIfFollowsText("null")){
if(caret.isAtText("null", true)){
return AbstractObjectWrapper::empty();
} else {
return readObject(type, caret, config);
@ -169,9 +176,9 @@ Deserializer::AbstractObjectWrapper Deserializer::readObjectValue(const Type* co
}
Deserializer::AbstractObjectWrapper Deserializer::readListValue(const Type* const type,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
const std::shared_ptr<Config>& config){
if(caret.proceedIfFollowsText("null")){
if(caret.isAtText("null", true)){
return AbstractObjectWrapper::empty();
} else {
return readList(type, caret, config);
@ -179,9 +186,9 @@ Deserializer::AbstractObjectWrapper Deserializer::readListValue(const Type* cons
}
Deserializer::AbstractObjectWrapper Deserializer::readListMapValue(const Type* const type,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
const std::shared_ptr<Config>& config){
if(caret.proceedIfFollowsText("null")){
if(caret.isAtText("null", true)){
return AbstractObjectWrapper::empty();
} else {
return readListMap(type, caret, config);
@ -189,7 +196,7 @@ Deserializer::AbstractObjectWrapper Deserializer::readListMapValue(const Type* c
}
Deserializer::AbstractObjectWrapper Deserializer::readValue(const Type* const type,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
const std::shared_ptr<Config>& config){
auto typeName = type->name;
@ -220,7 +227,7 @@ Deserializer::AbstractObjectWrapper Deserializer::readValue(const Type* const ty
}
Deserializer::AbstractObjectWrapper Deserializer::readList(const Type* type,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
const std::shared_ptr<Config>& config){
if(caret.canContinueAtChar('[', 1)) {
@ -231,18 +238,18 @@ Deserializer::AbstractObjectWrapper Deserializer::readList(const Type* type,
Type* itemType = *type->params.begin();
caret.findNotBlankChar();
caret.skipBlankChars();
while(!caret.isAtChar(']') && caret.canContinue()){
caret.findNotBlankChar();
caret.skipBlankChars();
auto item = readValue(itemType, caret, config);
if(caret.hasError()){
return AbstractObjectWrapper::empty();
}
list->addPolymorphicItem(item);
caret.findNotBlankChar();
caret.skipBlankChars();
caret.canContinueAtChar(',', 1);
@ -264,7 +271,7 @@ Deserializer::AbstractObjectWrapper Deserializer::readList(const Type* type,
}
Deserializer::AbstractObjectWrapper Deserializer::readListMap(const Type* type,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
const std::shared_ptr<Config>& config){
if(caret.canContinueAtChar('{', 1)) {
@ -280,27 +287,27 @@ Deserializer::AbstractObjectWrapper Deserializer::readListMap(const Type* type,
}
Type* valueType = *it;
caret.findNotBlankChar();
caret.skipBlankChars();
while (!caret.isAtChar('}') && caret.canContinue()) {
caret.findNotBlankChar();
caret.skipBlankChars();
auto key = Utils::parseString(caret);
if(caret.hasError()){
return AbstractObjectWrapper::empty();
}
caret.findNotBlankChar();
caret.skipBlankChars();
if(!caret.canContinueAtChar(':', 1)){
caret.setError("[oatpp::parser::json::mapping::Deserializer::readListMap()]: Error. ':' - expected", ERROR_CODE_OBJECT_SCOPE_COLON_MISSING);
return AbstractObjectWrapper::empty();
}
caret.findNotBlankChar();
caret.skipBlankChars();
map->putPolymorphicItem(key, readValue(valueType, caret, config));
caret.findNotBlankChar();
caret.skipBlankChars();
caret.canContinueAtChar(',', 1);
}
@ -323,7 +330,7 @@ Deserializer::AbstractObjectWrapper Deserializer::readListMap(const Type* type,
}
Deserializer::AbstractObjectWrapper Deserializer::readObject(const Type* type,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
const std::shared_ptr<Config>& config){
if(caret.canContinueAtChar('{', 1)) {
@ -331,11 +338,11 @@ Deserializer::AbstractObjectWrapper Deserializer::readObject(const Type* type,
auto object = type->creator();
const auto& fieldsMap = type->properties->getMap();
caret.findNotBlankChar();
caret.skipBlankChars();
while (!caret.isAtChar('}') && caret.canContinue()) {
caret.findNotBlankChar();
caret.skipBlankChars();
auto key = Utils::parseStringToStdString(caret);
if(caret.hasError()){
return AbstractObjectWrapper::empty();
@ -344,31 +351,31 @@ Deserializer::AbstractObjectWrapper Deserializer::readObject(const Type* type,
auto fieldIterator = fieldsMap.find(key);
if(fieldIterator != fieldsMap.end()){
caret.findNotBlankChar();
caret.skipBlankChars();
if(!caret.canContinueAtChar(':', 1)){
caret.setError("[oatpp::parser::json::mapping::Deserializer::readObject()]: Error. ':' - expected", ERROR_CODE_OBJECT_SCOPE_COLON_MISSING);
return AbstractObjectWrapper::empty();
}
caret.findNotBlankChar();
caret.skipBlankChars();
auto field = fieldIterator->second;
field->set(object.get(), readValue(field->type, caret, config));
} else if (config->allowUnknownFields) {
caret.findNotBlankChar();
caret.skipBlankChars();
if(!caret.canContinueAtChar(':', 1)){
caret.setError("[oatpp::parser::json::mapping::Deserializer::readObject()/if(config->allowUnknownFields){}]: Error. ':' - expected", ERROR_CODE_OBJECT_SCOPE_COLON_MISSING);
return AbstractObjectWrapper::empty();
}
caret.findNotBlankChar();
caret.skipBlankChars();
skipValue(caret);
} else {
caret.setError("[oatpp::parser::json::mapping::Deserializer::readObject()]: Error. Unknown field", ERROR_CODE_OBJECT_SCOPE_UNKNOWN_FIELD);
return AbstractObjectWrapper::empty();
}
caret.findNotBlankChar();
caret.skipBlankChars();
caret.canContinueAtChar(',', 1);
}

View File

@ -30,7 +30,7 @@
#include "oatpp/core/data/mapping/type/Primitive.hpp"
#include "oatpp/core/data/mapping/type/Type.hpp"
#include "oatpp/core/parser/ParsingCaret.hpp"
#include "oatpp/core/parser/Caret.hpp"
#include "oatpp/core/collection/LinkedList.hpp"
#include "oatpp/core/Types.hpp"
@ -105,49 +105,54 @@ public:
*/
static constexpr v_int32 ERROR_CODE_ARRAY_SCOPE_CLOSE = 6;
/**
* "'true' or 'false' - expected"
*/
static constexpr v_int32 ERROR_CODE_VALUE_BOOLEAN = 7;
private:
static void skipScope(oatpp::parser::ParsingCaret& caret, v_char8 charOpen, v_char8 charClose);
static void skipString(oatpp::parser::ParsingCaret& caret);
static void skipToken(oatpp::parser::ParsingCaret& caret);
static void skipValue(oatpp::parser::ParsingCaret& caret);
static void skipScope(oatpp::parser::Caret& caret, v_char8 charOpen, v_char8 charClose);
static void skipString(oatpp::parser::Caret& caret);
static void skipToken(oatpp::parser::Caret& caret);
static void skipValue(oatpp::parser::Caret& caret);
static AbstractObjectWrapper readStringValue(oatpp::parser::ParsingCaret& caret);
static AbstractObjectWrapper readInt32Value(oatpp::parser::ParsingCaret& caret);
static AbstractObjectWrapper readInt64Value(oatpp::parser::ParsingCaret& caret);
static AbstractObjectWrapper readFloat32Value(oatpp::parser::ParsingCaret& caret);
static AbstractObjectWrapper readFloat64Value(oatpp::parser::ParsingCaret& caret);
static AbstractObjectWrapper readBooleanValue(oatpp::parser::ParsingCaret& caret);
static AbstractObjectWrapper readStringValue(oatpp::parser::Caret& caret);
static AbstractObjectWrapper readInt32Value(oatpp::parser::Caret& caret);
static AbstractObjectWrapper readInt64Value(oatpp::parser::Caret& caret);
static AbstractObjectWrapper readFloat32Value(oatpp::parser::Caret& caret);
static AbstractObjectWrapper readFloat64Value(oatpp::parser::Caret& caret);
static AbstractObjectWrapper readBooleanValue(oatpp::parser::Caret& caret);
static AbstractObjectWrapper readObjectValue(const Type* const type,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
const std::shared_ptr<Config>& config);
static AbstractObjectWrapper readListValue(const Type* const type,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
const std::shared_ptr<Config>& config);
static AbstractObjectWrapper readListMapValue(const Type* const type,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
const std::shared_ptr<Config>& config);
static AbstractObjectWrapper readValue(const Type* const type,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
const std::shared_ptr<Config>& config);
static AbstractObjectWrapper readList(const Type* const type,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
const std::shared_ptr<Config>& config);
static AbstractObjectWrapper readListMap(const Type* const type,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
const std::shared_ptr<Config>& config);
static AbstractObjectWrapper readObject(const Type* const type,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
const std::shared_ptr<Config>& config);
public:
static AbstractObjectWrapper deserialize(oatpp::parser::ParsingCaret& caret,
static AbstractObjectWrapper deserialize(oatpp::parser::Caret& caret,
const std::shared_ptr<Config>& config,
const Type* const type) {
if(type->name == oatpp::data::mapping::type::__class::AbstractObject::CLASS_NAME){

View File

@ -59,7 +59,7 @@ public:
}
oatpp::data::mapping::type::AbstractObjectWrapper
read(oatpp::parser::ParsingCaret& caret,
read(oatpp::parser::Caret& caret,
const oatpp::data::mapping::type::Type* const type) const override {
return Deserializer::deserialize(caret, deserializerConfig, type);
}

View File

@ -32,7 +32,7 @@
#include "oatpp/core/data/mapping/type/Type.hpp"
#include "oatpp/core/data/stream/ChunkedBuffer.hpp"
#include "oatpp/core/parser/ParsingCaret.hpp"
#include "oatpp/core/parser/Caret.hpp"
#include "oatpp/core/collection/LinkedList.hpp"
#include "oatpp/core/Types.hpp"

View File

@ -134,9 +134,9 @@ oatpp::String Range::toString() const {
return stream.toString();
}
Range Range::parse(oatpp::parser::ParsingCaret& caret) {
Range Range::parse(oatpp::parser::Caret& caret) {
oatpp::parser::ParsingCaret::Label unitsLabel(caret);
oatpp::parser::Caret::Label unitsLabel(caret);
if(caret.findChar('=')) {
unitsLabel.end();
@ -146,7 +146,7 @@ Range Range::parse(oatpp::parser::ParsingCaret& caret) {
return Range();
}
oatpp::parser::ParsingCaret::Label startLabel(caret);
oatpp::parser::Caret::Label startLabel(caret);
if(caret.findChar('-')) {
startLabel.end();
caret.inc();
@ -155,7 +155,7 @@ Range Range::parse(oatpp::parser::ParsingCaret& caret) {
return Range();
}
oatpp::parser::ParsingCaret::Label endLabel(caret);
oatpp::parser::Caret::Label endLabel(caret);
caret.findRN();
endLabel.end();
@ -166,7 +166,7 @@ Range Range::parse(oatpp::parser::ParsingCaret& caret) {
}
Range Range::parse(const oatpp::String& str) {
oatpp::parser::ParsingCaret caret(str);
oatpp::parser::Caret caret(str);
return parse(caret);
}
@ -186,9 +186,9 @@ oatpp::String ContentRange::toString() const {
return stream.toString();
}
ContentRange ContentRange::parse(oatpp::parser::ParsingCaret& caret) {
ContentRange ContentRange::parse(oatpp::parser::Caret& caret) {
oatpp::parser::ParsingCaret::Label unitsLabel(caret);
oatpp::parser::Caret::Label unitsLabel(caret);
if(caret.findChar(' ')) {
unitsLabel.end();
@ -198,7 +198,7 @@ ContentRange ContentRange::parse(oatpp::parser::ParsingCaret& caret) {
return ContentRange();
}
oatpp::parser::ParsingCaret::Label startLabel(caret);
oatpp::parser::Caret::Label startLabel(caret);
if(caret.findChar('-')) {
startLabel.end();
caret.inc();
@ -207,7 +207,7 @@ ContentRange ContentRange::parse(oatpp::parser::ParsingCaret& caret) {
return ContentRange();
}
oatpp::parser::ParsingCaret::Label endLabel(caret);
oatpp::parser::Caret::Label endLabel(caret);
if(caret.findChar('/')) {
endLabel.end();
caret.inc();
@ -216,7 +216,7 @@ ContentRange ContentRange::parse(oatpp::parser::ParsingCaret& caret) {
return ContentRange();
}
oatpp::parser::ParsingCaret::Label sizeLabel(caret);
oatpp::parser::Caret::Label sizeLabel(caret);
caret.findRN();
sizeLabel.end();
@ -234,12 +234,12 @@ ContentRange ContentRange::parse(oatpp::parser::ParsingCaret& caret) {
}
ContentRange ContentRange::parse(const oatpp::String& str) {
oatpp::parser::ParsingCaret caret(str);
oatpp::parser::Caret caret(str);
return parse(caret);
}
oatpp::data::share::StringKeyLabelCI_FAST Protocol::parseHeaderNameLabel(const std::shared_ptr<oatpp::base::StrBuffer>& headersText,
oatpp::parser::ParsingCaret& caret) {
oatpp::parser::Caret& caret) {
p_char8 data = caret.getData();
for(v_int32 i = caret.getPosition(); i < caret.getSize(); i++) {
v_char8 a = data[i];
@ -255,10 +255,10 @@ oatpp::data::share::StringKeyLabelCI_FAST Protocol::parseHeaderNameLabel(const s
void Protocol::parseRequestStartingLine(RequestStartingLine& line,
const std::shared_ptr<oatpp::base::StrBuffer>& headersText,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
Status& error) {
oatpp::parser::ParsingCaret::Label methodLabel(caret);
oatpp::parser::Caret::Label methodLabel(caret);
if(caret.findChar(' ')){
line.method = oatpp::data::share::StringKeyLabel(headersText, methodLabel.getData(), methodLabel.getSize());
caret.inc();
@ -267,7 +267,7 @@ void Protocol::parseRequestStartingLine(RequestStartingLine& line,
return;
}
oatpp::parser::ParsingCaret::Label pathLabel(caret);
oatpp::parser::Caret::Label pathLabel(caret);
if(caret.findChar(' ')){
line.path = oatpp::data::share::StringKeyLabel(headersText, pathLabel.getData(), pathLabel.getSize());
caret.inc();
@ -276,7 +276,7 @@ void Protocol::parseRequestStartingLine(RequestStartingLine& line,
return;
}
oatpp::parser::ParsingCaret::Label protocolLabel(caret);
oatpp::parser::Caret::Label protocolLabel(caret);
if(caret.findRN()){
line.protocol = oatpp::data::share::StringKeyLabel(headersText, protocolLabel.getData(), protocolLabel.getSize());
caret.skipRN();
@ -289,10 +289,10 @@ void Protocol::parseRequestStartingLine(RequestStartingLine& line,
void Protocol::parseResponseStartingLine(ResponseStartingLine& line,
const std::shared_ptr<oatpp::base::StrBuffer>& headersText,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
Status& error) {
oatpp::parser::ParsingCaret::Label protocolLabel(caret);
oatpp::parser::Caret::Label protocolLabel(caret);
if(caret.findChar(' ')){
line.protocol = oatpp::data::share::StringKeyLabel(headersText, protocolLabel.getData(), protocolLabel.getSize());
caret.inc();
@ -301,9 +301,9 @@ void Protocol::parseResponseStartingLine(ResponseStartingLine& line,
return;
}
line.statusCode = caret.parseInt32();
line.statusCode = caret.parseInt();
oatpp::parser::ParsingCaret::Label descriptionLabel(caret);
oatpp::parser::Caret::Label descriptionLabel(caret);
if(caret.findRN()){
line.description = oatpp::data::share::StringKeyLabel(headersText, descriptionLabel.getData(), descriptionLabel.getSize());
caret.skipRN();
@ -316,17 +316,17 @@ void Protocol::parseResponseStartingLine(ResponseStartingLine& line,
void Protocol::parseOneHeader(Headers& headers,
const std::shared_ptr<oatpp::base::StrBuffer>& headersText,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
Status& error) {
caret.findNotSpaceChar();
caret.skipChar(' ');
auto name = parseHeaderNameLabel(headersText, caret);
if(name.getData() != nullptr) {
caret.findNotSpaceChar();
caret.skipChar(' ');
if(!caret.canContinueAtChar(':', 1)) {
error = Status::CODE_400;
return;
}
caret.findNotSpaceChar();
caret.skipChar(' ');
v_int32 valuePos0 = caret.getPosition();
caret.findRN();
headers[name] = oatpp::data::share::StringKeyLabel(headersText, &caret.getData()[valuePos0], caret.getPosition() - valuePos0);
@ -339,7 +339,7 @@ void Protocol::parseOneHeader(Headers& headers,
void Protocol::parseHeaders(Headers& headers,
const std::shared_ptr<oatpp::base::StrBuffer>& headersText,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
Status& error) {
while (!caret.isAtRN()) {

View File

@ -29,7 +29,7 @@
#include "oatpp/web/protocol/CommunicationError.hpp"
#include "oatpp/core/parser/ParsingCaret.hpp"
#include "oatpp/core/parser/Caret.hpp"
#include "oatpp/core/data/share/MemoryLabel.hpp"
#include "oatpp/core/data/stream/Delegate.hpp"
#include "oatpp/core/collection/ListMap.hpp"
@ -205,7 +205,7 @@ public:
return units.get() != nullptr;
}
static Range parse(oatpp::parser::ParsingCaret& caret);
static Range parse(oatpp::parser::Caret& caret);
static Range parse(const oatpp::String& str);
};
@ -243,7 +243,7 @@ public:
return units.get() != nullptr;
}
static ContentRange parse(oatpp::parser::ParsingCaret& caret);
static ContentRange parse(oatpp::parser::Caret& caret);
static ContentRange parse(const oatpp::String& str);
};
@ -265,27 +265,27 @@ public:
typedef std::unordered_map<oatpp::data::share::StringKeyLabelCI_FAST, oatpp::data::share::StringKeyLabel> Headers;
private:
static oatpp::data::share::StringKeyLabelCI_FAST parseHeaderNameLabel(const std::shared_ptr<oatpp::base::StrBuffer>& headersText,
oatpp::parser::ParsingCaret& caret);
oatpp::parser::Caret& caret);
public:
static void parseRequestStartingLine(RequestStartingLine& line,
const std::shared_ptr<oatpp::base::StrBuffer>& headersText,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
Status& error);
static void parseResponseStartingLine(ResponseStartingLine& line,
const std::shared_ptr<oatpp::base::StrBuffer>& headersText,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
Status& error);
static void parseOneHeader(Headers& headers,
const std::shared_ptr<oatpp::base::StrBuffer>& headersText,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
Status& error);
static void parseHeaders(Headers& headers,
const std::shared_ptr<oatpp::base::StrBuffer>& headersText,
oatpp::parser::ParsingCaret& caret,
oatpp::parser::Caret& caret,
Status& error);
};

View File

@ -86,7 +86,7 @@ private:
oatpp::async::Action onDecoded() {
auto body = m_chunkedBuffer->toString();
oatpp::parser::ParsingCaret caret(body);
oatpp::parser::Caret caret(body);
auto dto = m_objectMapper->readFromCaret<Type>(caret);
if(caret.hasError()) {
return this->error(caret.getErrorMessage());

View File

@ -82,7 +82,7 @@ RequestHeadersReader::Result RequestHeadersReader::readHeaders(const std::shared
if(error.ioStatus > 0) {
auto headersText = buffer.toString();
oatpp::parser::ParsingCaret caret (headersText);
oatpp::parser::Caret caret (headersText);
http::Status status;
http::Protocol::parseRequestStartingLine(result.startingLine, headersText.getPtr(), caret, status);
if(status.code == 0) {
@ -159,7 +159,7 @@ RequestHeadersReader::Action RequestHeadersReader::readHeadersAsync(oatpp::async
Action parseHeaders() {
auto headersText = m_bufferStream.toString();
oatpp::parser::ParsingCaret caret (headersText);
oatpp::parser::Caret caret (headersText);
http::Status status;
http::Protocol::parseRequestStartingLine(m_result.startingLine, headersText.getPtr(), caret, status);
if(status.code == 0) {

View File

@ -82,7 +82,7 @@ ResponseHeadersReader::Result ResponseHeadersReader::readHeaders(const std::shar
if(error.ioStatus > 0) {
auto headersText = buffer.toString();
oatpp::parser::ParsingCaret caret (headersText);
oatpp::parser::Caret caret (headersText);
http::Status status;
http::Protocol::parseResponseStartingLine(result.startingLine, headersText.getPtr(), caret, status);
if(status.code == 0) {
@ -159,7 +159,7 @@ ResponseHeadersReader::Action ResponseHeadersReader::readHeadersAsync(oatpp::asy
Action parseHeaders() {
auto headersText = m_bufferStream.toString();
oatpp::parser::ParsingCaret caret (headersText);
oatpp::parser::Caret caret (headersText);
http::Status status;
http::Protocol::parseResponseStartingLine(m_result.startingLine, headersText.getPtr(), caret, status);
if(status.code == 0) {

View File

@ -106,7 +106,7 @@ std::shared_ptr<Pattern> Pattern::parse(const oatpp::String& data){
return parse(data->getData(), data->getSize());
}
v_char8 Pattern::findSysChar(oatpp::parser::ParsingCaret& caret) {
v_char8 Pattern::findSysChar(oatpp::parser::Caret& caret) {
auto data = caret.getData();
for (v_int32 i = caret.getPosition(); i < caret.getSize(); i++) {
v_char8 a = data[i];
@ -121,7 +121,7 @@ v_char8 Pattern::findSysChar(oatpp::parser::ParsingCaret& caret) {
bool Pattern::match(const StringKeyLabel& url, MatchMap& matchMap) {
oatpp::parser::ParsingCaret caret(url.getData(), url.getSize());
oatpp::parser::Caret caret(url.getData(), url.getSize());
if(m_parts->count() == 0){
@ -142,7 +142,7 @@ bool Pattern::match(const StringKeyLabel& url, MatchMap& matchMap) {
if(part->function == Part::FUNCTION_CONST){
if(!caret.proceedIfFollowsText(part->text->getData(), part->text->getSize())){
if(!caret.isAtText(part->text->getData(), part->text->getSize(), true)){
return false;
}
@ -165,7 +165,7 @@ bool Pattern::match(const StringKeyLabel& url, MatchMap& matchMap) {
return false;
}
oatpp::parser::ParsingCaret::Label label(caret);
oatpp::parser::Caret::Label label(caret);
v_char8 a = findSysChar(caret);
if(a == '?') {
if(curr == nullptr || curr->getData()->function == Part::FUNCTION_ANY_END) {

View File

@ -29,7 +29,7 @@
#include "oatpp/core/collection/LinkedList.hpp"
#include "oatpp/core/parser/ParsingCaret.hpp"
#include "oatpp/core/parser/Caret.hpp"
#include <unordered_map>
@ -96,7 +96,7 @@ private:
private:
std::shared_ptr<oatpp::collection::LinkedList<std::shared_ptr<Part>>> m_parts;
private:
v_char8 findSysChar(oatpp::parser::ParsingCaret& caret);
v_char8 findSysChar(oatpp::parser::Caret& caret);
public:
Pattern()
: m_parts(oatpp::collection::LinkedList<std::shared_ptr<Part>>::createShared())

View File

@ -121,7 +121,7 @@ bool MemoryLabelTest::onRun() {
for(v_int32 i = 0; i < iterationsCount; i ++) {
oatpp::parser::ParsingCaret caret(headersText);
oatpp::parser::Caret caret(headersText);
oatpp::web::protocol::http::Status status;
oatpp::web::protocol::http::Protocol::Headers headers;
oatpp::web::protocol::http::Protocol::parseHeaders(headers, headersText.getPtr(), caret, status);

View File

@ -83,7 +83,7 @@ bool DTOMapperPerfTest::onRun() {
{
PerformanceChecker checker("Deserializer");
oatpp::parser::ParsingCaret caret(test1_Text);
oatpp::parser::Caret caret(test1_Text);
for(v_int32 i = 0; i < numIterations; i ++) {
caret.setPosition(0);
mapper->readFromCaret<Test1>(caret);

View File

@ -166,7 +166,7 @@ bool DTOMapperTest::onRun(){
OATPP_LOGD(TAG, "...");
auto config = oatpp::parser::json::mapping::Deserializer::Config::createShared();
oatpp::parser::ParsingCaret caret(result);
oatpp::parser::Caret caret(result);
auto obj = mapper->readFromCaret<Test>(caret);
OATPP_ASSERT(obj->_string);

View File

@ -34,7 +34,7 @@ namespace {
#include OATPP_CODEGEN_BEGIN(DTO)
typedef oatpp::data::mapping::type::Object DTO;
typedef oatpp::parser::ParsingCaret ParsingCaret;
typedef oatpp::parser::Caret ParsingCaret;
typedef oatpp::parser::json::mapping::Serializer Serializer;
typedef oatpp::parser::json::mapping::Deserializer Deserializer;