Skip to content

Commit fa8ddbc

Browse files
committed
bracket operator non-const char*
1 parent e4b0547 commit fa8ddbc

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

include/hjson/hjson.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ class Value {
169169
MapProxy operator[](const std::string&);
170170
const Value operator[](const char*) const;
171171
MapProxy operator[](const char*);
172+
const Value operator[](char*) const;
173+
MapProxy operator[](char*);
172174
const Value& operator[](int) const;
173175
Value& operator[](int);
174176

src/hjson_value.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,16 @@ MapProxy Value::operator[](const char *input) {
390390
}
391391

392392

393+
const Value Value::operator[](char *input) const {
394+
return operator[](std::string(input));
395+
}
396+
397+
398+
MapProxy Value::operator[](char *input) {
399+
return operator[](std::string(input));
400+
}
401+
402+
393403
const Value& Value::operator[](int index) const {
394404
switch (prv->type)
395405
{

test/test_value.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,16 @@ void test_value() {
509509
assert(itConst == valConst.end());
510510
}
511511

512+
{
513+
Hjson::Value val;
514+
val["first"] = "leaf1";
515+
char szKey[20];
516+
sprintf(szKey, "first");
517+
assert(val[szKey] == "leaf1");
518+
char *szKey2 = szKey;
519+
assert(val[szKey2] == "leaf1");
520+
}
521+
512522
{
513523
Hjson::Value val;
514524

0 commit comments

Comments
 (0)