Merge pull request #703 from oatpp/minor_code_cleanup

parser::Caret: code cleanup
This commit is contained in:
Leonid Stryzhevskyi 2023-01-18 03:44:04 +02:00 committed by GitHub
commit 0de4459c45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 86 deletions

View File

@ -218,7 +218,7 @@ v_int64 Caret::StateSaveGuard::getSavedErrorCode() {
bool Caret::skipBlankChars(){
while(m_pos < m_size){
v_char8 a = m_data[m_pos];
char a = m_data[m_pos];
if(a != ' ' && a != '\t' && a != '\n' && a != '\r' && a != '\f')
return true;
m_pos ++;
@ -227,7 +227,7 @@ v_int64 Caret::StateSaveGuard::getSavedErrorCode() {
return false;
}
bool Caret::skipChar(v_char8 c) {
bool Caret::skipChar(char c) {
while(m_pos < m_size){
if(m_data[m_pos] != c)
return true;
@ -236,7 +236,7 @@ v_int64 Caret::StateSaveGuard::getSavedErrorCode() {
return false;
}
bool Caret::findChar(v_char8 c){
bool Caret::findChar(char c){
while(m_pos < m_size){
if(m_data[m_pos] == c)
@ -272,7 +272,7 @@ v_int64 Caret::StateSaveGuard::getSavedErrorCode() {
while(m_pos < m_size){
v_char8 a = m_data[m_pos];
char a = m_data[m_pos];
for(v_buff_size i = 0; i < setSize; i++){
if(set[i] == a)
@ -315,7 +315,7 @@ v_int64 Caret::StateSaveGuard::getSavedErrorCode() {
bool Caret::findROrN() {
while(m_pos < m_size) {
v_char8 a = m_data[m_pos];
char a = m_data[m_pos];
if(a == '\r' || a == '\n') {
return true;
}
@ -339,7 +339,7 @@ v_int64 Caret::StateSaveGuard::getSavedErrorCode() {
bool Caret::skipAllRsAndNs() {
bool skipped = false;
while(m_pos < m_size) {
v_char8 a = m_data[m_pos];
char a = m_data[m_pos];
if(a == '\r' || a == '\n') {
m_pos ++;
skipped = true;
@ -432,8 +432,8 @@ v_int64 Caret::StateSaveGuard::getSavedErrorCode() {
for(v_buff_size i = 0; i < textSize; i++){
v_char8 c1 = text[i];
v_char8 c2 = m_data[m_pos + i];
char c1 = text[i];
char c2 = m_data[m_pos + i];
if(c1 >= 'a' && c1 <= 'z'){
c1 = 'A' + c1 - 'a';
@ -468,7 +468,7 @@ v_int64 Caret::StateSaveGuard::getSavedErrorCode() {
auto label = putLabel();
while(canContinue()){
v_char8 a = m_data[m_pos];
char a = m_data[m_pos];
if(a == escapeChar){
m_pos++;
@ -506,7 +506,7 @@ v_int64 Caret::StateSaveGuard::getSavedErrorCode() {
bool Caret::isAtCharFromSet(const char* set, v_buff_size setSize) const{
v_char8 a = m_data[m_pos];
char a = m_data[m_pos];
for(v_buff_size i = 0; i < setSize; i++){
if(a == set[i]){
@ -518,25 +518,25 @@ v_int64 Caret::StateSaveGuard::getSavedErrorCode() {
}
bool Caret::isAtChar(v_char8 c) const{
bool Caret::isAtChar(char c) const{
return m_data[m_pos] == c;
}
bool Caret::isAtBlankChar() const{
v_char8 a = m_data[m_pos];
char a = m_data[m_pos];
return (a == ' ' || a == '\t' || a == '\n' || a == '\r' || a == '\b' || a == '\f');
}
bool Caret::isAtDigitChar() const{
v_char8 a = m_data[m_pos];
char a = m_data[m_pos];
return (a >= '0' && a <= '9');
}
bool Caret::canContinueAtChar(v_char8 c) const{
bool Caret::canContinueAtChar(char c) const{
return m_pos < m_size && m_errorMessage == nullptr && m_data[m_pos] == c;
}
bool Caret::canContinueAtChar(v_char8 c, v_buff_size skipChars){
bool Caret::canContinueAtChar(char c, v_buff_size skipChars){
if(m_pos < m_size && m_errorMessage == nullptr && m_data[m_pos] == c){
m_pos = m_pos + skipChars;

View File

@ -264,7 +264,7 @@ public:
* @param c
* @return true if other char found
*/
bool skipChar(v_char8 c);
bool skipChar(char c);
/**
* Find char. Position will be set to a found char. If
@ -272,7 +272,7 @@ public:
* @param c
* @return true if found
*/
bool findChar(v_char8 c);
bool findChar(char c);
/**
* Skip chars defined by set.
@ -467,7 +467,7 @@ public:
* @param c
* @return
*/
bool isAtChar(v_char8 c) const;
bool isAtChar(char c) const;
/**
* Check if caret is at one of chars [' ', '\t', '\n', '\r','\f']
@ -486,7 +486,7 @@ public:
* @param c
* @return
*/
bool canContinueAtChar(v_char8 c) const;
bool canContinueAtChar(char c) const;
/**
* Check if caret is at char, and no error is set.
@ -495,7 +495,7 @@ public:
* @param skipChars
* @return
*/
bool canContinueAtChar(v_char8 c, v_buff_size skipChars);
bool canContinueAtChar(char c, v_buff_size skipChars);
/**
* Check if caret position < dataSize and not error is set

View File

@ -163,72 +163,6 @@ private:
}
template<class Collection>
static oatpp::Void deserializeKeyValue(Deserializer* deserializer, parser::Caret& caret, const Type* const type) {
if(caret.isAtText("null", true)){
return oatpp::Void(type);
}
if(caret.canContinueAtChar('{', 1)) {
auto polymorphicDispatcher = static_cast<const typename Collection::Class::PolymorphicDispatcher*>(type->polymorphicDispatcher);
auto mapWrapper = polymorphicDispatcher->createObject();
const auto& map = mapWrapper.template cast<Collection>();
auto it = type->params.begin();
auto keyType = *it ++;
if(keyType->classId.id != oatpp::data::mapping::type::__class::String::CLASS_ID.id){
throw std::runtime_error("[oatpp::parser::json::mapping::Deserializer::deserializeKeyValue()]: Invalid json map key. Key should be String");
}
auto valueType = *it;
caret.skipBlankChars();
while (!caret.isAtChar('}') && caret.canContinue()) {
caret.skipBlankChars();
auto key = Utils::parseString(caret);
if(caret.hasError()){
return nullptr;
}
caret.skipBlankChars();
if(!caret.canContinueAtChar(':', 1)){
caret.setError("[oatpp::parser::json::mapping::Deserializer::deserializeKeyValue()]: Error. ':' - expected", ERROR_CODE_OBJECT_SCOPE_COLON_MISSING);
return nullptr;
}
caret.skipBlankChars();
auto item = deserializer->deserialize(caret, valueType);
if(caret.hasError()){
return nullptr;
}
polymorphicDispatcher->addPolymorphicItem(mapWrapper, key, item);
caret.skipBlankChars();
caret.canContinueAtChar(',', 1);
}
if(!caret.canContinueAtChar('}', 1)){
if(!caret.hasError()){
caret.setError("[oatpp::parser::json::mapping::Deserializer::deserializeKeyValue()]: Error. '}' - expected", ERROR_CODE_OBJECT_SCOPE_CLOSE);
}
return nullptr;
}
return oatpp::Void(map.getPtr(), map.getValueType());
} else {
caret.setError("[oatpp::parser::json::mapping::Deserializer::deserializeKeyValue()]: Error. '{' - expected", ERROR_CODE_OBJECT_SCOPE_OPEN);
}
return nullptr;
}
static oatpp::Void deserializeFloat32(Deserializer* deserializer, parser::Caret& caret, const Type* const type);
static oatpp::Void deserializeFloat64(Deserializer* deserializer, parser::Caret& caret, const Type* const type);
static oatpp::Void deserializeBoolean(Deserializer* deserializer, parser::Caret& caret, const Type* const type);