| 71 | } |
| 72 | |
| 73 | void BoxedReg::writeKey(const char* path, const char* key, const char* value, bool useQuotesAroundValue) { |
| 74 | bool found = false; |
| 75 | BString section = B("["); |
| 76 | section += path; |
| 77 | section += "]"; |
| 78 | section.replace("\\", "\\\\"); |
| 79 | BString searchKey = B("\""); |
| 80 | searchKey += key; |
| 81 | searchKey += "\"="; |
| 82 | |
| 83 | for (size_t i = 0; i < lines.size(); i++) { |
| 84 | BString& line = lines[i]; |
| 85 | if (!found) { |
| 86 | if (line.startsWith(section)) { |
| 87 | found = true; |
| 88 | } |
| 89 | } else { |
| 90 | if (line.startsWith("[")) { |
| 91 | if (value) { |
| 92 | BString p = B("\""); |
| 93 | p += key; |
| 94 | p += "\"="; |
| 95 | if (useQuotesAroundValue) { |
| 96 | p += "\""; |
| 97 | } |
| 98 | p += value; |
| 99 | if (useQuotesAroundValue) { |
| 100 | p += "\""; |
| 101 | } |
| 102 | lines.insert(lines.begin() + i - 1, p); |
| 103 | } |
| 104 | return; |
| 105 | } |
| 106 | if (line.startsWith(searchKey)) { |
| 107 | if (value) { |
| 108 | line = "\""; |
| 109 | line += key; |
| 110 | line += "\"="; |
| 111 | if (useQuotesAroundValue) { |
| 112 | line += "\""; |
| 113 | } |
| 114 | line += value; |
| 115 | if (useQuotesAroundValue) { |
| 116 | line += "\""; |
| 117 | } |
| 118 | } else { |
| 119 | lines.erase(lines.begin() + i); |
| 120 | i--; |
| 121 | } |
| 122 | return; |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | if (value) { |
| 127 | BString line = B("\""); |
| 128 | line += key; |
| 129 | line += "\"="; |
| 130 | if (useQuotesAroundValue) { |
no test coverage detected