Exemple #1
0
// Load sentence file into memory, insert null terminators to
// delimit sentence name/sentence pairs.  Keep pointer to each
// sentence name so we can search later.
void VOX_ReadSentenceFile( const char *psentenceFileName )
{
    char	c, *pch, *pFileData;
    char	*pchlast, *pSentenceData;
    int	fileSize;

    // load file
    pFileData = (char *)FS_LoadFile( psentenceFileName, &fileSize, false );

    if( !pFileData )
    {
        MsgDev( D_WARN, "couldn't load %s\n", psentenceFileName );
        return;
    }

    pch = pFileData;
    pchlast = pch + fileSize;

    while( pch < pchlast )
    {
        // only process this pass on sentences
        pSentenceData = NULL;

        // skip newline, cr, tab, space

        c = *pch;
        while( pch < pchlast && IsWhiteSpace( c ))
            c = *(++pch);

        // skip entire line if first char is /
        if( *pch != '/' )
        {
            sentence_t *pSentence = &g_Sentences[g_numSentences++];

            pSentence->pName = pch;
            pSentence->length = 0;

            // scan forward to first space, insert null terminator
            // after sentence name

            c = *pch;
            while( pch < pchlast && c != ' ' )
                c = *(++pch);

            if( pch < pchlast )
                *pch++ = 0;

            // a sentence may have some line commands, make an extra pass
            pSentenceData = pch;
        }

        // scan forward to end of sentence or eof
        while( pch < pchlast && pch[0] != '\n' && pch[0] != '\r' )
            pch++;

        // insert null terminator
        if( pch < pchlast ) *pch++ = 0;

        // If we have some sentence data, parse out any line commands
        if( pSentenceData && pSentenceData < pchlast )
        {
            int	index = g_numSentences - 1;

            // the current sentence has an index of count-1
            VOX_ParseLineCommands( pSentenceData, index );
        }
    }
}
Exemple #2
0
BOOL CSZCommandLine::Analyze(LPCTSTR lpszCmdLine)
{
    BOOL    bResult = FALSE;
    int     nParamNamePos  = 0;
    int     nParamValuePos = 0;
    int     nSubCommandPos = 0;
    CString strParamName;
    CString strSubCommand;

    BOOL    bInQuotation   = FALSE;

    EM_CMDLINE_STATUS nStatus = em_Cmd_New_Arg;

    m_mapParams.RemoveAll();

    if (!lpszCmdLine)
        goto Exit0;

    for (int nPos = 0; 0 == nPos || lpszCmdLine[nPos - 1]; ++nPos)
    {
        TCHAR ch = lpszCmdLine[nPos];
        switch (nStatus)
        {
        case em_Cmd_New_Arg:
            bInQuotation = FALSE;
            // no break;

        case em_Cmd_White_Space:

            if (IsWhiteSpace(ch))
            {
                nStatus = em_Cmd_White_Space;
            }
            else if (IsArgNamePrefix(ch))
            {
                nStatus = em_Cmd_Arg_Name_Prefix;
            }
            else if (IsAlpha(ch))
            {   // skip sub command
                nSubCommandPos  = nPos;
                nStatus         = em_Cmd_Sub_Command;
            }
            else if (IsQuotation(ch))
            {
                bInQuotation = TRUE;
                nStatus = em_Cmd_White_Space;
            }
            else
            {
                goto Exit0;
            }

            break;

        case em_Cmd_Sub_Command:

            if (IsWhiteSpace(ch))
            {
                strSubCommand.SetString(lpszCmdLine + nSubCommandPos, nPos - nSubCommandPos);
                AppendSubCommand(strSubCommand);
                nStatus = em_Cmd_New_Arg;
            }
            else if (IsAlpha(ch))
            {   // skip sub command
                nStatus = em_Cmd_Sub_Command;
            }
            else if (IsQuotation(ch))
            {
                strSubCommand.SetString(lpszCmdLine + nSubCommandPos, nPos - nSubCommandPos);
                AppendSubCommand(strSubCommand);
                nStatus = em_Cmd_New_Arg;
            }
            else
            {
                goto Exit0;
            }

            break;

        case em_Cmd_Arg_Name_Prefix:

            if (IsWhiteSpace(ch))
            {
                goto Exit0;
            }
            else if (IsArgNamePrefix(ch))
            {   // Á¬ÐøµÄǰ׺
                nStatus = em_Cmd_Arg_Name_Prefix;
            }
            else
            {
                nParamNamePos = nPos;
                nStatus = em_Cmd_Arg_Name;
            }

            break;

        case em_Cmd_Arg_Name:

            if (IsWhiteSpace(ch))
            {
                strParamName.SetString(lpszCmdLine + nParamNamePos, nPos - nParamNamePos);
                SetParam(strParamName, _T(""));
                nStatus = em_Cmd_New_Arg;
            }
            else if (IsArgValuePrefix(ch))
            {
                strParamName.SetString(lpszCmdLine + nParamNamePos, nPos - nParamNamePos);
                nStatus = em_Cmd_Arg_Value_Prefix;
            }
            else if (IsQuotation(ch))
            {
                strParamName.SetString(lpszCmdLine + nParamNamePos, nPos - nParamNamePos);
                SetParam(strParamName, _T(""));
                nStatus = em_Cmd_New_Arg;
            }
            else
            {
                nStatus = em_Cmd_Arg_Name;
            }

            break;

        case em_Cmd_Arg_Value_Prefix:

            if (IsWhiteSpace(ch))
            {
                if (bInQuotation)
                {   // treat quoted white space as arg-value
                    nParamValuePos  = nPos;
                    nStatus         = em_Cmd_Arg_Value;
                }
                else
                {
                    SetParam(strParamName, _T(""));
                    nStatus         = em_Cmd_New_Arg;
                }

            }
            else if (IsQuotation(ch))
            {
                nParamValuePos  = nPos + 1;
                bInQuotation    = TRUE;
                nStatus         = em_Cmd_Arg_Value_Prefix;
            }
            else
            {
                nParamValuePos  = nPos;
                nStatus         = em_Cmd_Arg_Value;
            }

            break;

        case em_Cmd_Arg_Value:

            if (IsWhiteSpace(ch) && !bInQuotation)
            {
                SetParam(strParamName, lpszCmdLine + nParamValuePos, nPos - nParamValuePos);
                nStatus = em_Cmd_New_Arg;
            }
            else if (IsQuotation(ch))
            {
                SetParam(strParamName, lpszCmdLine + nParamValuePos, nPos - nParamValuePos);
                nStatus = em_Cmd_New_Arg;
            }
            else
            {
                nStatus = em_Cmd_Arg_Value;
            }

            break;
        }
     }

     bResult = TRUE;

Exit0:

     return bResult;
}
void TiXmlElement::StreamIn (std::istream * in, TIXML_STRING * tag)
{
    // We're called with some amount of pre-parsing. That is, some of "this"
    // element is in "tag". Go ahead and stream to the closing ">"
    while( in->good() )
    {
        int c = in->get();
        if ( c <= 0 )
        {
            TiXmlDocument* document = GetDocument();
            if ( document )
                document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
            return;
        }
        (*tag) += (char) c ;

        if ( c == '>' )
            break;
    }

    if ( tag->length() < 3 ) return;

    // Okay...if we are a "/>" tag, then we're done. We've read a complete tag.
    // If not, identify and stream.

    if (    tag->at( tag->length() - 1 ) == '>'
            && tag->at( tag->length() - 2 ) == '/' )
    {
        // All good!
        return;
    }
    else if ( tag->at( tag->length() - 1 ) == '>' )
    {
        // There is more. Could be:
        //		text
        //		cdata text (which looks like another node)
        //		closing tag
        //		another node.
        for ( ;; )
        {
            StreamWhiteSpace( in, tag );

            // Do we have text?
            if ( in->good() && in->peek() != '<' )
            {
                // Yep, text.
                TiXmlText text( "" );
                text.StreamIn( in, tag );

                // What follows text is a closing tag or another node.
                // Go around again and figure it out.
                continue;
            }

            // We now have either a closing tag...or another node.
            // We should be at a "<", regardless.
            if ( !in->good() ) return;
            assert( in->peek() == '<' );
            int tagIndex = (int) tag->length();

            bool closingTag = false;
            bool firstCharFound = false;

            for( ;; )
            {
                if ( !in->good() )
                    return;

                int c = in->peek();
                if ( c <= 0 )
                {
                    TiXmlDocument* document = GetDocument();
                    if ( document )
                        document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
                    return;
                }

                if ( c == '>' )
                    break;

                *tag += (char) c;
                in->get();

                // Early out if we find the CDATA id.
                if ( c == '[' && tag->size() >= 9 )
                {
                    size_t len = tag->size();
                    const char* start = tag->c_str() + len - 9;
                    if ( strcmp( start, "<![CDATA[" ) == 0 ) {
                        assert( !closingTag );
                        break;
                    }
                }

                if ( !firstCharFound && c != '<' && !IsWhiteSpace( c ) )
                {
                    firstCharFound = true;
                    if ( c == '/' )
                        closingTag = true;
                }
            }
            // If it was a closing tag, then read in the closing '>' to clean up the input stream.
            // If it was not, the streaming will be done by the tag.
            if ( closingTag )
            {
                if ( !in->good() )
                    return;

                int c = in->get();
                if ( c <= 0 )
                {
                    TiXmlDocument* document = GetDocument();
                    if ( document )
                        document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
                    return;
                }
                assert( c == '>' );
                *tag += (char) c;

                // We are done, once we've found our closing tag.
                return;
            }
            else
            {
                // If not a closing tag, id it, and stream.
                const char* tagloc = tag->c_str() + tagIndex;
                TiXmlNode* node = Identify( tagloc, TIXML_DEFAULT_ENCODING );
                if ( !node )
                    return;
                node->StreamIn( in, tag );
                delete node;
                node = 0;

                // No return: go around from the beginning: text, closing tag, or node.
            }
        }
    }
}
//------------------------------------------------------------------------------
Tokeniser::tokentype Tokeniser::GetNextToken ()
{
	tokentype TokenType = EMPTY;
	
	while ((TokenType == EMPTY) 
		&& !in.bad() 
		&& !atEOF)
	{
		curChar = GetNextChar ();
		
		//std::cout << curChar << " GetNextChar" << std::endl;

		if (IsWhiteSpace (curChar))
		{
			// skip white space
		}
		else
		{
			if (IsPunctuation (curChar))
			{
				//	std::cout << curChar << " IsPunctuation" << std::endl;
			
 				// classify punctuation token
				switch (curChar)
				{
					case '[': ParseComment (); break;
					case '\'':
						if (ParseString ())
							TokenType = STRING;
						else TokenType = BAD;
						break;
					case '(':
						TokenType = LPAR;
						break;
					case ')':
						TokenType = RPAR;
						break;
					case '{':
						TokenType = LPAR;
						break;
					case '}':
						TokenType = RPAR;
						break;
					case '!':
						TokenType = BANG;
						break;
					case '#':
						TokenType = HASH;
						break;
					case '=':
						TokenType = EQUALS;
						break;
					case ';':
						TokenType = SEMICOLON;
						break;
					case ',':
						TokenType = COMMA;
						break;
					case '*':
						TokenType = ASTERIX;
						break;
					case ':':
						TokenType = COLON;
						break;
					case '-':
						TokenType = MINUS;
						break;
					case '"':
						TokenType = DOUBLEQUOTE;
						break;
					case '/':
						TokenType = BACKSLASH;
						break;
					default:
						TokenType = OTHER;
						break;
				}
			}
			else
			{
            	// It's either a number, or a string
				if (isdigit (curChar))
				{
					TokenType = ParseNumber();
/*					if (ParseNumber ())
                    				TokenType = NUMBER;
                   			else
                    				TokenType = BAD;
*/
				}
				else
                			{
					if (ParseToken ())
						TokenType = STRING;
					else TokenType = BAD;
				}
			}
		}
	}

	if ((TokenType != STRING) && (TokenType != NUMBER))
	{
		token = "";
		token += curChar;
	}
	return TokenType;
}
void TiXmlElement::StreamIn (TIXML_ISTREAM * in, TIXML_STRING * tag)
{
	// We're called with some amount of pre-parsing. That is, some of "this"
	// element is in "tag". Go ahead and stream to the closing ">"
	while( in->good() )
	{
		int c = in->get();
		(*tag) += (TCHAR) c ;
		
		if ( c == '>' )
			break;
	}

	if ( tag->length() < 3 ) return;

	// Okay...if we are a "/>" tag, then we're done. We've read a complete tag.
	// If not, identify and stream.

	if (    tag->at( tag->length() - 1 ) == '>' 
		 && tag->at( tag->length() - 2 ) == '/' )
	{
		// All good!
		return;
	}
	else if ( tag->at( tag->length() - 1 ) == '>' )
	{
		// There is more. Could be:
		//		text
		//		closing tag
		//		another node.
		for ( ;; )
		{
			StreamWhiteSpace( in, tag );

			// Do we have text?
			if ( in->good() && in->peek() != '<' ) 
			{
				// Yep, text.
				TiXmlText text( TEXT("") );
				text.StreamIn( in, tag );

				// What follows text is a closing tag or another node.
				// Go around again and figure it out.
				continue;
			}

			// We now have either a closing tag...or another node.
			// We should be at a "<", regardless.
			if ( !in->good() ) return;
			assert( in->peek() == '<' );
			size_t tagIndex = tag->length();

			bool closingTag = false;
			bool firstCharFound = false;

			for( ;; )
			{
				if ( !in->good() )
					return;

				int c = in->peek();
				
				if ( c == '>' )
					break;

				*tag += (TCHAR)c;
				in->get();

				if ( !firstCharFound && c != '<' && !IsWhiteSpace( c ) )
				{
					firstCharFound = true;
					if ( c == '/' )
						closingTag = true;
				}
			}
			// If it was a closing tag, then read in the closing '>' to clean up the input stream.
			// If it was not, the streaming will be done by the tag.
			if ( closingTag )
			{
				int c = in->get();
				assert( c == '>' );
				*tag += (TCHAR)c;

				// We are done, once we've found our closing tag.
				return;
			}
			else
			{
				// If not a closing tag, id it, and stream.
				const TCHAR* tagloc = tag->c_str() + tagIndex;
				TiXmlNode* node = Identify( tagloc );
				if ( !node )
					return;
				node->StreamIn( in, tag );
				delete node;
				node = 0;

				// No return: go around from the beginning: text, closing tag, or node.
			}
		}
	}
}
Exemple #6
0
TRISTATE CTextParser::GetCharacterSequence(char* szSequence, int* piLength)
{
	char	c;
	BOOL	bFirst;
	int		iPos;

	bFirst = TRUE;
	iPos = 0;
	PushPosition();
	SkipWhiteSpace();

	//Make sure we're not off the end of the file.
	if (mbOutsideText)
	{
		PopPosition();
		SetErrorEndOfFile();
		return TRIERROR;
	}

	for (;;)
	{
		if (!mbOutsideText)
		{
			c = mszParserPos[0];
			StepRight();

			if (IsWhiteSpace(c))
			{
				if (bFirst)
				{
					if (szSequence)
						szSequence[iPos] = 0;

					PopPosition();
					return TRIFALSE;
				}
				else
				{
					if (szSequence)
						szSequence[iPos] = 0;

					if (szSequence)
						PassPosition();
					else
						PopPosition();

					SafeAssign(piLength, iPos);
					return TRITRUE;
				}
			}
			else
			{
				if (szSequence)
					szSequence[iPos] = c;
			}
		}
		else
		{
			if (bFirst)
			{
				PopPosition();
				SetErrorEndOfFile();
				return TRIERROR;
			}
			else
			{
				if (szSequence)
					szSequence[iPos] = 0;

				if (szSequence)
					PassPosition();
				else
					PopPosition();

				SafeAssign(piLength, iPos);
				return TRITRUE;
			}
		}
		bFirst = FALSE;
		iPos++;
	}
}
void FXmlFile::PreProcessInput(TArray<FString>& Input)
{
	// Note: This implementation is written simply and will not handle all cases.  It
	//       is made for the simple cases where FXmlFile is to be used.
	// Assumptions/Misc:
	//       - Well-formatted file with 1 entry per line
	//       - Ignoring versions, encodings, and doctypes

	// Remove white space at the beginning of lines
	for(int32 i = 0; i < Input.Num(); ++i)
	{
		int32 NumWhiteSpace = 0;
		for(int32 j = 0; j < Input[i].Len(); ++j)
		{
			if(!IsWhiteSpace(Input[i][j]))
			{
				break;
			}
			
			++NumWhiteSpace;
		}

		if(NumWhiteSpace > 0)
		{
			Input[i] = Input[i].Mid(NumWhiteSpace);
		}
	}

	// Cull any text that can be removed on a line-based parse
	for(int32 i = 0; i < Input.Num(); ++i)
	{
		// Find <!DOCTYPE or <?xml and remove those lines
		if(Input[i].StartsWith(TEXT("<!DOCTYPE")) || Input[i].StartsWith(TEXT("<?xml")))
		{
			Input[i] = TEXT("");
		}
	}

	// Cull any text inside of comments
	bool bInComment = false;
	int32 CommentLineStart = -1;
	int32 CommentIndexStart = -1;
	for(int32 i = 0; i < Input.Num(); ++i)
	{
		if(Input[i].Len() == 3)
		{
			if(bInComment)
			{
				if(Input[i][0] == TCHAR('-') && Input[i][1] == TCHAR('-') && Input[i][2] == TCHAR('>'))
				{
					// Found comment end, perform removal (simply replace all text with whitespace to be ignored by tokenizer)
					bInComment = false;
					int32 CommentLineEnd = i;
					int32 CommentIndexEnd = 2;
					WhiteOut(Input, CommentLineStart, CommentLineEnd, CommentIndexStart, CommentIndexEnd);
				}
			}
		}

		if(Input[i].Len() < 3)
		{
			continue;
		}

		int32 Indx1 = 0, Indx2 = 1, Indx3 = 2, Indx4 = 3;
		for(; Indx4 < Input[i].Len(); ++Indx1, ++Indx2, ++Indx3, ++Indx4)
		{
			// Looking for the start of a comment
			if(!bInComment)
			{
				if(Input[i][Indx1] == TCHAR('<') && Input[i][Indx2] == TCHAR('!') && Input[i][Indx3] == TCHAR('-') && Input[i][Indx4] == TCHAR('-'))
				{
					// Found comment start, mark it
					bInComment = true;
					CommentLineStart = i;
					CommentIndexStart = Indx1;
				}
			}

			// Looking for the end of a comment
			else
			{
				if( (Input[i][Indx2] == TCHAR('-') && Input[i][Indx3] == TCHAR('-') && Input[i][Indx4] == TCHAR('>')) ||
					(Input[i][Indx1] == TCHAR('-') && Input[i][Indx2] == TCHAR('-') && Input[i][Indx3] == TCHAR('>')) )
				{
					// Found comment end, perform removal (simply replace all text with whitespace to be ignored by tokenizer)
					bInComment = false;
					int32 CommentLineEnd = i;
					int32 CommentIndexEnd = Indx4;
					WhiteOut(Input, CommentLineStart, CommentLineEnd, CommentIndexStart, CommentIndexEnd);
				}
			}
		}
	}
}
	int InPlaceParser::ProcessLine(int lineno,char *line,InPlaceParserInterface *callback)
	{
		int ret = 0;

		const char *argv[MAXARGS];
		int argc = 0;

		char *foo = line;

		while ( !EOS(*foo) && argc < MAXARGS )
		{

			foo = SkipSpaces(foo); // skip any leading spaces

			if ( EOS(*foo) ) break;

			if ( *foo == mQuoteChar ) // if it is an open quote
			{
				foo++;
				if ( argc < MAXARGS )
				{
					argv[argc++] = foo;
				}
				while ( !EOS(*foo) && *foo != mQuoteChar ) foo++;
				if ( !EOS(*foo) )
				{
					*foo = 0; // replace close quote with zero byte EOS
					foo++;
				}
			}
			else
			{

				foo = AddHard(argc,argv,foo); // add any hard separators, skip any spaces

				if ( IsNonSeparator(*foo) )  // add non-hard argument.
				{
					bool quote  = false;
					if ( *foo == mQuoteChar )
					{
						foo++;
						quote = true;
					}

					if ( argc < MAXARGS )
					{
						argv[argc++] = foo;
					}

					if ( quote )
					{
						while (*foo && *foo != mQuoteChar ) foo++;
						if ( *foo ) *foo = 32;
					}

					// continue..until we hit an eos ..
					while ( !EOS(*foo) ) // until we hit EOS
					{
						if ( IsWhiteSpace(*foo) ) // if we hit a space, stomp a zero byte, and exit
						{
							*foo = 0;
							foo++;
							break;
						}
						else if ( IsHard(*foo) ) // if we hit a hard separator, stomp a zero byte and store the hard separator argument
						{
							const char *hard = &mHardString[*foo*2];
							*foo = 0;
							if ( argc < MAXARGS )
							{
								argv[argc++] = hard;
							}
							foo++;
							break;
						}
						foo++;
					} // end of while loop...
				}
			}
		}

		if ( argc )
		{
			ret = callback->ParseLine(lineno, argc, argv );
		}

		return ret;
	}
