123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #include "precomp_wasabi_bfc.h"
- #include "hierarchyparser.h"
- #include <bfc/nsguid.h>
- #include <wchar.h>
- HierarchyParser::HierarchyParser(const wchar_t *str, const wchar_t *_sibling, const wchar_t *_escape, const wchar_t *_parent_open, const wchar_t *_parent_close) {
-
- rootnode = new HPNode(str);
-
- HierarchyParser downparse(rootnode, _sibling, _escape, _parent_open, _parent_close);
-
- (*rootnode)() = L"";
-
- myalloc = 1;
- }
- HierarchyParser::~HierarchyParser() {
-
- if (myalloc) {
- delete rootnode;
- }
- }
- HPNode *HierarchyParser::findGuid(GUID g) {
- return NULL;
- }
- HPNode *HierarchyParser::findString(const wchar_t *str) {
- return NULL;
- }
- HierarchyParser::HierarchyParser(HPNode *_rootnode, const wchar_t *_sibling, const wchar_t *_escape, const wchar_t *_parent_open, const wchar_t *_parent_close) {
-
- rootnode = _rootnode;
- sibling = _sibling;
- escape = _escape;
- parent_open = _parent_open;
- parent_close = _parent_close;
- myalloc = 0;
- const wchar_t *parsestr = (*rootnode)();
- size_t i, length = wcslen(parsestr), depth = 0;
- StringW curr_sibling;
- for (i = 0; i < length; i++ ) {
- wchar_t c = parsestr[i];
- if (isEscape(c)) {
-
- curr_sibling += parsestr[++i];
- } else if (isSibling(c)) {
-
- if (!depth) {
-
- processSibling(curr_sibling);
-
- curr_sibling = L"";
- } else {
- curr_sibling += c;
- }
- } else if (isParentOpen(c)) {
-
- curr_sibling += c;
- depth++;
- } else if (isParentClose(c)) {
-
- curr_sibling += c;
- depth--;
- } else {
- curr_sibling += c;
- }
- }
-
- if (curr_sibling.len()) {
- processSibling(curr_sibling);
- }
- }
- void HierarchyParser::processSibling(const wchar_t *sibstr) {
- StringW curr_sibling = sibstr;
-
- StringW sibling_name = curr_sibling.lSpliceChar(parent_open);
-
- curr_sibling.rSpliceChar(parent_close);
-
- HPNode *child = new HPNode(curr_sibling, rootnode);
-
- HierarchyParser childparser(child, sibling, escape, parent_open, parent_close);
-
- (*child)() = sibling_name;
-
- rootnode->addChild(child);
- }
|