Exemplo n.º 1
0
bool JsonIn::get_bool()
{
    char ch;
    char text[5];
    std::stringstream err;
    eat_whitespace();
    stream->get(ch);
    if (ch == 't') {
        stream->get(text, 4);
        if (strcmp(text, "rue") == 0) {
            end_value();
            return true;
        } else {
            err << "not a boolean. expected \"true\", but got \"";
            err << ch << text << "\"";
            error(err.str(), -4);
        }
    } else if (ch == 'f') {
        stream->get(text, 5);
        if (strcmp(text, "alse") == 0) {
            end_value();
            return false;
        } else {
            err << "not a boolean. expected \"false\", but got \"";
            err << ch << text << "\"";
            error(err.str(), -5);
        }
    }
    err << "not a boolean value! expected 't' or 'f' but got '" << ch << "'";
    error(err.str(), -1);
    throw (std::string)"warnings are silly";
}
Exemplo n.º 2
0
    void do_double_value(double value, uint8_t precision) override
    {
        begin_value();

        if (is_nan(value) && format_.replace_nan())
        {
            bos_.write(format_.nan_replacement());
        }
        else if (is_pos_inf(value) && format_.replace_pos_inf())
        {
            bos_.write(format_.pos_inf_replacement());
        }
        else if (is_neg_inf(value) && format_.replace_neg_inf())
        {
            bos_.write(format_.neg_inf_replacement());
        }
        //else if (format_.floatfield() != 0)
        //{
            //std::basic_ostringstream<CharT> os;
            //os.imbue(std::locale::classic());
            //os.setf(format_.floatfield(), std::ios::floatfield);
            //os << std::showpoint << std::setprecision(format_.precision()) << value;
            //*os_ << os.str();
        //}
        else
        {
            fp_.print(value,precision,bos_);
        }

        end_value();
    }
Exemplo n.º 3
0
    void do_double_value(double value) override
    {
        begin_value();

        if (is_nan(value) && format_.replace_nan())
        {
            *os_ << format_.nan_replacement();
        }
        else if (is_pos_inf(value) && format_.replace_pos_inf())
        {
            *os_ << format_.pos_inf_replacement();
        }
        else if (is_neg_inf(value) && format_.replace_neg_inf())
        {
            *os_ << format_.neg_inf_replacement();
        }
        else if (format_.floatfield() != 0)
        {
            std::basic_ostringstream<Char> os;
            os.imbue(std::locale::classic());
            os.setf(format_.floatfield(), std::ios::floatfield);
            os << std::showpoint << std::setprecision(format_.precision()) << value;
            *os_ << os.str();
        }
        else
        {
            std::basic_string<Char> buf = float_to_string<Char>(value,format_.precision());
            *os_ << buf;
        }

        end_value();
    }
Exemplo n.º 4
0
    void do_null_value() override
    {
        begin_value();

        *os_ << json_char_traits<Char,sizeof(Char)>::null_literal();

        end_value();
    }
Exemplo n.º 5
0
    void do_longlong_value(long long value) override
    {
        begin_value();

        *os_ << value;

        end_value();
    }
Exemplo n.º 6
0
    void do_ulonglong_value(unsigned long long value) override
    {
        begin_value();

        *os_ << value;

        end_value();
    }
Exemplo n.º 7
0
    virtual void write_bool(bool value)
    {
        begin_value();

        os_ << (value ? json_char_traits<Char,sizeof(Char)>::true_literal() :  json_char_traits<Char,sizeof(Char)>::false_literal());

        end_value();
    }
Exemplo n.º 8
0
    virtual void write_ulonglong(unsigned long long value)
    {
        begin_value();

        os_  << value;

        end_value();
    }
Exemplo n.º 9
0
    virtual void write_longlong(long long value)
    {
        begin_value();

        os_  << value;

        end_value();
    }
Exemplo n.º 10
0
    virtual void write_null()
    {
        begin_value();

        os_ << json_char_traits<Char,sizeof(Char)>::null_literal();

        end_value();
    }
Exemplo n.º 11
0
    void do_bool_value(bool value) override
    {
        begin_value();

        *os_ << (value ? json_char_traits<Char,sizeof(Char)>::true_literal() :  json_char_traits<Char,sizeof(Char)>::false_literal());

        end_value();
    }