Exemple #9
0
bool TiXmlText::Blank() const {
  for (auto & elem : value)
    if (!IsWhiteSpace(elem)) return false;
  return true;
}
nsresult nsPropertiesParser::ParseBuffer(const PRUnichar* aBuffer,
                                         PRUint32 aBufferLength)
{
  const PRUnichar* cur = aBuffer;
  const PRUnichar* end = aBuffer + aBufferLength;

  // points to the start/end of the current key or value
  const PRUnichar* tokenStart = nsnull;

  // if we're in the middle of parsing a key or value, make sure
  // the current token points to the beginning of the current buffer
  if (mState == eParserState_Key ||
      mState == eParserState_Value) {
    tokenStart = aBuffer;
  }

  nsAutoString oldValue;

  while (cur != end) {

    PRUnichar c = *cur;

    switch (mState) {
    case eParserState_AwaitingKey:
      if (c == '#' || c == '!')
        EnterCommentState();

      else if (!IsWhiteSpace(c)) {
        // not a comment, not whitespace, we must have found a key!
        EnterKeyState();
        tokenStart = cur;
      }
      break;

    case eParserState_Key:
      if (c == '=' || c == ':') {
        mKey += Substring(tokenStart, cur);
        WaitForValue();
      }
      break;

    case eParserState_AwaitingValue:
      if (IsEOL(c)) {
        // no value at all! mimic the normal value-ending
        EnterValueState();
        FinishValueState(oldValue);
      }

      // ignore white space leading up to the value
      else if (!IsWhiteSpace(c)) {
        tokenStart = cur;
        EnterValueState();

        // make sure to handle this first character
        if (ParseValueCharacter(c, cur, tokenStart, oldValue))
          cur++;
        // If the character isn't consumed, don't do cur++ and parse
        // the character again. This can happen f.e. for char 'X' in sequence
        // "\u00X". This character can be control character and must be
        // processed again.
        continue;
      }
      break;

    case eParserState_Value:
      if (ParseValueCharacter(c, cur, tokenStart, oldValue))
        cur++;
      // See few lines above for reason of doing this
      continue;

    case eParserState_Comment:
      // stay in this state till we hit EOL
      if (c == '\r' || c== '\n')
        WaitForKey();
      break;
    }

    // finally, advance to the next character
    cur++;
  }

  // if we're still parsing the value and are in eParserSpecial_None, then
  // append whatever we have..
  if (mState == eParserState_Value && tokenStart &&
      mSpecialState == eParserSpecial_None) {
    mValue += Substring(tokenStart, cur);
  }
  // if we're still parsing the key, then append whatever we have..
  else if (mState == eParserState_Key && tokenStart) {
    mKey += Substring(tokenStart, cur);
  }

  return NS_OK;
}
Exemple #11
0
AString ADVBPatterns::ParsePattern(const AString& _line, PATTERN& pattern, const AString& user)
{
	const ADVBConfig& config = ADVBConfig::Get();
	ADataList& list   = pattern.list;
	AString&   errors = pattern.errors;
	AString    line   = config.ReplaceTerms(user, _line);
	TERM   *term;
	uint_t i;

	pattern.exclude    = false;
	pattern.enabled    = true;
	pattern.scorebased = false;
	pattern.pri        = 0;
	pattern.user       = user;
	pattern.pattern    = line;

	if (pattern.user.Valid()) {
		pattern.pri = (int)config.GetUserConfigItem(pattern.user, "pri");
	}

	list.DeleteList();
	list.SetDestructor(&__DeleteTerm);

	i = 0;
	while (IsWhiteSpace(line[i])) i++;
	if (line[i] == '#') {
		pattern.enabled = false;
		i++;
	}
	else if (line[i] == ';') {
		return errors;
	}

	while (IsWhiteSpace(line[i])) i++;

	if (line[i]) {
		while (line[i] && errors.Empty()) {
			if (!IsSymbolStart(line[i])) {
				errors.printf("Character '%c' (at %u) is not a legal field start character (term %u)", line[i], i, list.Count() + 1);
				break;
			}

			uint_t fieldstart = i++;
			while (IsSymbolChar(line[i])) i++;
			AString field = line.Mid(fieldstart, i - fieldstart).ToLower();

			while (IsWhiteSpace(line[i])) i++;

			if (field == "exclude") {
				pattern.exclude = true;
				continue;
			}

			const FIELD *fieldptr = (const FIELD *)ADVBProg::fieldhash.Read(field);
			if (!fieldptr) {
				uint_t nfields;
				const FIELD *fields = ADVBProg::GetFields(nfields);

				errors.printf("'%s' (at %u) is not a valid search field (term %u), valid search fields are: ", field.str(), fieldstart, list.Count() + 1);
				for (i = 0; i < nfields; i++) {
					const FIELD& field = fields[i];

					if (i) errors.printf(", ");
					errors.printf("'%s'", field.name);
				}
				break;
			}

			uint_t opstart = i;

			const char *str = line.str() + i;
			bool isassign = fieldptr->assignable;
			uint_t j;
			uint_t opindex = 0, opcode = Operator_EQ;
			for (j = 0; j < NUMBEROF(operators); j++) {
				if (((isassign == operators[j].assign) ||
					 (isassign && !operators[j].assign)) &&
					(operators[j].fieldtypes & (1U << fieldptr->type)) &&
					(strncmp(str, operators[j].str, operators[j].len) == 0)) {
					i      += operators[j].len;
					opindex = j;
					opcode  = operators[j].opcode;
					break;
				}
			}

			while (IsWhiteSpace(line[i])) i++;

			AString value;
			bool    implicitvalue = false;
			if (j == NUMBEROF(operators)) {
				if (!line[i] || IsSymbolStart(line[i])) {
					if (fieldptr->assignable) {
						switch (fieldptr->type) {
							case FieldType_string:
								break;

							case FieldType_date:
								value = "now";
								break;

							default:
								value = "1";
								break;
						}

						opcode = Operator_Assign;
					}
					else opcode = Operator_NE;

					for (j = 0; j < NUMBEROF(operators); j++) {
						if ((opcode == operators[j].opcode) &&
							((isassign == operators[j].assign) ||
							 (isassign && !operators[j].assign)) &&
							(operators[j].fieldtypes & (1U << fieldptr->type))) {
							opindex = j;
							break;
						}
					}

					implicitvalue = true;
				}
				else {
					errors.printf("Symbols at %u do not represent a legal operator (term %u), legal operators for the field '%s' are: ", opstart, list.Count() + 1, field.str());

					bool flag = false;
					for (j = 0; j < NUMBEROF(operators); j++) {
						if (((isassign == operators[j].assign) ||
							 (isassign && !operators[j].assign)) &&
							(operators[j].fieldtypes & (1U << fieldptr->type))) {
							if (flag) errors.printf(", ");
							errors.printf("'%s'", operators[j].str);
							flag = true;
						}
					}
					break;
				}
			}

			if (!implicitvalue) {
				char quote = 0;
				if (IsQuoteChar(line[i])) quote = line[i++];

				uint_t valuestart = i;
				while (line[i] && ((!quote && !IsWhiteSpace(line[i])) || (quote && (line[i] != quote)))) {
					if (line[i] == '\\') i++;
					i++;
				}

				value = line.Mid(valuestart, i - valuestart).DeEscapify();

				if (quote && (line[i] == quote)) i++;

				while (IsWhiteSpace(line[i])) i++;
			}

			bool orflag = false;
			if ((line.Mid(i, 2).ToLower() == "or") && IsWhiteSpace(line[i + 2])) {
				orflag = true;
				i += 2;

				while (IsWhiteSpace(line[i])) i++;
			}
			else if ((line[i] == '|') && IsWhiteSpace(line[i + 1])) {
				orflag = true;
				i += 1;

				while (IsWhiteSpace(line[i])) i++;
			}

			if ((term = new TERM) != NULL) {
				term->data.start   = fieldstart;
				term->data.length  = i - fieldstart;
				term->data.field   = fieldptr - ADVBProg::fields;
				term->data.opcode  = opcode;
				term->data.opindex = opindex;
				term->data.value   = value;
				term->data.orflag  = (orflag && !RANGE(opcode, Operator_First_Assignable, Operator_Last_Assignable));
				term->field    	   = fieldptr;
				term->datetype 	   = DateType_none;

				switch (term->field->type) {
					case FieldType_string:
#if DVBDATVERSION > 1
						if (fieldptr->offset == ADVBProg::GetTagsDataOffset()) {
							value = "|" + value + "|";
						}
#endif
						
						if ((opcode & ~Operator_Inverted) == Operator_Regex) {
							AString regexerrors;
							AString rvalue;

							rvalue = ParseRegex(value, regexerrors);
							if (regexerrors.Valid()) {
								errors.printf("Regex error in value '%s' (term %u): %s", value.str(), list.Count() + 1, regexerrors.str());
							}

							value = rvalue;
						}
						term->value.str = value.Steal();
						break;

					case FieldType_date: {
						ADateTime dt;
						uint_t specified;

						dt.StrToDate(value, ADateTime::Time_Relative_Local, &specified);

						//debug("Value '%s', specified %u\n", value.str(), specified);

						if (!specified) {
							errors.printf("Failed to parse date '%s' (term %u)", value.str(), list.Count() + 1);
							break;
						}
						else if (((specified == ADateTime::Specified_Day) && (stricmp(term->field->name, "on") == 0)) ||
								 (stricmp(term->field->name, "day") == 0)) {
							//debug("Date from '%s' is '%s' (week day only)\n", value.str(), dt.DateToStr().str());
							term->value.u64 = dt.GetWeekDay();
							term->datetype  = DateType_weekday;
						}
						else if (specified & ADateTime::Specified_Day) {
							specified |= ADateTime::Specified_Date;
						}

						if (term->datetype == DateType_none) {
							specified &= ADateTime::Specified_Date | ADateTime::Specified_Time;

							if (specified == (ADateTime::Specified_Date | ADateTime::Specified_Time)) {
								//debug("Date from '%s' is '%s' (full date and time)\n", value.str(), dt.DateToStr().str());
								term->value.u64 = (uint64_t)dt;
								term->datetype  = DateType_fulldate;
							}
							else if (specified == ADateTime::Specified_Date) {
								//debug("Date from '%s' is '%s' (date only)\n", value.str(), dt.DateToStr().str());
								term->value.u64 = dt.GetDays();
								term->datetype  = DateType_date;
							}
							else if (specified == ADateTime::Specified_Time) {
								//debug("Date from '%s' is '%s' (time only)\n", value.str(), dt.DateToStr().str());
								term->value.u64 = dt.GetMS();
								term->datetype  = DateType_time;
							}
							else {
								errors.printf("Unknown date specifier '%s' (term %u)", value.str(), list.Count() + 1);
							}
						}
						break;
					}

					case FieldType_span:
					case FieldType_age: {
						ADateTime dt;
						//ADateTime::EnableDebugStrToDate(true);
						term->value.u64 = (uint64_t)ADateTime(value, ADateTime::Time_Absolute);
						//ADateTime::EnableDebugStrToDate(false);
						break;
					}

					case FieldType_uint32_t:
					case FieldType_external_uint32_t:
						term->value.u32 = (uint32_t)value;
						break;

					case FieldType_sint32_t:
					case FieldType_external_sint32_t:
						term->value.s32 = (sint32_t)value;
						break;

					case FieldType_uint16_t:
						term->value.u16 = (uint16_t)value;
						break;

					case FieldType_sint16_t:
						term->value.s16 = (sint16_t)value;
						break;

					case FieldType_uint8_t:
						term->value.u8 = (uint8_t)(uint16_t)value;
						break;

					case FieldType_sint8_t:
						term->value.s8 = (sint8_t)(sint16_t)value;
						break;

					case FieldType_flag...FieldType_lastflag:
						term->value.u8 = ((uint32_t)value != 0);
						//debug("Setting test of flag to %u\n", (uint_t)term->value.u8);
						break;

					case FieldType_prog: {
						ADVBProg *prog;

						if ((prog = new ADVBProg) != NULL) {
							if (prog->Base64Decode(value)) {
								term->value.prog = prog;
							}
							else {
								errors.printf("Failed to decode base64 programme ('%s') for %s at %u (term %u)", value.str(), field.str(), fieldstart, list.Count() + 1);
								delete prog;
							}
						}
						else {
							errors.printf("Failed to allocate memory for base64 programme ('%s') for %s at %u (term %u)", value.str(), field.str(), fieldstart, list.Count() + 1);
						}
						break;
					}

					default:
						errors.printf("Unknown field '%s' type (%u) (term %u)", field.str(), (uint_t)term->field->type, list.Count() + 1);
						break;
				}

				//debug("term: field {name '%s', type %u, assignable %u, offset %u} type %u dateflags %u value '%s'\n", term->field->name, (uint_t)term->field->type, (uint_t)term->field->assignable, term->field->offset, (uint_t)term->data.opcode, (uint_t)term->dateflags, term->value.str);

				if (errors.Empty()) {
					pattern.scorebased |= (term->field->offset == ADVBProg::GetScoreDataOffset());
					list.Add((uptr_t)term);
				}
				else {
					__DeleteTerm((uptr_t)term, NULL);
					break;
				}
			}
		}
	}
void VTextState::Paint(VGraphicsInfo *pGraphics, VWindowBase *pParentWnd, VColorRef iColor)
{
  const char *szText = GetText();
  if (!m_spFont || !szText || !szText[0])
    return;

  VRectanglef vParentRect = pParentWnd->GetClientRect(); // clipping box of parent control

  if(!m_bCachedLinesValid)
  {
    m_lines.Reset();
    m_lineOffsets.Reset();

    float fLineHeight = m_spFont->GetFontHeight() * m_fRelativeFontHeight * m_fFontScaling;

    if(!m_bTextWrap)
    {
      const char* szCurrentLine = szText;
      for (const char* szPtr = szCurrentLine; *szPtr != '\0'; ++szPtr)
      {
        if (*szPtr == '\n')
        {
          VStaticString<512> line;
          line.Set(szCurrentLine, szPtr - szCurrentLine);

          m_lines.Add(line.AsChar());
          szCurrentLine = szPtr + 1;
        }
      }

      // Add the last line
      if(*szCurrentLine)
      {
        m_lines.Add(szCurrentLine);
      }
    }
    else
    {
      float fMaxLineWidth = vParentRect.GetSizeX() / m_fFontScaling;

      // Wrap text into individual lines
      {
        const char *szCurrentLine = szText;
        while (*szCurrentLine)
        {
          // byte offsets
          int iByteOffsetAtWrapPosition;
          int iByteOffsetAfterWrapPosition;

          // search for next newline
          const char *pNextNewLine = strchr(szCurrentLine, '\n');

          // compute automatic wrap character index
          int iCharCount = m_spFont->GetCharacterIndexAtPos(szCurrentLine, fMaxLineWidth, -1, false);
          int iWrapOffset = VString::GetUTF8CharacterOffset(szCurrentLine, iCharCount);

          if (pNextNewLine != NULL && (pNextNewLine - szCurrentLine) <= iWrapOffset)
          {
            // newline occurs before automatic text wrap
            iByteOffsetAtWrapPosition = static_cast<int>(pNextNewLine - szCurrentLine);
            iByteOffsetAfterWrapPosition = iByteOffsetAtWrapPosition + 1;
          }
          else if(strlen(szCurrentLine) <= iWrapOffset)
          {
            // End of text occurs before automatic text wrap
            iByteOffsetAtWrapPosition = strlen(szCurrentLine);
            iByteOffsetAfterWrapPosition = iByteOffsetAtWrapPosition;
          }
          else
          {
            // automatic text wrap
            iByteOffsetAtWrapPosition = iWrapOffset;
            if (iByteOffsetAtWrapPosition > 0)
            {
              // Go backwards and try to find white space
              while (iByteOffsetAtWrapPosition > 0 && !IsWhiteSpace(szCurrentLine[iByteOffsetAtWrapPosition]))
              {
                iByteOffsetAtWrapPosition--;
              }

              // no whitespace found? then wrap inside word
              if (iByteOffsetAtWrapPosition == 0)
              {
                iByteOffsetAtWrapPosition = iWrapOffset;
              }
              else
              {
                // Find end of next word
                int iEndOfWord = iByteOffsetAtWrapPosition + 1;
                while(szCurrentLine[iEndOfWord] && !IsWhiteSpace(szCurrentLine[iEndOfWord]))
                {
                  iEndOfWord++;
                }

                // If the word does not fit into a line by itself, it will be wrapped anyway, so wrap it early to avoid ragged looking line endings
                VRectanglef nextWordSize;
                m_spFont->GetTextDimension(szCurrentLine + iByteOffsetAtWrapPosition, nextWordSize, iEndOfWord - iByteOffsetAtWrapPosition);
                if(nextWordSize.GetSizeX() > fMaxLineWidth)
                {
                  iByteOffsetAtWrapPosition = iWrapOffset;
                }
              }
            }
            else
            {
              // First character is already wider than the line
              iByteOffsetAtWrapPosition = VString::GetUTF8CharacterOffset(szCurrentLine, 1);
            }
            iByteOffsetAfterWrapPosition = iByteOffsetAtWrapPosition;
          }

          // put together line
          VStaticString<512> line;
          line.Set(szCurrentLine, iByteOffsetAtWrapPosition);

          m_lines.Add(line.AsChar());

          szCurrentLine = &szCurrentLine[iByteOffsetAfterWrapPosition];
          while(*szCurrentLine == ' ')
            szCurrentLine++;
        }
      }
    }

    // Compute offset for each line
    for(int iLineIdx = 0; iLineIdx < m_lines.GetLength(); iLineIdx++)
    {
      hkvVec2 offset = m_vOffset;

      offset.x += m_spFont->GetTextPositionOfs(m_lines[iLineIdx], vParentRect.GetSize(), m_hAlign, m_vAlign, m_fFontScaling).x;
      offset.y += iLineIdx * fLineHeight;

      if (m_vAlign == VisFont_cl::ALIGN_CENTER)
      {
        offset.y += (vParentRect.GetSizeY() - fLineHeight * m_lines.GetSize()) * 0.5f;
      }
      else if (m_vAlign == VisFont_cl::ALIGN_BOTTOM)
      {
        offset.y += (vParentRect.GetSizeY() - fLineHeight * m_lines.GetSize());
      }

      m_lineOffsets.Add(offset);
    }

    m_bCachedLinesValid = true;
  }

  // Render lines
  if (pGraphics)
  {
    VSimpleRenderState_t state = VGUIManager::DefaultGUIRenderState();
    if (m_fFontScaling!=1.0f)
      state.SetFlag(RENDERSTATEFLAG_FILTERING);

    for(int iLineIdx = 0; iLineIdx < m_lines.GetLength(); iLineIdx++)
    {
      m_spFont->PrintText(&pGraphics->Renderer, vParentRect.m_vMin + m_lineOffsets[iLineIdx], m_lines[iLineIdx], iColor, state, 
        m_fFontScaling, m_pCustomBBox ? m_pCustomBBox : &vParentRect);
    }
  }
}
Exemple #13
0
//------------------------------------------------------------------------------
// Parse a number (integer or real).
tokentype Parser::ParseNumber ()
{
	enum {
		start		= 0x0001, // 0
		sign		= 0x0002, // 1
        digit		= 0x0004, // 2
		fraction	= 0x0008, // 3
		expsymbol	= 0x0010, // 4
		expsign		= 0x0020, // 5
        exponent 	= 0x0040, // 6
        bad			= 0x0080,
        done		= 0x0100
    } state;

    tokentype result = BAD;

	token = "";
    state = start;

    char curChar = text[pos]; 

    while (!IsWhiteSpace (curChar)
    	&& !(IsPunctuation (curChar) && (curChar != '-'))
        && (state != bad)
        && (state != done))
    {
    	if (isdigit (curChar))
        {
        	switch (state)
            {
            	case start:
                case sign:
                	state = digit;
                    break;
                case expsymbol:
                case expsign:
                	state = exponent;
                    break;
                default:
                	break;
            }
        }
        else if ((curChar == '-') || (curChar == '+'))
        {
        	switch (state)
            {
            	case start:
                	state = sign;		// sign of number
                    break;
                case digit:
                	state = done;		// minus sign is punctuation, such as 6-10
                	break;
                case expsymbol:
                	state = expsign;	// sign of exponent
                    break;
                default:
                	state = bad;		// syntax error
                    break;
            }
        }
        else if ((curChar == '.') && (state == digit))
        	state = fraction;
        else if (((curChar == 'E') || (curChar == 'e')) && (state & (digit | fraction)))
        	state = expsymbol;
        else
        	state = bad;

        if ((state != bad) && (state != done))
        {
        	token += curChar;
            curChar = GetNextChar ();
        }
    }

    int isNumber =  state & (digit | fraction | exponent | done);
    if (isNumber)
    {
    	// We have a number
		result = NUMBER;

		if (IsPunctuation (curChar))
        {
//        	PutBack (curChar);
//            if (!atEOL)
//            	filecol--;
        }
	}        

	else
    {
		// Not a number, but a string that starts with numbers, such as "00BW0762.1"
//        cout << "Do something!" << endl;
			do {
				if (curChar == '_')
					token += ' ';
				else
					token += curChar;
            	curChar = GetNextChar ();
 			} while (isalnum (curChar) || (curChar == '_') || (curChar == '.') && (pos < text.length()));
			result = STRING; //classify the token

    }

	return result;
}
Exemple #14
0
	char * InPlaceParser::SkipSpaces(char *foo)
	{
		while ( !EOS(*foo) && IsWhiteSpace(*foo) ) foo++;
		return foo;
	}
bool TextAreaTextRange::CheckEndPointIsUnitEndpoint(_In_ EndPoint check, _In_ TextUnit unit, _In_ TEXTATTRIBUTEID specificAttribute)
{
    if (unit == TextUnit_Character)
    {
        return true;
    }

    EndPoint next;
    EndPoint prev;
    if (!_control->StepCharacter(check, true, &next) ||
        !_control->StepCharacter(check, false, &prev))
    {
        // If we're at the beginning or end, we're at an endpoint
        return true;
    }

    else if (unit == TextUnit_Word)
    {
        if (IsWhiteSpace(prev) && !IsWhiteSpace(check))
        {
            return true;
        }
        return false;
    }

    else if (unit == TextUnit_Line || unit == TextUnit_Paragraph)
    {
        return check.line != next.line;
    }

    // TextUnit_Page and TextUnit_Document are covered by the initial beginning/end check
    else if (unit == TextUnit_Page || unit == TextUnit_Document)
    {
        return false;
    }

    else if (unit == TextUnit_Format)
    {
        bool matching = true;
        bool checkedLineBoundary = false;
        
        // There are limited attributes that vary in this control
        // If its not one of those attributes, then it is not an Endpoint
        // unless it's the document start or end, which is checked above
        for (int i = 0; i < ARRAYSIZE(lineVariableAttributes); i++)
        {
            if (specificAttribute == 0 || specificAttribute == lineVariableAttributes[i])
            {
                if (!checkedLineBoundary)
                {
                    if (!CheckEndPointIsUnitEndpoint(check, TextUnit_Paragraph, 0))
                    {
                        break;
                    }
                    checkedLineBoundary = true;
                }

                VARIANT varC = _control->GetAttributeAtPoint(check, lineVariableAttributes[i]);
                VARIANT varN = _control->GetAttributeAtPoint(next, lineVariableAttributes[i]);
                HRESULT hr = VarCmp(&varC, &varN, LOCALE_NEUTRAL);
                VariantClear(&varC);
                VariantClear(&varN);
                if (hr != VARCMP_EQ)
                {
                    matching = false;
                    break;
                }
            }
        }

        for (int i = 0; i < ARRAYSIZE(charVariableAttributes); i++)
        {
            if (specificAttribute == 0 || specificAttribute == charVariableAttributes[i])
            {
                int *annotationIds;
                int annotationCount;
                if (GetAnnotationsAtPoint(check, &annotationIds, &annotationCount))
                {
                    int *prevAnnotationIds;
                    int prevAnnotationCount;
                    if (GetAnnotationsAtPoint(prev, &prevAnnotationIds, &prevAnnotationCount))
                    {
                        if (annotationCount != prevAnnotationCount)
                        {
                            matching = false;
                        }
                        // Since all our annotations are the same type, if the number matches,
                        // then the UIA_AnnotationTypesAttributeId all match
                        else if (charVariableAttributes[i] == UIA_AnnotationObjectsAttributeId)
                        {
                            for (int j = 0; j < annotationCount; j++)
                            {
                                if (annotationIds[j] != prevAnnotationIds[j])
                                {
                                    matching = false;
                                }
                            }
                        }
                        delete [] prevAnnotationIds;
                    }
                    delete [] annotationIds;
                }
            }
        }
        return !matching;
    }

    return false;
}
Exemple #16
0
	bool InPlaceParser::IsNonSeparator(char c)
	{
		if ( !IsHard(c) && !IsWhiteSpace(c) && c != 0 ) return true;
		return false;
	}
Exemple #17
0
bool DTextParser::SearchWordInBlock( lpctstr t_pWord, DTextBlock& Block )
{
	if( !m_pBuffer || t_pWord==NULL || t_pWord[0]==0 ) return false;
	//if( bFromStart )
	{
		m_lBufPosition = Block.Start();
	}

	SString strTemp = t_pWord;
	int iSrcPos=0;
	int iSrcSize = strTemp.Len();

	int iReadWordMode = 0;

	long BufEnd = Block.End();

	while( m_lBufPosition <= BufEnd )
	{
		// 한줄주석처리 ';'가 나오면 리턴문자가 올 때까지 모든 문자를Skip한다.
		if( m_pBuffer[m_lBufPosition]==';' )
		{
			// reset state
			//iReadWordMode = 0;
			//iSrcPos = 0;
			// go to the end of line
			m_lBufPosition++;
			while( m_lBufPosition < BufEnd && m_pBuffer[m_lBufPosition] != '\r' && m_pBuffer[m_lBufPosition] != '\n' )
					m_lBufPosition++;
		}

		if( iReadWordMode==0 )
		{// Word에 진입하지 않은 상태
			//소스 첫글자와 대상현재위치의 단어가 같다면 WordMode=1
			if( t_pWord[0]==m_pBuffer[m_lBufPosition] )
			{
				iSrcPos = 1;
				iReadWordMode = 1;
			}
			++m_lBufPosition;
		}
		else if( iReadWordMode==1 )
		{// Word에 진입하여 검사중인 상태
			// WhiteSpace가 나오거나, 틀리면 Mode=0, 그 외에는 SrcPos를 증가
			if( t_pWord[iSrcPos]==m_pBuffer[m_lBufPosition] )
			{
				++iSrcPos;
			}
			else if( IsWhiteSpace(m_pBuffer[m_lBufPosition]) )
			{// 단어검사중에 단어의 끝을 만났다면 현재까지 검사된 단어의 길이를 보고
				//맞는 단어를 찾았는지 검사한다.
				if( iSrcPos>=iSrcSize ) return true;//found!
			}
			else
			{// 그저 틀린 문자를 발견했다면, Mode=0
				iReadWordMode = 0;
				iSrcPos = 0;
			}
			++m_lBufPosition;
		}
	}

	return false;
}
Exemple #18
0
const char* TiXmlAttribute::Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding)
{
	p = SkipWhiteSpace(p, encoding);
	if (!p || !*p) return 0;

	int tabsize = 4;
	if (document)
		tabsize = document->TabSize();

	if (data)
	{
		data->Stamp(p, encoding);
		location = data->Cursor();
	}
	// Read the name, the '=' and the value.
	const char* pErr = p;
	p = ReadName(p, &name, encoding);
	if (!p || !*p)
	{
		if (document) document->SetError(TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding);
		return 0;
	}
	p = SkipWhiteSpace(p, encoding);
	if (!p || !*p || *p != '=')
	{
		if (document) document->SetError(TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding);
		return 0;
	}

	++p;	// skip '='
	p = SkipWhiteSpace(p, encoding);
	if (!p || !*p)
	{
		if (document) document->SetError(TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding);
		return 0;
	}
	
	const char* end;

	if (*p == '\'')
	{
		++p;
		end = "\'";
		p = ReadText(p, &value, false, end, false, encoding);
	}
	else if (*p == '"')
	{
		++p;
		end = "\"";
		p = ReadText(p, &value, false, end, false, encoding);
	}
	else
	{
		// All attribute values should be in single or double quotes.
		// But this is such a common error that the parser will try
		// its best, even without them.
		value = "";
		while (   p && *p										// existence
				&& !IsWhiteSpace(*p) && *p != '\n' && *p != '\r'	// whitespace
				&& *p != '/' && *p != '>')						// tag end
		{
			value += *p;
			++p;
		}
	}
	return p;
}
Exemple #19
0
// buf Get Word
// 한 단어. 마치 fscanf같은 역할을 버퍼내에서 하고
// 버퍼 포인팅을 자동으로 이동한다.
// state 0 : init W/S elimination
// state 1 : normal copy mode
// state 2 : "..." copy mode
int DTextParser::GetWord( char *t_pWord, int t_iNumber )
{
	int state = 0, i = 0;
	if( !m_pBuffer || m_lBufPosition>=m_lBufSize ) return -1;

	while( m_lBufPosition < m_lBufSize ) {
/*		// 주석처리
		if( m_pBuffer[m_lBufPosition]=='/' && m_pBuffer[m_lBufPosition]=='*' ) {
			m_lBufPosition++;
			while( m_lBufPosition < m_lBufSize && m_pBuffer[m_lBufPosition] != '\r' && m_pBuffer[m_lBufPosition] != '\n' &&
					m_pBuffer[m_lBufPosition] != '#' )
					m_lBufPosition++;
		}
*/
		// 한줄주석처리 ';'가 나오면 리턴문자가 올 때까지 모든 문자를Skip한다.
		if( m_pBuffer[m_lBufPosition]==';' )
		{
			m_lBufPosition++;
			while( m_lBufPosition < m_lBufSize && m_pBuffer[m_lBufPosition] != '\r' && m_pBuffer[m_lBufPosition] != '\n' )
					m_lBufPosition++;
		}

		// 단어읽기에 들어가고 W/S일 경우
		if( state == 1 && IsWhiteSpace(m_pBuffer[m_lBufPosition])) {
			t_iNumber--;
			state = 0;
			if( t_iNumber < 1 ) {
				t_pWord[i++] = 0;
				m_lBufPosition++;
				return 1;
			} else {
				t_pWord[i++] = ' ';
			}
		// ".."를 읽고 있으며 Space가 아닌 W/S나 "가 나타났을 때
		} else if( state == 2 &&( m_pBuffer[m_lBufPosition]=='\"' || m_pBuffer[m_lBufPosition]=='\r' || m_pBuffer[m_lBufPosition]=='\n')) {
			// "..."
			t_iNumber--;
			state = 0;
			if( t_iNumber < 1 ) {
				t_pWord[i++] = 0;
				m_lBufPosition++;
				return 1;
			} else {
				t_pWord[i++] = ' ';
			}
		}

		// 보통 문자를 넣고 있는 중일때.. (".."든 보통이든..)
		if( state == 2 || !IsWhiteSpace(m_pBuffer[m_lBufPosition]) ) {
			if(state == 0 ) 
				state = 1;
			t_pWord[i++] = m_pBuffer[m_lBufPosition];
			if( i-1 == 0 && t_pWord[0]=='\"' ) {
				i--;
				state = 2;
			}
		}
		m_lBufPosition++;
	}

	t_pWord[i] = 0;

	return 1;
}
bool TiXmlText::Blank() const {
    for ( unsigned i=0; i<value.length(); i++ )
        if ( !IsWhiteSpace( value[i] ) )
            return false;
    return true;
}
Exemple #21
0
void conv(RR& x, const char *s)
{
   long c;
   long cval;
   long sign;
   ZZ a, b;
   long i = 0;

   if (!s) Error("bad RR input");


   c = s[i];
   while (IsWhiteSpace(c)) {
      i++;
      c = s[i];
   }

   if (c == '-') {
      sign = -1;
      i++;
      c = s[i];
   }
   else
      sign = 1;

   long got1 = 0;
   long got_dot = 0;
   long got2 = 0;

   a = 0;
   b = 1;

   cval = CharToIntVal(c);

   if (cval >= 0 && cval <= 9) {
      got1 = 1;

      while (cval >= 0 && cval <= 9) {
         mul(a, a, 10);
         add(a, a, cval);
         i++;
         c = s[i];
         cval = CharToIntVal(c);
      }
   }

   if (c == '.') {
      got_dot = 1;

      i++;
      c = s[i];
      cval = CharToIntVal(c);

      if (cval >= 0 && cval <= 9) {
         got2 = 1;

         while (cval >= 0 && cval <= 9) {
            mul(a, a, 10);
            add(a, a, cval);
            mul(b, b, 10);
            i++;
            c = s[i];
            cval = CharToIntVal(c);
         }
      }
   }

   if (got_dot && !got1 && !got2)  Error("bad RR input");

   ZZ e;

   long got_e = 0;
   long e_sign;

   if (c == 'e' || c == 'E') {
      got_e = 1;

      i++;
      c = s[i];

      if (c == '-') {
         e_sign = -1;
         i++;
         c = s[i];
      }
      else if (c == '+') {
         e_sign = 1;
         i++;
         c = s[i];
      }
      else
         e_sign = 1;


      cval = CharToIntVal(c);

      if (cval < 0 || cval > 9) Error("bad RR input");

      e = 0;
      while (cval >= 0 && cval <= 9) {
         mul(e, e, 10);
         add(e, e, cval);
         i++;
         c = s[i];
         cval = CharToIntVal(c);
      }
   }

   if (!got1 && !got2 && !got_e) Error("bad RR input");

   RR t1, t2, v;

   long old_p = RR::precision();

   if (got1 || got2) {
      ConvPrec(t1, a, max(NumBits(a), 1));
      ConvPrec(t2, b, NumBits(b));
      if (got_e)
         RR::SetPrecision(old_p + 10);

      div(v, t1, t2);
   }
   else
      set(v);

   if (sign < 0)
      negate(v, v);

   if (got_e) {
      if (e >= NTL_OVFBND) Error("RR input overflow");
      long E;
      conv(E, e);
      if (e_sign < 0) E = -E;
      RR::SetPrecision(old_p + 10);
      power(t1, to_RR(10), E);
      mul(v, v, t1);
      RR::prec = old_p;
   }

   xcopy(x, v);
}
const char* TiXmlBase::ReadText(	const char* p,
                                    TIXML_STRING * text,
                                    bool trimWhiteSpace,
                                    const char* endTag,
                                    bool caseInsensitive,
                                    TiXmlEncoding encoding )
{
    *text = "";
    if (    !trimWhiteSpace			// certain tags always keep whitespace
            || !condenseWhiteSpace )	// if true, whitespace is always kept
    {
        // Keep all the white space.
        while (	   p && *p
                   && !StringEqual( p, endTag, caseInsensitive, encoding )
              )
        {
            int len;
            char cArr[4] = { 0, 0, 0, 0 };
            p = GetChar( p, cArr, &len, encoding );
            text->append( cArr, len );
        }
    }
    else
    {
        bool whitespace = false;

        // Remove leading white space:
        p = SkipWhiteSpace( p, encoding );
        while (	   p && *p
                   && !StringEqual( p, endTag, caseInsensitive, encoding ) )
        {
            if ( *p == '\r' || *p == '\n' )
            {
                whitespace = true;
                ++p;
            }
            else if ( IsWhiteSpace( *p ) )
            {
                whitespace = true;
                ++p;
            }
            else
            {
                // If we've found whitespace, add it before the
                // new character. Any whitespace just becomes a space.
                if ( whitespace )
                {
                    (*text) += ' ';
                    whitespace = false;
                }
                int len;
                char cArr[4] = { 0, 0, 0, 0 };
                p = GetChar( p, cArr, &len, encoding );
                if ( len == 1 )
                    (*text) += cArr[0];	// more efficient
                else
                    text->append( cArr, len );
            }
        }
    }
    if ( p )
        p += strlen( endTag );
    return p;
}
Exemple #23
0
/*
 *	CRchTxtPtr::ChangeCase(cch, Type, publdr)
 *	
 *	@mfunc
 *		Change case of cch chars starting at this text ptr according to Type,
 *		which has the possible values:
 *
 *		tomSentenceCase	= 0: capitalize first letter of each sentence
 *		tomLowerCase	= 1: change all letters to lower case
 *		tomUpperCase	= 2: change all letters to upper case
 *		tomTitleCase	= 3: capitalize the first letter of each word
 *		tomToggleCase	= 4: toggle the case of each letter
 *	
 *	@rdesc
 *		TRUE iff a change occurred
 *
 *	@devnote
 *		Since this routine only changes the case of characters, it has no
 *		effect on rich-text formatting.  However it is part of the CRchTxtPtr
 *		class in order to notify the display of changes.  CTxtRanges are also
 *		notified just in case the text blocks are modified.
 */
