Temporary stashing group changes

This commit is contained in:
WolverinDEV 2021-02-28 19:03:40 +01:00
parent 71443bc4d3
commit b26132fa54

View File

@ -102,40 +102,57 @@ std::string query::unescape(std::string in, bool throw_error) {
in.replace(index, 1, "", 0); //Cut the character out in.replace(index, 1, "", 0); //Cut the character out
index--; index--;
} else if(current >= 194 && current <= 223) { } else if(current >= 194 && current <= 223) {
if(in.length() - index <= 1) if(in.length() - index <= 1) {
in.replace(index, in.length() - index, "", 0); in.replace(index, in.length() - index, "", 0);
else if((uint8_t) in[index + 1] >= 128 && (uint8_t) in[index + 1] <= 191) index += 1; //Valid } else if((uint8_t) in[index + 1] >= 128 && (uint8_t) in[index + 1] <= 191) {
else { index += 1; //Valid
if(throw_error) throw invalid_argument("Invalid UTF-8 character at index " + to_string(index)); } else {
if(throw_error) {
throw invalid_argument("Invalid UTF-8 character at index " + to_string(index));
}
in.replace(index, 2, "", 0); //Cut the two characters out in.replace(index, 2, "", 0); //Cut the two characters out
index--; index--;
} }
} else if(current >= 224 && current <= 239) { } else if(current >= 224 && current <= 239) {
if(in.length() - index <= 2) if(in.length() - index <= 2) {
in.replace(index, in.length() - index, "", 0); in.replace(index, in.length() - index, "", 0);
else if((uint8_t) in[index + 1] >= 128 && (uint8_t) in[index + 1] <= 191 && } else if((uint8_t) in[index + 1] >= 128 && (uint8_t) in[index + 1] <= 191 &&
(uint8_t) in[index + 2] >= 128 && (uint8_t) in[index + 2] <= 191) index += 2; //Valid (uint8_t) in[index + 2] >= 128 && (uint8_t) in[index + 2] <= 191) {
else { index += 2; //Valid
if(throw_error) throw invalid_argument("Invalid UTF-8 character at index " + to_string(index)); } else {
if(throw_error) {
throw invalid_argument("Invalid UTF-8 character at index " + to_string(index));
}
in.replace(index, 3, "", 0); //Cut the three characters out in.replace(index, 3, "", 0); //Cut the three characters out
index--; index--;
} }
} else if(current >= 240 && current <= 244) { } else if(current >= 240 && current <= 244) {
if(in.length() - index <= 3) if(in.length() - index <= 3) {
in.replace(index, in.length() - index, "", 0); in.replace(index, in.length() - index, "", 0);
else if((uint8_t) in[index + 1] >= 128 && (uint8_t) in[index + 1] <= 191 && } else if((uint8_t) in[index + 1] >= 128 && (uint8_t) in[index + 1] <= 191 &&
(uint8_t) in[index + 2] >= 128 && (uint8_t) in[index + 2] <= 191 && (uint8_t) in[index + 2] >= 128 && (uint8_t) in[index + 2] <= 191 &&
(uint8_t) in[index + 3] >= 128 && (uint8_t) in[index + 3] <= 191) index += 3; //Valid (uint8_t) in[index + 3] >= 128 && (uint8_t) in[index + 3] <= 191) {
else { index += 3; //Valid
if(throw_error) throw invalid_argument("Invalid UTF-8 character at index " + to_string(index)); } else {
if(throw_error) {
throw invalid_argument("Invalid UTF-8 character at index " + to_string(index));
}
in.replace(index, 4, "", 0); //Cut the three characters out in.replace(index, 4, "", 0); //Cut the three characters out
index--; index--;
} }
} else { } else {
if(throw_error) throw invalid_argument("Invalid UTF-8 character at index " + to_string(index)); if(throw_error) {
throw invalid_argument("Invalid UTF-8 character at index " + to_string(index));
}
in.replace(index, 1, "", 0); //Cut the character out in.replace(index, 1, "", 0); //Cut the character out
index--; index--;
} }
} else if(current < 0x0A) {
in.replace(index, 1, " ", 1);
} }
index++; index++;
} }