bool XMLReader::IsNameToken(const UnicodeString & token)
	{
		// Nmtoken ::= (NameChar)+
		size_t n = token.size();
		if (n == 0) return false;
		for (size_t i = 0; i < n; ++i) {
			if (! IsNameChar(token[i])) return false;
		}
		return true;
	}
Exemple #2
0
	void MeasureTokenLength()
	{
		if(IsNameChar(*m_pNext))
		{
			for(m_len = 1; IsNameChar(m_pNext[m_len]) || IsDigit(m_pNext[m_len]); m_len++)
			{
			}
			m_type = name;
		}
		else if(IsDigit(*m_pNext) || *m_pNext == '.')
		{
			int exps = 0;
			int decimals = 0;
			if(*m_pNext == '.')
				decimals++;
			for(m_len = 1; m_pNext[m_len] != '\0'; m_len++)
			{
				if(IsDigit(m_pNext[m_len]))
					continue;
				if(m_pNext[m_len] == '.' && decimals == 0 && exps == 0)
				{
					decimals++;
					continue;
				}
				if(m_pNext[m_len] == 'e' && IsDigit(m_pNext[m_len + 1]) && exps == 0)
				{
					exps++;
					continue;
				}
				break;
			}
			m_type = number;
		}
		else
		{
			m_len = 1;
			m_type = symbol;
		}
	}
	bool XMLReader::IsName(const UnicodeString & name)
	{
		// Name ::= (Letter | '_' | ':') (NameChar)*
		size_t n = name.size();
		if (n == 0) return false;
		UnicodeChar c = name[0];
		if ((c == UnicodeChar('_')) || (c == UnicodeChar(':')) || IsLetter(c)) {
			for (size_t i = 1; i < n; ++i) {
				if (! IsNameChar(name[i])) return false;
			}
		}
		return true;
	}
	bool XMLReader::ParseName(Name & name)
	{
		// Name ::= (Letter | '_' | ':') (NameChar)*
		UnicodeString temp;
		UnicodeChar c = ReadChar();
		if ((c == UnicodeChar('_')) || (c == UnicodeChar(':')) || IsLetter(c)) {
			temp += c;
			while (IsNameChar(PeekChar())) temp += ReadChar();
			name.SetName(temp);
			return true;
		}
		return false;
	}
