aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/bookmaker/parserCommon.cpp
diff options
context:
space:
mode:
authorGravatar Cary Clark <caryclark@skia.org>2017-07-28 11:04:54 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-28 15:30:38 +0000
commit8032b983faaa8c76f81bf3cf028e9c64f4635478 (patch)
treeed3be061ff02a99dab1b3e443d48b7f5c906417e /tools/bookmaker/parserCommon.cpp
parentacaa607328fb0dfac0894d4a2fcdead520e696b3 (diff)
bookmaker initial checkin
bookmaker is a tool that generates documentation backends from a canonical markup. Documentation for bookmaker itself is evolving at docs/usingBookmaker.bmh, which is visible online at skia.org/user/api/bmh_usingBookmaker Change-Id: Ic76ddf29134895b5c2ebfbc84603e40ff08caf09 Reviewed-on: https://skia-review.googlesource.com/28000 Commit-Queue: Cary Clark <caryclark@google.com> Reviewed-by: Cary Clark <caryclark@google.com>
Diffstat (limited to 'tools/bookmaker/parserCommon.cpp')
-rw-r--r--tools/bookmaker/parserCommon.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/tools/bookmaker/parserCommon.cpp b/tools/bookmaker/parserCommon.cpp
new file mode 100644
index 0000000000..cb55bcb640
--- /dev/null
+++ b/tools/bookmaker/parserCommon.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "bookmaker.h"
+
+bool ParserCommon::parseSetup(const char* path) {
+ this->reset();
+ sk_sp<SkData> data = SkData::MakeFromFileName(path);
+ if (nullptr == data.get()) {
+ SkDebugf("%s missing\n", path);
+ return false;
+ }
+ const char* rawText = (const char*) data->data();
+ bool hasCR = false;
+ size_t dataSize = data->size();
+ for (size_t index = 0; index < dataSize; ++index) {
+ if ('\r' == rawText[index]) {
+ hasCR = true;
+ break;
+ }
+ }
+ string name(path);
+ if (hasCR) {
+ vector<char> lfOnly;
+ for (size_t index = 0; index < dataSize; ++index) {
+ char ch = rawText[index];
+ if ('\r' == rawText[index]) {
+ ch = '\n';
+ if ('\n' == rawText[index + 1]) {
+ ++index;
+ }
+ }
+ lfOnly.push_back(ch);
+ }
+ fLFOnly[name] = lfOnly;
+ dataSize = lfOnly.size();
+ rawText = &fLFOnly[name].front();
+ }
+ fRawData[name] = data;
+ fStart = rawText;
+ fLine = rawText;
+ fChar = rawText;
+ fEnd = rawText + dataSize;
+ fFileName = string(path);
+ fLineCount = 1;
+ return true;
+}