| Index: experimental/docs/jsonReader.cpp
|
| diff --git a/experimental/docs/jsonReader.cpp b/experimental/docs/jsonReader.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3c5fa2fdcdb0eb1c053f6d14c3982cb7ee34393a
|
| --- /dev/null
|
| +++ b/experimental/docs/jsonReader.cpp
|
| @@ -0,0 +1,66 @@
|
| +/*
|
| + * Copyright 2006 The Android Open Source Project
|
| + *
|
| + * Use of this source code is governed by a BSD-style license that can be
|
| + * found in the LICENSE file.
|
| + */
|
| +
|
| +#include "SkTArray.h"
|
| +#include "SkTDict.h"
|
| +#include "SkString.h"
|
| +
|
| +enum ReadState {
|
| + kRoot_ReadState,
|
| +
|
| +};
|
| +
|
| +static bool isToken(const char* s, const char* e) {
|
| + SkASSERT(s < e);
|
| + while (s < e) {
|
| + char c = *s++;
|
| + char u = c & ~0x20;
|
| + if ((u < 'A' || u > 'Z') && (c < '0' || c > '9') && c != '_') {
|
| + return false;
|
| + }
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +static void skpWhiteSpace(const char** strPtr) {
|
| + const char* str = *strPtr;
|
| + while (*str && *str <= ' ') {
|
| + str++;
|
| + }
|
| + *strPtr = str;
|
| +}
|
| +
|
| +static void ReadRoot(const char** strPtr) {
|
| + skipWhiteSpace(strPtr);
|
| + const char* str = *strPtr;
|
| + const char kVarStr[] = "var ";
|
| + SkASSERT(SkStrStartsWith(str, kVarStr));
|
| + const char* rootVar = str + sizeof(kVarStr) - 1;
|
| + const char* rootEnd = strchr(rootVar, ' ');
|
| + SkASSERT(rootEnd);
|
| + SkASSERT(isToken(rootVar, rootEnd));
|
| + const char* rootAssign = rootEnd;
|
| + skipWhiteSpace(rootAssign);
|
| + SkASSERT(rootAssign[0] == '=');
|
| + const char* rootData = rootAssign + 1;
|
| + SkASSERT(rootData[0]);
|
| + skipWhiteSpace(rootData);
|
| + if (rootData[0] == '{') {
|
| + addObject(rootVar, rootEnd);
|
| + } else if (rootData[0] == '[') {
|
| + addArray(rootVar, rootEnd);
|
| + } else {
|
| + SkASSERT(0);
|
| + }
|
| + *strPtr = str;
|
| +}
|
| +
|
| +static void reader(const char* str) {
|
| + while (*str) {
|
| + ReadRoot(&str);
|
| + }
|
| +}
|
|
|