BOOL CRchTxtPtr::ChangeCase (
	LONG		  cch,			//@parm # chars to change case for
	LONG		  Type,			//@parm Type of change case command
	IUndoBuilder *publdr)		//@parm UndoBuilder to receive anti-event
								//  	for any replacements
{
	TRACEBEGIN(TRCSUBSYSBACK, TRCSCOPEINTERN, "CRchTxtPtr::ChangeCase");
	_TEST_INVARIANT_

#define	BUFFERLEN	256

	LONG	cchChunk, cchFirst, cchGet, cchLast;
	BOOL	fAlpha, fToUpper, fUpper;			// Flags controling case change
	BOOL	fChange = FALSE;					// No change yet
	BOOL	fStart = TRUE;						// Start of Word/Sentence
	TCHAR *	pch;								// Ptr to walk rgCh with
	WORD *	pType;								// Ptr to walk rgType with
	TCHAR	rgCh[BUFFERLEN];					// Char buffer to work in
	WORD	rgType[BUFFERLEN];					// C1_TYPE array for rgCh

	if( GetCp() )
	{
		if( Type == tomSentenceCase )
		{
			fStart = _rpTX.IsAtBOSentence();
		}
		else if( Type == tomTitleCase )
		{
			// check to see if we are at the beginning of
			// a word.  This is the case if the character preceeding
			// our current position is white space.
			fStart = IsWhiteSpace(_rpTX.PrevChar());
			_rpTX.AdvanceCp(1);
		}
	}
	while(cch > 0)								// Do 'em all (or as many as
	{											//  in story)
		cchChunk = min(BUFFERLEN, cch);			// Get next bufferful
		cch -= cchChunk;						// Decrement the count
		cchGet = _rpTX.GetText(cchChunk, rgCh);	// Manipulate chars in buffer
		if(cchGet < cchChunk)					//  (for undo, need to use
		{										//  ReplaceRange())
			cch = 0;							// No more chars in story,
			if(!cchGet)							//  so we'll be done
				break;							// We're done already
			cchChunk = cchGet;					// Something in this chunk
		}

		GetStringTypeEx(0, CT_CTYPE1, rgCh,		// Find out whether chars are
						cchChunk, rgType);		//  UC, LC, or neither
		
		cchLast = 0;							// Default nothing to replace
		cchFirst = -1;
		for(pch = rgCh, pType = rgType;			// Process buffered chars
			cchChunk;
			cchChunk--, pch++, pType++)
		{
			fAlpha = *pType & (C1_UPPER | C1_LOWER); // Nonzero if UC or LC
			fUpper = (*pType & C1_UPPER) != 0;	// TRUE if UC
			fToUpper = fStart ? TRUE : fUpper;	// capitalize first letter of a
												// sentence
			switch(Type)
			{									// Decide whether to change
			case tomLowerCase:					//  case and determine start
				fToUpper = FALSE;				//  of word/sentence for title
				break;							//  and sentence cases

			case tomUpperCase:
				fToUpper = TRUE;
				break;

			case tomToggleCase:
				fToUpper = !fUpper;
				break;

			case tomSentenceCase:
				if(*pch == TEXT('.'))			// If sentence terminator,
					fStart = TRUE;				//  capitalize next alpha
				if(fAlpha)						// If this char is alpha, next
					fStart = FALSE;				//  char can't start a
				break;							//  sentence

			case tomTitleCase:					// If this char is alpha, next
				fStart = (fAlpha == 0);			//  char can't start a word
				break;
			default:
				return FALSE;
			}

			if(fAlpha && (fToUpper ^ fUpper))	// Only change case if it
			{									//  makes a difference (saves
				if(fToUpper)					//  on system calls and undos)
					CharUpperBuff(pch, 1);
				else
					CharLowerBuff(pch, 1);

				fChange = TRUE;					// Return value: change made
				if( cchFirst == -1 )			// Save cch of unchanged
					cchFirst = cchGet-cchChunk;	//  leading string
				cchLast = cchChunk - 1;			// Save cch of unchanged
			}									//  trailing string
		}
		if( cchFirst == -1 )
		{
			Assert(cchLast == 0);
			cchFirst = cchGet;
		}

		Advance(cchFirst);						// Skip unchanged leading
		cchGet -= cchFirst + cchLast;			//  string. cchGet = cch of
		ReplaceRange(cchGet, cchGet, rgCh		//  changed span
			+ cchFirst, publdr, tomUndefined);
		Advance(cchLast);						// Skip unchanged trailing 
	}											//  string
	return fChange;
}
Exemple #24
0
const char* TiXmlAttribute::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding )
{
    p = SkipWhiteSpace( p, encoding );
    if ( !p || !*p ) return 0;

    if ( data )
    {
        data->Stamp( p, encoding );
        location = data->Cursor();
    }
    // Read the name, the '=' and the value.
    const char* pErr = p;
    p = ReadName( p, &name, encoding );
    if ( !p || !*p )
    {
        if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding );
        return 0;
    }
    p = SkipWhiteSpace( p, encoding );
    if ( !p || !*p || *p != '=' )
    {
        if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
        return 0;
    }

    ++p;    // skip '='
    p = SkipWhiteSpace( p, encoding );
    if ( !p || !*p )
    {
        if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
        return 0;
    }

    const char* end;
    const char SINGLE_QUOTE = '\'';
    const char DOUBLE_QUOTE = '\"';

    if ( *p == SINGLE_QUOTE )
    {
        ++p;
        end = "\'";        // single quote in string
        p = ReadText( p, &value, false, end, false, encoding );
    }
    else if ( *p == DOUBLE_QUOTE )
    {
        ++p;
        end = "\"";        // double quote in string
        p = ReadText( p, &value, false, end, false, encoding );
    }
    else
    {
        // All attribute values should be in single or double quotes.
        // But this is such a common error that the parser will try
        // its best, even without them.
        value = "";
        while (    p && *p                                            // existence
                && !IsWhiteSpace( *p ) && *p != '\n' && *p != '\r'    // whitespace
                && *p != '/' && *p != '>' )                            // tag end
        {
            if ( *p == SINGLE_QUOTE || *p == DOUBLE_QUOTE ) {
                // [ 1451649 ] Attribute values with trailing quotes not handled correctly
                // We did not have an opening quote but seem to have a
                // closing one. Give up and throw an error.
                if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
                return 0;
            }
            value += *p;
            ++p;
        }
    }
    return p;
}
Exemple #25
0
/*--------------------------------------------------------------------------------------*/
int p3parseline(char *line, char **argv) 
{
  char *bptr;        /* Pointer into the buffer buf */
  char *tptr;        /* Temp pointer */
  int intoken;       /* Are we in the middle of reading a token in? */
  int argc;          /* Number of args */
  int bg;            /* Background job? */

  if ((strlen(line)*2) > MAXLINE) {
    HandleError("Line too long for p3parseline\n");
  }

  argc = 0;
  intoken = 0;
  
  /* Copy line into buf character-by-character to create the argv strings */
  bptr = buf;
  tptr = line;
  while (*tptr != '\n') {
    
    if (IsWhiteSpace(*tptr)) {
      *bptr++ = '\0';                  /* insert \0 to terminate current token */
      intoken = 0;
    }
    else if (IsSpecialChar(*tptr)) {   /* stand-alone token -- add room for \0 */
      if (intoken) {  
	*bptr++ = '\0';
	intoken = 0;
      }
      argv[argc++] = bptr;
      *bptr++ = *tptr;
      *bptr++ = '\0';
    }
    else if (*tptr == '"') {            /* starting a string -- copy until matching \" */
      if (intoken) {  
	*bptr++ = '\0';
	intoken = 0;
      }
      argv[argc++] = bptr;
      tptr++;
      while ((*tptr != '\"') && (*tptr != '\0')) *bptr++ = *tptr++;
      if (*tptr == '\0') {
	HandleError("String not terminated -- missing double quote\n");
      }
      else {
        *bptr++ = '\0';
      }
    }
    else {                             /* non-special character */
      if (intoken) *bptr++ = *tptr;
      else {
	intoken = 1;
	argv[argc++] = bptr;
	*bptr++ = *tptr;
      }
    }
    
    tptr++;                             /* move to the next character */
    
  }
  *bptr = '\0';                         /* terminate the last token */

  argv[argc] = NULL;

  if (argc == 0)  /* Ignore blank line */
    return 1;

  /* Should the job run in the background? */
  if ((bg = (*argv[argc-1] == '&')) != 0)
    argv[--argc] = NULL;

#ifdef P3PARSELINE_DEBUG
  int i;
  for (i = 0; i < argc; i++) printf("argv[%d] = '%s'\n", i, argv[i]);
#endif
  

  return bg;
}