Exemplo n.º 12
0
/**
 * Set a value compatible for 7 and 8 bit version of blank end.
 * VGA doc report use of 7 bit, but other documentations report that many
 * SVGA use all 8 bit.
 * \note Call after vertical_blank_start_set.
 */
void vga_regs_vbe_set(struct vga_regs* regs, unsigned value)
{
	/* get first 8 bit of start */
	unsigned start8 = regs->crtc[0x15];
	/* compute first 8 bit of end, compatible also for 7 bit regs */
	unsigned end8 = end_value(start8, value & 0x7F, 7);
	regs->crtc[0x16] = mask(end8, 0, 8);
}
Exemplo n.º 13
0
void eval_standard(int argc, char *argv[])
	{
	main_argc = argc;
	main_argv = argv;
	beg_const();
	eval_script();
	end_const();
	end_value();
	}
Exemplo n.º 14
0
    void do_null_value() override
    {
        begin_value();

        auto buf = json_literals<CharT>::null_literal();
        bos_.write(buf.first,buf.second);

        end_value();
    }
Exemplo n.º 15
0
    void do_string_value(const CharT* value, size_t length) override
    {
        begin_value();

        bos_. put('\"');
        escape_string<CharT>(value, length, format_, bos_);
        bos_. put('\"');

        end_value();
    }
Exemplo n.º 16
0
    virtual void write_string(const Char* value, size_t length)
    {
        begin_value();

        os_.put('\"');
        escape_string<Char>(value, length, format_, os_);
        os_.put('\"');

        end_value();
    }
Exemplo n.º 17
0
    void do_string_value(const Char* value, size_t length) override
    {
        begin_value();

        os_->put('\"');
        escape_string<Char>(value, length, format_, *os_);
        os_->put('\"');

        end_value();
    }
Exemplo n.º 18
0
void JsonIn::skip_false()
{
    char text[6];
    eat_whitespace();
    stream->get(text, 6);
    if (strcmp(text, "false") != 0) {
        std::stringstream err;
        err << "expected \"false\", but found \"" << text << "\"";
        error(err.str(), -5);
    }
    end_value();
}
Exemplo n.º 19
0
void JsonIn::skip_null()
{
    char text[5];
    eat_whitespace();
    stream->get(text, 5);
    if (strcmp(text, "null") != 0) {
        std::stringstream err;
        err << "expected \"null\", but found \"" << text << "\"";
        error(err.str(), -4);
    }
    end_value();
}
Exemplo n.º 20
0
    void do_end_object() override
    {
        unindent();
        if (indenting_ && !stack_.empty())
        {
            write_indent();
        }
        stack_.pop_back();
        os_->put('}');

        end_value();
    }
Exemplo n.º 21
0
    virtual void end_array()
    {
        unindent();
        if (indenting_ && !stack_.empty() && stack_.back().content_indented_)
        {
            write_indent();
        }
        stack_.pop_back();
        os_.put(']');

        end_value();
    }
Exemplo n.º 22
0
    virtual void end_object()
    {
        unindent();
        if (indenting_ && !stack_.empty())
        {
            write_indent();
        }
        stack_.pop_back();
        os_.put('}');

        end_value();
    }
Exemplo n.º 23
0
    void do_end_array() override
    {
        unindent();
        if (indenting_ && !stack_.empty() && stack_.back().content_indented_)
        {
            write_indent();
        }
        stack_.pop_back();
        os_->put(']');

        end_value();
    }
Exemplo n.º 24
0
  void fallFromStage() noexcept {
    on_stage_ = false;

    ci::Vec3f end_value(block_position_ + ci::Vec3f(0, fall_y_, 0));
    auto options = animation_timeline_->apply(&position_,
                                              end_value,
                                              fall_duration_,
                                              getEaseFunc(fall_ease_));

    options.finishFn([this]() noexcept {
        active_ = false;
      });
  }
