diff options
author | Brian Osman <brianosman@google.com> | 2017-08-09 20:44:31 +0000 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-08-09 20:44:46 +0000 |
commit | a5a69cfb480b99747ddc272149d35c6302abf1bf (patch) | |
tree | 4fa12241ef7c9f87ec1c865011cec14889cf9a64 /src/utils | |
parent | 91326c34ee1f1531d62caa153746821b58e6e55d (diff) |
Revert "Support single line objects and arrays"
This reverts commit 6a7d56fa0f7009be9df36774774f3c337d7c7760.
Reason for revert: Earlier commit needs to be reverted for Chrome roll.
Original change's description:
> Support single line objects and arrays
>
> This is just a formatting nicety. The new caps dump has several large
> arrays of structs, and keeping each object on one line makes them much
> more readable. (It also limits the total length of the output, which
> helps when scanning through).
>
> Example of the output, before and after this change:
> https://gist.github.com/brianosman/872f33be9af49031023b791e7db0b1fb
>
> Bug: skia:
> Change-Id: I0fe0c2241b0c7f451b0837500e554d0491126d5e
> Reviewed-on: https://skia-review.googlesource.com/32820
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Brian Osman <brianosman@google.com>
TBR=bsalomon@google.com,brianosman@google.com
Change-Id: I2b05cf79ca4804e5944f2eb3e17fe4be4d5af290
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/32860
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/SkJSONWriter.h | 45 |
1 files changed, 10 insertions, 35 deletions
diff --git a/src/utils/SkJSONWriter.h b/src/utils/SkJSONWriter.h index 716bd60d9c..9ac28ebc47 100644 --- a/src/utils/SkJSONWriter.h +++ b/src/utils/SkJSONWriter.h @@ -54,14 +54,12 @@ public: , fMode(mode) , fState(State::kStart) { fScopeStack.push_back(Scope::kNone); - fNewlineStack.push_back(true); } ~SkJSONWriter() { this->flush(); delete[] fBlock; SkASSERT(fScopeStack.count() == 1); - SkASSERT(fNewlineStack.count() == 1); } /** @@ -88,7 +86,7 @@ public: if (State::kObjectValue == fState) { this->write(",", 1); } - this->separator(this->multiline()); + this->newline(); this->write("\"", 1); this->write(name, strlen(name)); this->write("\":", 2); @@ -98,17 +96,12 @@ public: /** * Adds a new object. A name must be supplied when called between beginObject() and * endObject(). Calls to beginObject() must be balanced by corresponding calls to endObject(). - * By default, objects are written out with one named value per line (when in kPretty mode). - * This can be overridden for a particular object by passing false for multiline, this will - * keep the entire object on a single line. This can help with readability in some situations. - * In kFast mode, this parameter is ignored. */ - void beginObject(const char* name = nullptr, bool multiline = true) { + void beginObject(const char* name = nullptr) { this->appendName(name); this->beginValue(true); this->write("{", 1); fScopeStack.push_back(Scope::kObject); - fNewlineStack.push_back(multiline); fState = State::kObjectBegin; } @@ -119,10 +112,9 @@ public: SkASSERT(Scope::kObject == this->scope()); SkASSERT(State::kObjectBegin == fState || State::kObjectValue == fState); bool emptyObject = State::kObjectBegin == fState; - bool wasMultiline = this->multiline(); this->popScope(); if (!emptyObject) { - this->separator(wasMultiline); + this->newline(); } this->write("}", 1); } @@ -130,17 +122,12 @@ public: /** * Adds a new array. A name must be supplied when called between beginObject() and * endObject(). Calls to beginArray() must be balanced by corresponding calls to endArray(). - * By default, arrays are written out with one value per line (when in kPretty mode). - * This can be overridden for a particular array by passing false for multiline, this will - * keep the entire array on a single line. This can help with readability in some situations. - * In kFast mode, this parameter is ignored. */ - void beginArray(const char* name = nullptr, bool multiline = true) { + void beginArray(const char* name = nullptr) { this->appendName(name); this->beginValue(true); this->write("[", 1); fScopeStack.push_back(Scope::kArray); - fNewlineStack.push_back(multiline); fState = State::kArrayBegin; } @@ -151,10 +138,9 @@ public: SkASSERT(Scope::kArray == this->scope()); SkASSERT(State::kArrayBegin == fState || State::kArrayValue == fState); bool emptyArray = State::kArrayBegin == fState; - bool wasMultiline = this->multiline(); this->popScope(); if (!emptyArray) { - this->separator(wasMultiline); + this->newline(); } this->write("]", 1); } @@ -273,7 +259,7 @@ private: this->write(",", 1); } if (Scope::kArray == this->scope()) { - this->separator(this->multiline()); + this->newline(); } else if (Scope::kObject == this->scope() && Mode::kPretty == fMode) { this->write(" ", 1); } @@ -284,15 +270,11 @@ private: } } - void separator(bool multiline) { + void newline() { if (Mode::kPretty == fMode) { - if (multiline) { - this->write("\n", 1); - for (int i = 0; i < fScopeStack.count() - 1; ++i) { - this->write(" ", 3); - } - } else { - this->write(" ", 1); + this->write("\n", 1); + for (int i = 0; i < fScopeStack.count() - 1; ++i) { + this->write(" ", 3); } } } @@ -316,14 +298,8 @@ private: return fScopeStack.back(); } - bool multiline() const { - SkASSERT(!fNewlineStack.empty()); - return fNewlineStack.back(); - } - void popScope() { fScopeStack.pop_back(); - fNewlineStack.pop_back(); switch (this->scope()) { case Scope::kNone: fState = State::kEnd; @@ -348,7 +324,6 @@ private: Mode fMode; State fState; SkSTArray<16, Scope, true> fScopeStack; - SkSTArray<16, bool, true> fNewlineStack; }; #endif |