blob: 0ab8cb19080a25343978b1ccfeba0b510667349a [file] [log] [blame]
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +00001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 *
7 * Helper functions for result writing operations.
8 */
9
10#include "ResultsWriter.h"
kelvinly4d1a3642014-06-26 11:26:40 -070011#include "SkString.h"
12#include "SkTArray.h"
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +000013
commit-bot@chromium.org37c772a2014-05-29 17:10:24 +000014Json::Value* SkFindNamedNode(Json::Value* root, const char name[]) {
15 Json::Value* search_results = NULL;
16 for(Json::Value::iterator iter = root->begin();
17 iter!= root->end(); ++iter) {
18 if(SkString(name).equals((*iter)["name"].asCString())) {
19 search_results = &(*iter);
20 break;
21 }
22 }
23
24 if(search_results != NULL) {
25 return search_results;
26 } else {
27 Json::Value* new_val = &(root->append(Json::Value()));
28 (*new_val)["name"] = name;
29 return new_val;
30 }
31}
32
kelvinly4d1a3642014-06-26 11:26:40 -070033Json::Value SkMakeBuilderJSON(const SkString &builderName) {
34 static const int kNumKeys = 6;
35 static const char* kKeys[kNumKeys] = {
36 "role", "os", "model", "gpu", "arch", "configuration"};
37 Json::Value builderData;
38
39 if (!builderName.isEmpty()) {
40 SkTArray<SkString> splitBuilder;
41 SkStrSplit(builderName.c_str(), "-", &splitBuilder);
42 SkASSERT(splitBuilder.count() >= kNumKeys);
43 for (int i = 0; i < kNumKeys && i < splitBuilder.count(); ++i) {
44 builderData[kKeys[i]] = splitBuilder[i].c_str();
45 }
46 builderData["builderName"] = builderName.c_str();
47 if (kNumKeys < splitBuilder.count()) {
48 SkString extras;
49 for (int i = kNumKeys; i < splitBuilder.count(); ++i) {
50 extras.append(splitBuilder[i]);
51 if (i != splitBuilder.count() - 1) {
52 extras.append("-");
53 }
54 }
55 builderData["badParams"] = extras.c_str();
56 }
57 }
58 return builderData;
59}