Move Lexer to u16string handling, for unicode support
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -96,7 +96,7 @@ shared_ptr<BooleanEvalValue> Evaluator::EvaluateBooleanBinary(const BoundBinaryE
|
||||
shared_ptr<StringEvalValue> Evaluator::EvaluateStringBinary(const BoundBinaryExpression* expression){
|
||||
if (expression->GetOperation() != BoundBinaryOperation::Concatenation)
|
||||
throw;
|
||||
std::ostringstream strs;
|
||||
std::basic_ostringstream<char16_t > strs;
|
||||
auto left = this -> EvaluateStringExpression(expression->GetLeft());
|
||||
strs << *left->EvaluateString();
|
||||
auto right = this -> EvaluateExpression(expression->GetRight());
|
||||
|
||||
@@ -20,7 +20,7 @@ extern "C" {
|
||||
return v->EvaluateBool();
|
||||
}
|
||||
|
||||
const char* EvaluateEvalValueString(EvalValue* v){
|
||||
const char16_t * EvaluateEvalValueString(EvalValue* v){
|
||||
return v->EvaluateString() -> c_str();
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ extern "C" {
|
||||
return new BooleanEvalValue(b);
|
||||
}
|
||||
|
||||
EvalValue* CreateStringEvalValue(const char* s){
|
||||
EvalValue* CreateStringEvalValue(const char16_t * s){
|
||||
return new StringEvalValue(s);
|
||||
}
|
||||
}
|
||||
@@ -47,11 +47,12 @@ extern "C" {
|
||||
|
||||
|
||||
TEST_CASE( "Evaluate String", "[integration]" ) {
|
||||
auto script = Script::Create("\"foo bar\"");
|
||||
auto script = Script::Create(u"\"foo bar\"");
|
||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||
script->Evaluate();
|
||||
auto lastValue = script->GetLastValue();
|
||||
REQUIRE(std::strcmp(EvaluateEvalValueString(lastValue), "foo bar") == 0);
|
||||
auto s = u16string(EvaluateEvalValueString(lastValue));
|
||||
REQUIRE(s == u"foo bar");
|
||||
delete script;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
virtual bool EvaluateBool() const{
|
||||
throw EvaluationException("Can't evaluate this EvalValue as bool.");
|
||||
}
|
||||
virtual const std::string* EvaluateString() const {
|
||||
virtual const std::u16string* EvaluateString() const {
|
||||
throw EvaluationException("Can't evaluate this EvalValue as string.");
|
||||
}
|
||||
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
using namespace std;
|
||||
|
||||
class StringEvalValue : public EvalValue{
|
||||
string _value;
|
||||
u16string _value;
|
||||
size_t _hash;
|
||||
public:
|
||||
explicit StringEvalValue(string s){
|
||||
explicit StringEvalValue(u16string s){
|
||||
_value = move(s);
|
||||
_hash = HashedString::ConstHash (_value.c_str());
|
||||
}
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
return this->_hash == b->GetHashCode();
|
||||
};
|
||||
|
||||
const string* EvaluateString() const final{
|
||||
const u16string* EvaluateString() const final{
|
||||
return &_value;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
shared_ptr<EvalValue> IndexValue(EvalValue* val) final{
|
||||
// Porygon is 1-indexed, so we convert to that.
|
||||
auto l = val->EvaluateInteger() - 1;
|
||||
return make_shared<StringEvalValue>(string(1, _value[l]));
|
||||
return make_shared<StringEvalValue>(u16string(1, _value[l]));
|
||||
}
|
||||
|
||||
std::size_t GetHashCode() final{
|
||||
|
||||
Reference in New Issue
Block a user