mirror of https://github.com/CrowCpp/Crow.git
Merge pull request #683 from cschreib/const
Add missing const to mustache `render` and `json::wvalue::operator[]`
This commit is contained in:
commit
c755c4c8e6
|
@ -1656,7 +1656,7 @@ namespace crow
|
|||
}
|
||||
else
|
||||
{
|
||||
#if defined(__APPLE__) || defined(__MACH__) || defined (__FreeBSD__) || defined (__ANDROID__)
|
||||
#if defined(__APPLE__) || defined(__MACH__) || defined(__FreeBSD__) || defined(__ANDROID__)
|
||||
o = std::unique_ptr<object>(new object(initializer_list));
|
||||
#else
|
||||
(*o) = initializer_list;
|
||||
|
@ -1675,7 +1675,7 @@ namespace crow
|
|||
}
|
||||
else
|
||||
{
|
||||
#if defined(__APPLE__) || defined(__MACH__) || defined (__FreeBSD__)
|
||||
#if defined(__APPLE__) || defined(__MACH__) || defined(__FreeBSD__)
|
||||
o = std::unique_ptr<object>(new object(value));
|
||||
#else
|
||||
(*o) = value;
|
||||
|
@ -1719,7 +1719,12 @@ namespace crow
|
|||
return (*l)[index];
|
||||
}
|
||||
|
||||
int count(const std::string& str)
|
||||
const wvalue& operator[](unsigned index) const
|
||||
{
|
||||
return const_cast<wvalue*>(this)->operator[](index);
|
||||
}
|
||||
|
||||
int count(const std::string& str) const
|
||||
{
|
||||
if (t_ != type::Object)
|
||||
return 0;
|
||||
|
@ -1738,6 +1743,11 @@ namespace crow
|
|||
return (*o)[str];
|
||||
}
|
||||
|
||||
const wvalue& operator[](const std::string& str) const
|
||||
{
|
||||
return const_cast<wvalue*>(this)->operator[](str);
|
||||
}
|
||||
|
||||
std::vector<std::string> keys() const
|
||||
{
|
||||
if (t_ != type::Object)
|
||||
|
@ -1841,9 +1851,9 @@ namespace crow
|
|||
} f_state;
|
||||
char outbuf[128];
|
||||
#ifdef _MSC_VER
|
||||
sprintf_s(outbuf, sizeof(outbuf), "%f", v.num.d);
|
||||
sprintf_s(outbuf, sizeof(outbuf), "%f", v.num.d);
|
||||
#else
|
||||
snprintf(outbuf, sizeof(outbuf), "%f", v.num.d);
|
||||
snprintf(outbuf, sizeof(outbuf), "%f", v.num.d);
|
||||
#endif
|
||||
char *p = &outbuf[0], *o = nullptr; // o is the position of the first trailing 0
|
||||
f_state = start;
|
||||
|
|
|
@ -85,7 +85,7 @@ namespace crow
|
|||
{
|
||||
return body_.substr(action.start, action.end - action.start);
|
||||
}
|
||||
auto find_context(const std::string& name, const std::vector<context*>& stack, bool shouldUseOnlyFirstStackValue = false) const -> std::pair<bool, context&>
|
||||
auto find_context(const std::string& name, const std::vector<const context*>& stack, bool shouldUseOnlyFirstStackValue = false) const -> std::pair<bool, const context&>
|
||||
{
|
||||
if (name == ".")
|
||||
{
|
||||
|
@ -123,7 +123,7 @@ namespace crow
|
|||
|
||||
for (auto it = stack.rbegin(); it != stack.rend(); ++it)
|
||||
{
|
||||
context* view = *it;
|
||||
const context* view = *it;
|
||||
bool found = true;
|
||||
for (auto jt = names.begin(); jt != names.end(); ++jt)
|
||||
{
|
||||
|
@ -170,7 +170,7 @@ namespace crow
|
|||
}
|
||||
}
|
||||
|
||||
bool isTagInsideObjectBlock(const int& current, const std::vector<context*>& stack) const
|
||||
bool isTagInsideObjectBlock(const int& current, const std::vector<const context*>& stack) const
|
||||
{
|
||||
int openedBlock = 0;
|
||||
for (int i = current; i > 0; --i)
|
||||
|
@ -194,7 +194,7 @@ namespace crow
|
|||
return false;
|
||||
}
|
||||
|
||||
void render_internal(int actionBegin, int actionEnd, std::vector<context*>& stack, std::string& out, int indent) const
|
||||
void render_internal(int actionBegin, int actionEnd, std::vector<const context*>& stack, std::string& out, int indent) const
|
||||
{
|
||||
int current = actionBegin;
|
||||
|
||||
|
@ -360,7 +360,7 @@ namespace crow
|
|||
rendered_template render() const
|
||||
{
|
||||
context empty_ctx;
|
||||
std::vector<context*> stack;
|
||||
std::vector<const context*> stack;
|
||||
stack.emplace_back(&empty_ctx);
|
||||
|
||||
std::string ret;
|
||||
|
@ -369,9 +369,9 @@ namespace crow
|
|||
}
|
||||
|
||||
/// Apply the values from the context provided and output a returnable template from this mustache template
|
||||
rendered_template render(context& ctx) const
|
||||
rendered_template render(const context& ctx) const
|
||||
{
|
||||
std::vector<context*> stack;
|
||||
std::vector<const context*> stack;
|
||||
stack.emplace_back(&ctx);
|
||||
|
||||
std::string ret;
|
||||
|
@ -380,7 +380,7 @@ namespace crow
|
|||
}
|
||||
|
||||
/// Apply the values from the context provided and output a returnable template from this mustache template
|
||||
rendered_template render(context&& ctx) const
|
||||
rendered_template render(const context&& ctx) const
|
||||
{
|
||||
return render(ctx);
|
||||
}
|
||||
|
@ -389,7 +389,7 @@ namespace crow
|
|||
std::string render_string() const
|
||||
{
|
||||
context empty_ctx;
|
||||
std::vector<context*> stack;
|
||||
std::vector<const context*> stack;
|
||||
stack.emplace_back(&empty_ctx);
|
||||
|
||||
std::string ret;
|
||||
|
@ -398,9 +398,9 @@ namespace crow
|
|||
}
|
||||
|
||||
/// Apply the values from the context provided and output a returnable template from this mustache template
|
||||
std::string render_string(context& ctx) const
|
||||
std::string render_string(const context& ctx) const
|
||||
{
|
||||
std::vector<context*> stack;
|
||||
std::vector<const context*> stack;
|
||||
stack.emplace_back(&ctx);
|
||||
|
||||
std::string ret;
|
||||
|
|
Loading…
Reference in New Issue