Skip to content

Commit 5eae434

Browse files
Update WebForms.h
1 parent 47a3b45 commit 5eae434

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

cpp/WebForms.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,24 @@ class NameValueCollection {
8686
}
8787

8888
void ChangeValueByIndex(int index, const std::string& value) {
89-
if (index >= 0 && index < data.size()) {
90-
data[index].Value = value;
89+
int idx = (index >= 0) ? index : data.size() + index;
90+
if (idx >= 0 && idx < data.size()) {
91+
data[idx].Value = value;
9192
}
9293
}
9394

9495
void ChangeNameByIndex(int index, const std::string& newName) {
95-
if (index >= 0 && index < data.size()) {
96-
data[index].Name = newName;
96+
int idx = (index >= 0) ? index : data.size() + index;
97+
if (idx >= 0 && idx < data.size()) {
98+
data[idx].Name = newName;
9799
}
98100
}
99101

100102
void ChangeNameValueByIndex(int index, const std::string& newName, const std::string& value) {
101-
if (index >= 0 && index < data.size()) {
102-
data[index].Name = newName;
103-
data[index].Value = value;
103+
int idx = (index >= 0) ? index : data.size() + index;
104+
if (idx >= 0 && idx < data.size()) {
105+
data[idx].Name = newName;
106+
data[idx].Value = value;
104107
}
105108
}
106109

@@ -122,15 +125,17 @@ class NameValueCollection {
122125
}
123126

124127
std::string GetNameByIndex(int index) {
125-
if (index >= 0 && index < data.size()) {
126-
return data[index].Name;
128+
int idx = (index >= 0) ? index : data.size() + index;
129+
if (idx >= 0 && idx < data.size()) {
130+
return data[idx].Name;
127131
}
128132
return "";
129133
}
130134

131135
std::string GetValueByIndex(int index) {
132-
if (index >= 0 && index < data.size()) {
133-
return data[index].Value;
136+
int idx = (index >= 0) ? index : data.size() + index;
137+
if (idx >= 0 && idx < data.size()) {
138+
return data[idx].Value;
134139
}
135140
return "";
136141
}

0 commit comments

Comments
 (0)