Exemple #5
0
FarString FarXMLScanner::NextName()
{
    if (!IsNameStart (*fBufPos))
  {
    if (fErrorSink)
      fErrorSink->ReportError (fCurLine, GetCurColumn(), "name");
    return FarString();
  }
  int nameLength = 1;
  while (IsNameChar (fBufPos [nameLength]))
    nameLength++;
    FarString result (fBufPos, nameLength);
  fBufPos += nameLength;
  return result;
}
Exemple #6
0
parseritem * myscanner::getitem(){
	UNCH work[100], strch, *tch, s[2];
	unsigned workpos;
#define EXPECTELE 1
#define EXPECTVAR 2
#define EXPECTNOTHING 0
	int specchar = EXPECTNOTHING;
	while (1) {
		switch (State) {
		case FILEEOF:
			return new myitem(ENDOFFILE, (*elup)[ENDOFFILE], 0);
		case PASTEND:
			break;
		case FINDSTART:
			while ((GivenLine[pos] == 0) || (GivenLine[pos] == COMMENTID)) {
				if (NULL == (GivenLine = pfile->Data())){
					State = FILEEOF;
					return new myitem(ENDOFFILE, (*elup)[ENDOFFILE], 0);
				}
				pos = 0;
			}
		case SKIPBLANKS:
			if ((GivenLine[pos] != ' ')&&(GivenLine[pos] != '\t')) State = WHATISIT;
			else pos++;
			specchar = EXPECTNOTHING;
			break;
		case WHATISIT:
			if ((GivenLine[pos] == 0) || (GivenLine[pos] == COMMENTID)) {
				State = FINDSTART;
				if (NULL == (GivenLine = pfile->Data()))
					State = FILEEOF;
				pos = 0;
				return new myitem(STATEMENTEND, (*elup)[STATEMENTEND], pfile->LineNo()-1);
			}
			else if (GivenLine[pos] == ANNOUNCEELE) {
				strch = GivenLine[pos++];
				specchar = EXPECTELE;
				State = MUSTBEALPHA;
			}
			else if (GivenLine[pos] == ANNOUNCEVAR) {
				strch = GivenLine[pos++];
				specchar = EXPECTVAR;
				State = MUSTBEALPHA;
			}
			else if ((isalpha(GivenLine[pos]))||(GivenLine[pos]=='\\')) {
				State = COLLECTALPHA;
				workpos = 0;
			}
			else if ((GivenLine[pos] == '"')||(GivenLine[pos] == '\'')){
				State = COLLECTSTRING;
				workpos = 0;
				strch = GivenLine[pos++];
			}
			else if (NULL != (tch = ustrchr(singlesstr, GivenLine[pos]))){
				State = SKIPBLANKS;
				work[1] = 0; work[0] = GivenLine[pos++];
				return new myitem(SINGLESOFFSET + (tch - singlesstr), work, pfile->LineNo());
			}
			else if ((GivenLine[pos]>='0')&&(GivenLine[pos]<='9') ) {
				State = COLLECTNUMBER;
				workpos = 0;
			}
			else {
				/*RES OLD MSG 587
				File %0: Unrecognized character "%1" found in line %2.
				*/
				ResFile->MsgData(epmfilename);
				ResFile->MsgData((unsigned short)GivenLine[pos]);
				ResFile->MsgData(pfile->LineNo());
				ResFile->PutResError(/*RES REM INS*/ 587);
				s[1] = 0; s[0] = GivenLine[pos];
				return new myitem(9999, s, pfile->LineNo());
			}
			break;
		case MUSTBEALPHA:
			if ((isalpha(GivenLine[pos]))||(GivenLine[pos]=='\\')) {
				State = COLLECTALPHA;
				workpos = 0;
			}
			else {
				/*RES OLD MSG 599
				File %0: A name does not follow "%1" on in line %2.
				*/
				ResFile->MsgData(epmfilename);
				ResFile->MsgData(strch);
				ResFile->MsgData(pfile->LineNo());
				ResFile->PutResError(/*RES REM INS*/ 599);
				s[1] = 0; s[0] = strch;
				return new myitem(9999, s, pfile->LineNo());
			}
			break;
		case COLLECTALPHA:
			if (IsNameChar(GivenLine[pos]))work[workpos++] = toupper(GivenLine[pos++]);
         else if (GivenLine[pos] == '\\'){
            if (GivenLine[pos+1] != 0)pos++;
            work[workpos++] = GivenLine[pos++];
         }
			else {
				work[workpos] = 0;
				State = CHECKALPHA;
			}
			break;
		case CHECKALPHA:
			etd *fndetd;
  //		basevalue *fndid;
			int rslt;
			varname *vn;
			State = SKIPBLANKS;
			if (specchar == EXPECTELE){
				if ((fndetd = IsElementName(work)) != NULL)
					return new etditem(ELEMENTNAME, work, pfile->LineNo(), fndetd);
				/*RES OLD MSG 600
				File %0: "%1" is not an element name, on line %2.
				*/
				ResFile->MsgData(epmfilename);
				ResFile->MsgData(work);
				ResFile->MsgData(pfile->LineNo());
				ResFile->PutResError(/*RES REM INS*/ 600);
				return new myitem(9999, work, pfile->LineNo());
			}
			else if (specchar == EXPECTVAR){
				if ((vn = IsVarName(globalvars,work)) != NULL)
					return new varitem(VARIABLENAME, work, pfile->LineNo(), vn);
				/*RES OLD MSG 601
				File %0: "%1" is not a global variable or TACTid name, on line %2.
				*/
				ResFile->MsgData(epmfilename);
				ResFile->MsgData(work);
				ResFile->MsgData(pfile->LineNo());
				ResFile->PutResError(/*RES REM INS*/ 601);
				return new myitem(9999, work, pfile->LineNo());
			}
			if (0 != (rslt = slup->Lookup(work)))
				return new myitem(STRINGSSTART + rslt, work, pfile->LineNo());
			else
			if ((fndetd = IsElementName(work)) != NULL)
				return new etditem(ELEMENTNAME, work, pfile->LineNo(), fndetd);
			if ((vn = IsVarName(localvars,work)) != NULL)
				return new varitem(VARIABLENAME, work, pfile->LineNo(), vn);
			if ((vn = IsVarName(globalvars,work)) != NULL)
				return new varitem(VARIABLENAME, work, pfile->LineNo(), vn);
			else
				return new myitem(UNDECLAREDNAME, work, pfile->LineNo());
		case COLLECTSTRING:
			if ((GivenLine[pos] == COMMENTID)|(GivenLine[pos] == 0)) {
				/*RES OLD MSG 584
				File %0: A string without a closing character was found on line %1
				*/
				ResFile->MsgData(epmfilename);
				ResFile->MsgData(pfile->LineNo());
				ResFile->PutResError(/*RES REM INS*/ 584);
				return new myitem(9999, work, pfile->LineNo());
			}
			if (GivenLine[pos] == strch)
			{
				pos++;
				State = SKIPBLANKS;
				work[workpos] = 0;
				return new myitem(STRING, work, pfile->LineNo());
			}
			else work[workpos++] = GivenLine[pos++];
			break;
		case COLLECTNUMBER:
			if ((GivenLine[pos]>='0')&&(GivenLine[pos]<='9') ) work[workpos++] = GivenLine[pos++];
			else {
				State = SKIPBLANKS;
				work[workpos] = 0;
				return new myitem(NUMBER, work, pfile->LineNo());
			}
			break;
		}
	}
};
// skip all html tag or attribute characters
static void SkipName(const char*& s, const char *end)
{
    while ((s < end) && IsNameChar(*s)) {
        s++;
    }
}
static bool IsValidTagStart(char c)
{
    return c == '/' || c == '!' || c == '?' || IsNameChar(c);
}