Skip to content

Commit ef16a35

Browse files
damiramdamiram
damiram
authored and
damiram
committed
Fixing warnings. Added JSONCPP_DEPRECATED definition for clang. Also updating .gitignore to ignore .DS_Store files (Mac OS Finder generated)
1 parent 7354da8 commit ef16a35

File tree

7 files changed

+57
-10
lines changed

7 files changed

+57
-10
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,6 @@ jsoncpp_lib_static.dir/
5050
.project
5151
.cproject
5252
/.settings/
53+
54+
# DS_Store
55+
.DS_Store

include/json/config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@
120120
#endif
121121

122122
#ifdef __clang__
123+
# if __has_extension(attribute_deprecated_with_message)
124+
# define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message)))
125+
# endif
123126
#elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc)
124127
# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
125128
# define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message)))

include/json/reader.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace Json {
3232
*
3333
* \deprecated Use CharReader and CharReaderBuilder.
3434
*/
35-
class JSON_API Reader {
35+
class JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead") JSON_API Reader {
3636
public:
3737
typedef char Char;
3838
typedef const Char* Location;
@@ -230,6 +230,9 @@ class JSON_API Reader {
230230
void addComment(Location begin, Location end, CommentPlacement placement);
231231
void skipCommentTokens(Token& token);
232232

233+
static bool containsNewLine(Location begin, Location end);
234+
static JSONCPP_STRING normalizeEOL(Location begin, Location end);
235+
233236
typedef std::stack<Value*> Nodes;
234237
Nodes nodes_;
235238
Errors errors_;

include/json/value.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,12 @@ Json::Value obj_value(Json::objectValue); // {}
518518
/// \pre type() is objectValue or nullValue
519519
/// \post type() is unchanged
520520
/// \deprecated
521+
JSONCPP_DEPRECATED("")
521522
Value removeMember(const char* key);
522523
/// Same as removeMember(const char*)
523524
/// \param key may contain embedded nulls.
524525
/// \deprecated
526+
JSONCPP_DEPRECATED("")
525527
Value removeMember(const JSONCPP_STRING& key);
526528
/// Same as removeMember(const char* begin, const char* end, Value* removed),
527529
/// but 'key' is null-terminated.

include/json/writer.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class JSON_API StreamWriterBuilder : public StreamWriter::Factory {
140140
/** \brief Abstract class for writers.
141141
* \deprecated Use StreamWriter. (And really, this is an implementation detail.)
142142
*/
143-
class JSON_API Writer {
143+
class JSONCPP_DEPRECATED("Use StreamWriter instead") JSON_API Writer {
144144
public:
145145
virtual ~Writer();
146146

@@ -156,7 +156,7 @@ class JSON_API Writer {
156156
* \sa Reader, Value
157157
* \deprecated Use StreamWriterBuilder.
158158
*/
159-
class JSON_API FastWriter : public Writer {
159+
class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API FastWriter : public Writer {
160160

161161
public:
162162
FastWriter();
@@ -209,7 +209,7 @@ class JSON_API FastWriter : public Writer {
209209
* \sa Reader, Value, Value::setComment()
210210
* \deprecated Use StreamWriterBuilder.
211211
*/
212-
class JSON_API StyledWriter : public Writer {
212+
class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API StyledWriter : public Writer {
213213
public:
214214
StyledWriter();
215215
~StyledWriter() JSONCPP_OVERRIDE {}
@@ -267,12 +267,14 @@ class JSON_API StyledWriter : public Writer {
267267
* If the Value have comments then they are outputed according to their
268268
#CommentPlacement.
269269
*
270-
* \param indentation Each level will be indented by this amount extra.
271270
* \sa Reader, Value, Value::setComment()
272271
* \deprecated Use StreamWriterBuilder.
273272
*/
274-
class JSON_API StyledStreamWriter {
273+
class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API StyledStreamWriter {
275274
public:
275+
/**
276+
* \param indentation Each level will be indented by this amount extra.
277+
*/
276278
StyledStreamWriter(JSONCPP_STRING indentation = "\t");
277279
~StyledStreamWriter() {}
278280

src/lib_json/json_reader.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Features Features::strictMode() {
8181
// Implementation of class Reader
8282
// ////////////////////////////////
8383

84-
static bool containsNewLine(Reader::Location begin, Reader::Location end) {
84+
bool Reader::containsNewLine(Reader::Location begin, Reader::Location end) {
8585
for (; begin < end; ++begin)
8686
if (*begin == '\n' || *begin == '\r')
8787
return true;
@@ -370,7 +370,7 @@ bool Reader::readComment() {
370370
return true;
371371
}
372372

373-
static JSONCPP_STRING normalizeEOL(Reader::Location begin, Reader::Location end) {
373+
JSONCPP_STRING Reader::normalizeEOL(Reader::Location begin, Reader::Location end) {
374374
JSONCPP_STRING normalized;
375375
normalized.reserve(static_cast<size_t>(end - begin));
376376
Reader::Location current = begin;
@@ -1019,6 +1019,9 @@ class OurReader {
10191019
void addComment(Location begin, Location end, CommentPlacement placement);
10201020
void skipCommentTokens(Token& token);
10211021

1022+
static JSONCPP_STRING normalizeEOL(Location begin, Location end);
1023+
static bool containsNewLine(Location begin, Location end);
1024+
10221025
typedef std::stack<Value*> Nodes;
10231026
Nodes nodes_;
10241027
Errors errors_;
@@ -1036,6 +1039,13 @@ class OurReader {
10361039

10371040
// complete copy of Read impl, for OurReader
10381041

1042+
bool OurReader::containsNewLine(OurReader::Location begin, OurReader::Location end) {
1043+
for (; begin < end; ++begin)
1044+
if (*begin == '\n' || *begin == '\r')
1045+
return true;
1046+
return false;
1047+
}
1048+
10391049
OurReader::OurReader(OurFeatures const& features)
10401050
: errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(),
10411051
lastValue_(), commentsBefore_(),
@@ -1345,6 +1355,25 @@ bool OurReader::readComment() {
13451355
return true;
13461356
}
13471357

1358+
JSONCPP_STRING OurReader::normalizeEOL(OurReader::Location begin, OurReader::Location end) {
1359+
JSONCPP_STRING normalized;
1360+
normalized.reserve(static_cast<size_t>(end - begin));
1361+
OurReader::Location current = begin;
1362+
while (current != end) {
1363+
char c = *current++;
1364+
if (c == '\r') {
1365+
if (current != end && *current == '\n')
1366+
// convert dos EOL
1367+
++current;
1368+
// convert Mac EOL
1369+
normalized += '\n';
1370+
} else {
1371+
normalized += c;
1372+
}
1373+
}
1374+
return normalized;
1375+
}
1376+
13481377
void
13491378
OurReader::addComment(Location begin, Location end, CommentPlacement placement) {
13501379
assert(collectComments_);

src/lib_json/json_value.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,8 +1453,13 @@ ptrdiff_t Value::getOffsetStart() const { return start_; }
14531453
ptrdiff_t Value::getOffsetLimit() const { return limit_; }
14541454

14551455
JSONCPP_STRING Value::toStyledString() const {
1456-
StyledWriter writer;
1457-
return writer.write(*this);
1456+
StreamWriterBuilder builder;
1457+
1458+
JSONCPP_STRING out = this->hasComment(commentBefore) ? "\n" : "";
1459+
out += Json::writeString(builder, *this);
1460+
out += "\n";
1461+
1462+
return out;
14581463
}
14591464

14601465
Value::const_iterator Value::begin() const {

0 commit comments

Comments
 (0)