Example #1
0
File: Parse.cpp Project: juherr/fit
  void ceefit_call_spec PARSE::Construct(const STRING& text, const DYNARRAY<STRING>& tags, int level, int offset)
  {
    STRING lc(text.ToLowercase());
    int startTag = lc.IndexOf(STRING("<")+tags[level]);
    int endTag = lc.IndexOf(STRING(">"), startTag) + 1;
    //int startEnd = lc.IndexOf(STRING("</")+tags[level], endTag);
		int startEnd = findMatchingEndTag(lc, endTag, tags[level], offset);
    int endEnd = lc.IndexOf(STRING(">"), startEnd) + 1;
    int startMore = lc.IndexOf(STRING("<") + tags[level], endEnd);
    if (startTag<0 || endTag<0 || startEnd<0 || endEnd<0)
    {
      throw new PARSEEXCEPTION(STRING("Can't find tag: ") + GetTagsStrings()[level], offset);
    }

    Leader = text.Substring(0, startTag);
    Tag = text.Substring(startTag, endTag);
    Body = text.Substring(endTag, startEnd);
    End = text.Substring(startEnd, endEnd);
    Trailer = text.Substring(endEnd);

    if ((level+1) < tags.GetSize())
    {
      Parts = new PARSE(Body, tags, level + 1, offset + endTag);
      Body.Reset();
    }
		else 
    { 
      // Check for nested table
			int index = Body.IndexOf(STRING("<") + tags[0]);
			if (index >= 0) 
      {
				Parts = new PARSE(Body, tags, 0, offset + endTag);
				Body = L"";
			}
		}

    if (startMore>=0)
    {
      More = new PARSE(Trailer, tags, level, offset+endEnd);
      Trailer.Reset();
    }
  }