Exemplo n.º 25
0
void JsonIn::skip_number()
{
    char ch;
    eat_whitespace();
    // skip all of (+-0123456789.eE)
    while (stream->good()) {
        stream->get(ch);
        if (ch != '+' && ch != '-' && (ch < '0' || ch > '9') &&
                ch != 'e' && ch != 'E' && ch != '.') {
            stream->unget();
            break;
        }
    }
    end_value();
}
Exemplo n.º 26
0
bool JsonIn::end_object()
{
    eat_whitespace();
    if (peek() == '}') {
        if (strict && ate_separator) {
            uneat_whitespace();
            error("separator not strictly allowed at end of object");
        }
        stream->get();
        end_value();
        return true;
    } else {
        // not the end yet, so just return false?
        return false;
    }
}
Exemplo n.º 27
0
    void do_bool_value(bool value) override
    {
        begin_value();

        if (value)
        {
            auto buf = json_literals<CharT>::true_literal();
            bos_.write(buf.first,buf.second);
        }
        else
        {
            auto buf = json_literals<CharT>::false_literal();
            bos_.write(buf.first,buf.second);
        }

        end_value();
    }
Exemplo n.º 28
0
  void fallFromStage() noexcept {
    on_stage_  = false;
    getatable_ = false;

    offset_.stop();
    
    ci::Vec3f end_value(block_position_ + ci::Vec3f(0, fall_y_, 0));
    auto options = animation_timeline_->apply(&position_,
                                              end_value,
                                              fall_duration_,
                                              getEaseFunc(fall_ease_));

    options.finishFn([this]() noexcept {
        active_ = false;
      });

    startShadowAlphaTween(0.0f);
  }
Exemplo n.º 29
0
void JsonIn::skip_string()
{
    char ch;
    eat_whitespace();
    stream->get(ch);
    if (ch != '"') {
        std::stringstream err;
        err << "expecting string but found '" << ch << "'";
        error(err.str(), -1);
    }
    while (stream->good()) {
        stream->get(ch);
        if (ch == '\\') {
            stream->get(ch);
            continue;
        } else if (ch == '"') {
            break;
        } else if (strict && (ch == '\r' || ch == '\n')) {
            error("string not closed before end of line", -1);
        }
    }
    end_value();
}
Exemplo n.º 30
0
std::string JsonIn::get_string()
{
    std::string s = "";
    char ch;
    bool backslash = false;
    char unihex[5] = "0000";
    eat_whitespace();
    int startpos = tell();
    // the first character had better be a '"'
    stream->get(ch);
    if (ch != '"') {
        std::stringstream err;
        err << "expecting string but got '" << ch << "'";
        error(err.str(), -1);
    }
    // add chars to the string, one at a time, converting:
    // \", \\, \/, \b, \f, \n, \r, \t and \uxxxx according to JSON spec.
    while (stream->good()) {
        stream->get(ch);
        if (ch == '\\') {
            if (backslash) {
                s += '\\';
                backslash = false;
            } else {
                backslash = true;
                continue;
            }
        } else if (backslash) {
            backslash = false;
            if (ch == '"') {
                s += '"';
            } else if (ch == '/') {
                s += '/';
            } else if (ch == 'b') {
                s += '\b';
            } else if (ch == 'f') {
                s += '\f';
            } else if (ch == 'n') {
                s += '\n';
            } else if (ch == 'r') {
                s += '\r';
            } else if (ch == 't') {
                s += '\t';
            } else if (ch == 'u') {
                // get the next four characters as hexadecimal
                stream->get(unihex, 5);
                // insert the appropriate unicode character in utf8
                // TODO: verify that unihex is in fact 4 hex digits.
                char** endptr = 0;
                unsigned u = (unsigned)strtoul(unihex, endptr, 16);
                s += utf16_to_utf8(u);
            } else {
                // for anything else, just add the character, i suppose
                s += ch;
            }
        } else if (ch == '"') {
            // end of the string
            end_value();
            return s;
        } else if (strict && (ch == '\r' || ch == '\n')) {
            error("reached end of line without closing string", -1);
        } else if (strict && (unsigned char)ch < 0x20) {
            error("invalid character inside string", -1);
        } else {
            s += ch;
        }
    }
    // if we get to here, probably hit a premature EOF?
    if (stream->eof()) {
        stream->clear();
        seek(startpos);
        error("couldn't find end of string, reached EOF.");
    } else if (stream->fail()) {
        throw (std::string)"stream failure while reading string.";
    }
    throw (std::string)"something went wrong D:";
}