mirror of https://github.com/CrowCpp/Crow.git
Add missing const to mustache and json::wvalue::operator[]
This commit is contained in:
parent
af6b7edc22
commit
42fab729a2
|
@ -1656,7 +1656,7 @@ namespace crow
|
||||||
}
|
}
|
||||||
else
|
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));
|
o = std::unique_ptr<object>(new object(initializer_list));
|
||||||
#else
|
#else
|
||||||
(*o) = initializer_list;
|
(*o) = initializer_list;
|
||||||
|
@ -1675,7 +1675,7 @@ namespace crow
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#if defined(__APPLE__) || defined(__MACH__) || defined (__FreeBSD__)
|
#if defined(__APPLE__) || defined(__MACH__) || defined(__FreeBSD__)
|
||||||
o = std::unique_ptr<object>(new object(value));
|
o = std::unique_ptr<object>(new object(value));
|
||||||
#else
|
#else
|
||||||
(*o) = value;
|
(*o) = value;
|
||||||
|
@ -1719,7 +1719,12 @@ namespace crow
|
||||||
return (*l)[index];
|
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)
|
if (t_ != type::Object)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1738,6 +1743,11 @@ namespace crow
|
||||||
return (*o)[str];
|
return (*o)[str];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const wvalue& operator[](const std::string& str) const
|
||||||
|
{
|
||||||
|
return const_cast<wvalue*>(this)->operator[](str);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> keys() const
|
std::vector<std::string> keys() const
|
||||||
{
|
{
|
||||||
if (t_ != type::Object)
|
if (t_ != type::Object)
|
||||||
|
@ -1841,9 +1851,9 @@ namespace crow
|
||||||
} f_state;
|
} f_state;
|
||||||
char outbuf[128];
|
char outbuf[128];
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
sprintf_s(outbuf, sizeof(outbuf), "%f", v.num.d);
|
sprintf_s(outbuf, sizeof(outbuf), "%f", v.num.d);
|
||||||
#else
|
#else
|
||||||
snprintf(outbuf, sizeof(outbuf), "%f", v.num.d);
|
snprintf(outbuf, sizeof(outbuf), "%f", v.num.d);
|
||||||
#endif
|
#endif
|
||||||
char *p = &outbuf[0], *o = nullptr; // o is the position of the first trailing 0
|
char *p = &outbuf[0], *o = nullptr; // o is the position of the first trailing 0
|
||||||
f_state = start;
|
f_state = start;
|
||||||
|
|
|
@ -85,7 +85,7 @@ namespace crow
|
||||||
{
|
{
|
||||||
return body_.substr(action.start, action.end - action.start);
|
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 == ".")
|
if (name == ".")
|
||||||
{
|
{
|
||||||
|
@ -123,7 +123,7 @@ namespace crow
|
||||||
|
|
||||||
for (auto it = stack.rbegin(); it != stack.rend(); ++it)
|
for (auto it = stack.rbegin(); it != stack.rend(); ++it)
|
||||||
{
|
{
|
||||||
context* view = *it;
|
const context* view = *it;
|
||||||
bool found = true;
|
bool found = true;
|
||||||
for (auto jt = names.begin(); jt != names.end(); ++jt)
|
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;
|
int openedBlock = 0;
|
||||||
for (int i = current; i > 0; --i)
|
for (int i = current; i > 0; --i)
|
||||||
|
@ -194,7 +194,7 @@ namespace crow
|
||||||
return false;
|
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;
|
int current = actionBegin;
|
||||||
|
|
||||||
|
@ -360,7 +360,7 @@ namespace crow
|
||||||
rendered_template render() const
|
rendered_template render() const
|
||||||
{
|
{
|
||||||
context empty_ctx;
|
context empty_ctx;
|
||||||
std::vector<context*> stack;
|
std::vector<const context*> stack;
|
||||||
stack.emplace_back(&empty_ctx);
|
stack.emplace_back(&empty_ctx);
|
||||||
|
|
||||||
std::string ret;
|
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
|
/// 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);
|
stack.emplace_back(&ctx);
|
||||||
|
|
||||||
std::string ret;
|
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
|
/// 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);
|
return render(ctx);
|
||||||
}
|
}
|
||||||
|
@ -389,7 +389,7 @@ namespace crow
|
||||||
std::string render_string() const
|
std::string render_string() const
|
||||||
{
|
{
|
||||||
context empty_ctx;
|
context empty_ctx;
|
||||||
std::vector<context*> stack;
|
std::vector<const context*> stack;
|
||||||
stack.emplace_back(&empty_ctx);
|
stack.emplace_back(&empty_ctx);
|
||||||
|
|
||||||
std::string ret;
|
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
|
/// 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);
|
stack.emplace_back(&ctx);
|
||||||
|
|
||||||
std::string ret;
|
std::string ret;
|
||||||
|
|
Loading…
Reference in New Issue