| 1 |
/* |
| 2 |
* Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2020 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-runtime-lib |
| 6 |
* Created on: 30 апр. 2020 г. |
| 7 |
* |
| 8 |
* lsp-runtime-lib is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU Lesser General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* lsp-runtime-lib is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include <lsp-plug.in/fmt/config/PushParser.h> |
| 23 |
|
| 24 |
namespace lsp |
| 25 |
{ |
| 26 |
namespace config |
| 27 |
{ |
| 28 |
|
| 29 |
PushParser::PushParser() |
| 30 |
{ |
| 31 |
} |
| 32 |
|
| 33 |
PushParser::~PushParser() |
| 34 |
{ |
| 35 |
} |
| 36 |
|
| 37 |
status_t PushParser::parse_file(IConfigHandler *handler, const char *path, const char *charset) |
| 38 |
{ |
| 39 |
IConfigHandler stub; |
| 40 |
status_t res = sParser.open(path, charset); |
| 41 |
if (res == STATUS_OK) |
| 42 |
res = parse_document((handler != NULL) ? handler : &stub); |
| 43 |
if (res == STATUS_OK) |
| 44 |
res = sParser.close(); |
| 45 |
else |
| 46 |
sParser.close(); |
| 47 |
return res; |
| 48 |
} |
| 49 |
|
| 50 |
status_t PushParser::parse_file(IConfigHandler *handler, const LSPString *path, const char *charset) |
| 51 |
{ |
| 52 |
IConfigHandler stub; |
| 53 |
status_t res = sParser.open(path, charset); |
| 54 |
if (res == STATUS_OK) |
| 55 |
res = parse_document((handler != NULL) ? handler : &stub); |
| 56 |
if (res == STATUS_OK) |
| 57 |
res = sParser.close(); |
| 58 |
else |
| 59 |
sParser.close(); |
| 60 |
return res; |
| 61 |
} |
| 62 |
|
| 63 |
status_t PushParser::parse_file(IConfigHandler *handler, const io::Path *path, const char *charset) |
| 64 |
{ |
| 65 |
IConfigHandler stub; |
| 66 |
status_t res = sParser.open(path, charset); |
| 67 |
if (res == STATUS_OK) |
| 68 |
res = parse_document((handler != NULL) ? handler : &stub); |
| 69 |
if (res == STATUS_OK) |
| 70 |
res = sParser.close(); |
| 71 |
else |
| 72 |
sParser.close(); |
| 73 |
return res; |
| 74 |
} |
| 75 |
|
| 76 |
status_t PushParser::parse_data(IConfigHandler *handler, io::IInStream *is, size_t flags, const char *charset) |
| 77 |
{ |
| 78 |
IConfigHandler stub; |
| 79 |
status_t res = sParser.wrap(is, flags, charset); |
| 80 |
if (res == STATUS_OK) |
| 81 |
res = parse_document((handler != NULL) ? handler : &stub); |
| 82 |
if (res == STATUS_OK) |
| 83 |
res = sParser.close(); |
| 84 |
else |
| 85 |
sParser.close(); |
| 86 |
return res; |
| 87 |
} |
| 88 |
|
| 89 |
status_t PushParser::parse_data(IConfigHandler *handler, const char *str, const char *charset) |
| 90 |
{ |
| 91 |
IConfigHandler stub; |
| 92 |
status_t res = sParser.wrap(str, charset); |
| 93 |
if (res == STATUS_OK) |
| 94 |
res = parse_document((handler != NULL) ? handler : &stub); |
| 95 |
if (res == STATUS_OK) |
| 96 |
res = sParser.close(); |
| 97 |
else |
| 98 |
sParser.close(); |
| 99 |
return res; |
| 100 |
} |
| 101 |
|
| 102 |
status_t PushParser::parse_data(IConfigHandler *handler, const LSPString *str) |
| 103 |
{ |
| 104 |
IConfigHandler stub; |
| 105 |
status_t res = sParser.wrap(str); |
| 106 |
if (res == STATUS_OK) |
| 107 |
res = parse_document((handler != NULL) ? handler : &stub); |
| 108 |
if (res == STATUS_OK) |
| 109 |
res = sParser.close(); |
| 110 |
else |
| 111 |
sParser.close(); |
| 112 |
return res; |
| 113 |
} |
| 114 |
|
| 115 |
status_t PushParser::parse_data(IConfigHandler *handler, io::IInSequence *seq, size_t flags) |
| 116 |
{ |
| 117 |
IConfigHandler stub; |
| 118 |
status_t res = sParser.wrap(seq, flags); |
| 119 |
if (res == STATUS_OK) |
| 120 |
res = parse_document((handler != NULL) ? handler : &stub); |
| 121 |
if (res == STATUS_OK) |
| 122 |
res = sParser.close(); |
| 123 |
else |
| 124 |
sParser.close(); |
| 125 |
return res; |
| 126 |
} |
| 127 |
|
| 128 |
status_t PushParser::parse_document(IConfigHandler *handler) |
| 129 |
{ |
| 130 |
// Indicate start of parsing |
| 131 |
status_t res = handler->start(); |
| 132 |
if (res != STATUS_OK) |
| 133 |
return res; |
| 134 |
|
| 135 |
// Main loop |
| 136 |
while ((res = sParser.next()) == STATUS_OK) |
| 137 |
{ |
| 138 |
if ((res = handler->handle(sParser.current())) != STATUS_OK) |
| 139 |
break; |
| 140 |
} |
| 141 |
|
| 142 |
if (res == STATUS_EOF) |
| 143 |
res = STATUS_OK; |
| 144 |
|
| 145 |
// Always indicate end of parsing |
| 146 |
return handler->finish(res); |
| 147 |
} |
| 148 |
|
| 149 |
} /* namespace config */ |
| 150 |
} /* namespace lsp */ |