Skip to content
This repository was archived by the owner on Jun 17, 2022. It is now read-only.

Commit d208f98

Browse files
committed
Cleaned up namespace imports to reduce symbol collisions
1 parent 8a2d6f1 commit d208f98

File tree

5 files changed

+27
-36
lines changed

5 files changed

+27
-36
lines changed

gen/gen.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include <string.h>
1313
#include "univalue.h"
1414

15-
using namespace std;
16-
1715
static bool initEscapes;
1816
static std::string escapes[256];
1917

lib/univalue.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
#include "univalue.h"
1212

13-
using namespace std;
14-
1513
const UniValue NullUniValue;
1614

1715
void UniValue::clear()
@@ -37,15 +35,15 @@ bool UniValue::setBool(bool val_)
3735
return true;
3836
}
3937

40-
static bool validNumStr(const string& s)
38+
static bool validNumStr(const std::string& s)
4139
{
42-
string tokenVal;
40+
std::string tokenVal;
4341
unsigned int consumed;
4442
enum jtokentype tt = getJsonToken(tokenVal, consumed, s.data(), s.data() + s.size());
4543
return (tt == JTOK_NUMBER);
4644
}
4745

48-
bool UniValue::setNumStr(const string& val_)
46+
bool UniValue::setNumStr(const std::string& val_)
4947
{
5048
if (!validNumStr(val_))
5149
return false;
@@ -58,7 +56,7 @@ bool UniValue::setNumStr(const string& val_)
5856

5957
bool UniValue::setInt(uint64_t val_)
6058
{
61-
ostringstream oss;
59+
std::ostringstream oss;
6260

6361
oss << val_;
6462

@@ -67,7 +65,7 @@ bool UniValue::setInt(uint64_t val_)
6765

6866
bool UniValue::setInt(int64_t val_)
6967
{
70-
ostringstream oss;
68+
std::ostringstream oss;
7169

7270
oss << val_;
7371

@@ -76,7 +74,7 @@ bool UniValue::setInt(int64_t val_)
7674

7775
bool UniValue::setFloat(double val_)
7876
{
79-
ostringstream oss;
77+
std::ostringstream oss;
8078

8179
oss << std::setprecision(16) << val_;
8280

@@ -85,7 +83,7 @@ bool UniValue::setFloat(double val_)
8583
return ret;
8684
}
8785

88-
bool UniValue::setStr(const string& val_)
86+
bool UniValue::setStr(const std::string& val_)
8987
{
9088
clear();
9189
typ = VSTR;

lib/univalue_read.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include "univalue.h"
99
#include "univalue_utffilter.h"
1010

11-
using namespace std;
12-
1311
static bool json_isdigit(int ch)
1412
{
1513
return ((ch >= '0') && (ch <= '9'));
@@ -42,7 +40,7 @@ static const char *hatoui(const char *first, const char *last,
4240
return first;
4341
}
4442

45-
enum jtokentype getJsonToken(string& tokenVal, unsigned int& consumed,
43+
enum jtokentype getJsonToken(std::string& tokenVal, unsigned int& consumed,
4644
const char *raw, const char *end)
4745
{
4846
tokenVal.clear();
@@ -114,7 +112,7 @@ enum jtokentype getJsonToken(string& tokenVal, unsigned int& consumed,
114112
case '8':
115113
case '9': {
116114
// part 1: int
117-
string numStr;
115+
std::string numStr;
118116

119117
const char *first = raw;
120118

@@ -174,7 +172,7 @@ enum jtokentype getJsonToken(string& tokenVal, unsigned int& consumed,
174172
case '"': {
175173
raw++; // skip "
176174

177-
string valStr;
175+
std::string valStr;
178176
JSONUTF8StringFilter writer(valStr);
179177

180178
while (true) {
@@ -255,9 +253,9 @@ bool UniValue::read(const char *raw, size_t size)
255253
clear();
256254

257255
uint32_t expectMask = 0;
258-
vector<UniValue*> stack;
256+
std::vector<UniValue*> stack;
259257

260-
string tokenVal;
258+
std::string tokenVal;
261259
unsigned int consumed;
262260
enum jtokentype tok = JTOK_NONE;
263261
enum jtokentype last_tok = JTOK_NONE;

lib/univalue_write.cpp

+8-10
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
#include "univalue.h"
99
#include "univalue_escapes.h"
1010

11-
using namespace std;
12-
13-
static string json_escape(const string& inS)
11+
static std::string json_escape(const std::string& inS)
1412
{
15-
string outS;
13+
std::string outS;
1614
outS.reserve(inS.size() * 2);
1715

1816
for (unsigned int i = 0; i < inS.size(); i++) {
@@ -28,10 +26,10 @@ static string json_escape(const string& inS)
2826
return outS;
2927
}
3028

31-
string UniValue::write(unsigned int prettyIndent,
32-
unsigned int indentLevel) const
29+
std::string UniValue::write(unsigned int prettyIndent,
30+
unsigned int indentLevel) const
3331
{
34-
string s;
32+
std::string s;
3533
s.reserve(1024);
3634

3735
unsigned int modIndent = indentLevel;
@@ -62,12 +60,12 @@ string UniValue::write(unsigned int prettyIndent,
6260
return s;
6361
}
6462

65-
static void indentStr(unsigned int prettyIndent, unsigned int indentLevel, string& s)
63+
static void indentStr(unsigned int prettyIndent, unsigned int indentLevel, std::string& s)
6664
{
6765
s.append(prettyIndent * indentLevel, ' ');
6866
}
6967

70-
void UniValue::writeArray(unsigned int prettyIndent, unsigned int indentLevel, string& s) const
68+
void UniValue::writeArray(unsigned int prettyIndent, unsigned int indentLevel, std::string& s) const
7169
{
7270
s += "[";
7371
if (prettyIndent)
@@ -89,7 +87,7 @@ void UniValue::writeArray(unsigned int prettyIndent, unsigned int indentLevel, s
8987
s += "]";
9088
}
9189

92-
void UniValue::writeObject(unsigned int prettyIndent, unsigned int indentLevel, string& s) const
90+
void UniValue::writeObject(unsigned int prettyIndent, unsigned int indentLevel, std::string& s) const
9391
{
9492
s += "{";
9593
if (prettyIndent)

test/unitester.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
1818
#endif
1919

20-
using namespace std;
21-
string srcdir(JSON_TEST_SRC);
20+
std::string srcdir(JSON_TEST_SRC);
2221
static bool test_failed = false;
2322

2423
#define d_assert(expr) { if (!(expr)) { test_failed = true; fprintf(stderr, "%s failed\n", filename.c_str()); } }
@@ -30,9 +29,9 @@ static std::string rtrim(std::string s)
3029
return s;
3130
}
3231

33-
static void runtest(string filename, const string& jdata)
32+
static void runtest(std::string filename, const std::string& jdata)
3433
{
35-
string prefix = filename.substr(0, 4);
34+
std::string prefix = filename.substr(0, 4);
3635

3736
bool wantPass = (prefix == "pass") || (prefix == "roun");
3837
bool wantFail = (prefix == "fail");
@@ -56,19 +55,19 @@ static void runtest(string filename, const string& jdata)
5655

5756
static void runtest_file(const char *filename_)
5857
{
59-
string basename(filename_);
60-
string filename = srcdir + "/" + basename;
58+
std::string basename(filename_);
59+
std::string filename = srcdir + "/" + basename;
6160
FILE *f = fopen(filename.c_str(), "r");
6261
assert(f != NULL);
6362

64-
string jdata;
63+
std::string jdata;
6564

6665
char buf[4096];
6766
while (!feof(f)) {
6867
int bread = fread(buf, 1, sizeof(buf), f);
6968
assert(!ferror(f));
7069

71-
string s(buf, bread);
70+
std::string s(buf, bread);
7271
jdata += s;
7372
}
7473

0 commit comments

Comments
 (0)