blob: cb55bcb640ba24a974179115f88a35cee9c1ab27 [file] [log] [blame]
Cary Clark8032b982017-07-28 11:04:54 -04001/*
2 * Copyright 2017 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
8#include "bookmaker.h"
9
10bool ParserCommon::parseSetup(const char* path) {
11 this->reset();
12 sk_sp<SkData> data = SkData::MakeFromFileName(path);
13 if (nullptr == data.get()) {
14 SkDebugf("%s missing\n", path);
15 return false;
16 }
17 const char* rawText = (const char*) data->data();
18 bool hasCR = false;
19 size_t dataSize = data->size();
20 for (size_t index = 0; index < dataSize; ++index) {
21 if ('\r' == rawText[index]) {
22 hasCR = true;
23 break;
24 }
25 }
26 string name(path);
27 if (hasCR) {
28 vector<char> lfOnly;
29 for (size_t index = 0; index < dataSize; ++index) {
30 char ch = rawText[index];
31 if ('\r' == rawText[index]) {
32 ch = '\n';
33 if ('\n' == rawText[index + 1]) {
34 ++index;
35 }
36 }
37 lfOnly.push_back(ch);
38 }
39 fLFOnly[name] = lfOnly;
40 dataSize = lfOnly.size();
41 rawText = &fLFOnly[name].front();
42 }
43 fRawData[name] = data;
44 fStart = rawText;
45 fLine = rawText;
46 fChar = rawText;
47 fEnd = rawText + dataSize;
48 fFileName = string(path);
49 fLineCount = 1;
50 return true;
51}