Beispiel #1
0
Token* Scanner::GetSymbol(char currentChar) {
	string s = "";
	int pos = currentPos, line = currentLine;
	bool escapeDetector = false;
	currentChar = GetChar();
	s += currentChar;

	if(IsCharSeparator(currentChar))	throw ScannerException(currentLine, currentPos, "Empty character constant");
	if(IsEndOfLine(currentChar))		throw ScannerException(currentLine, currentPos, "Newline in character constant");
	if(IsTabulationSymbol(currentChar))	throw ScannerException(currentLine, currentPos, "Tabulation symbol in character constant");

	if(currentChar == '\\') {
		escapeDetector = true;
		s += (currentChar = GetChar());
		if(!IsEscapeSequence(currentChar)) 
			throw ScannerException(currentLine, currentPos, "Invalid ESCAPE-sequence: \"" + s + "\"");
	}

	if( IsCharSeparator(currentChar = GetChar()) )
		return new Token(line, pos, escapeDetector ? ESCAPE_SEQUENCE : CONST_CHAR, DEFAULT, s);
	else {
		s += currentChar;
		throw ScannerException(currentLine, currentPos, "Too many long character constant: \"" + s + "\"");
	}
}
VOID
ISAPI_STRING::Unescape(
    VOID
    )
/*++

Purpose:

    Decodes escape sequences in the ISAPI_STRING's data

Arguments:

    None

Returns:

    None

--*/
{
    CHAR *  pRead;
    CHAR *  pWrite;
    CHAR    szHex[3] = {0};
    BYTE    c;

    pRead = (CHAR*)_Buffer.QueryPtr();
    pWrite = pRead;

    while ( *pRead )
    {
        if ( IsEscapeSequence( pRead ) )
        {
            szHex[0] = *(pRead+1);
            szHex[1] = *(pRead+2);

            c = (BYTE)strtoul( szHex, NULL, 16 );

            *pWrite = c;

            pRead += 3;
            pWrite++;

            continue;
        }

        *pWrite = *pRead;

        pRead++;
        pWrite++;
    }

    *pWrite = '\0';

    CalcLen();

    return;
}
/*******************************************************************
*
* CSVRead
*
*******************************************************************/
string CSVload::Read()
{
	if( !IsFile() ){ return ""; }
	string result = "";
	bool SkipStanbyFlag = false;

	while(!IsEof()){
		//エスケープシーケンススキップ
		if(IsEscapeSequence())
		{
			CharGet();//一文字飛ばす
			continue;
		}
		//デミリター文字か改行なら
		if(IsDemiliter()){
			CharGet();//一文字飛ばす
			break;
		}

		char c = CharGet();//1文字取得する

		if(c == '/'){//スラッシュがあれば
			if(SkipStanbyFlag){//前の文字もスラッシュだったら
				LineSkip();//改行までループ
				result = "";//中身をリセット
				SkipStanbyFlag = false;
				continue;
			}
			SkipStanbyFlag = true;//スキップスタンバイ
		}else{
			SkipStanbyFlag = false;
		}
		result += c;//文字を追加する
	}

	if( result == "" && !IsEof() ){ //もしも、文字列の中身がないならもう一度試行する
		result = Read(); 
	}

	return result;
}
//************************************************************************************
Lexeme CBCGPOutlineParser::GetNext (const CString& strIn, int& nOffset, const int nSearchTo)
{
	while (nOffset >= 0 && nOffset < strIn.GetLength () && nOffset <= nSearchTo)
	{
		if (IsEscapeSequence (strIn, nOffset))
		{
			continue;
		}

		for (int i = 0; i <= m_arrBlockTypes.GetUpperBound (); i++)
		{
			BlockType* pBlockType = m_arrBlockTypes [i];
			ASSERT (pBlockType != NULL);

			// Nested blocks:
			if (pBlockType->m_bAllowNestedBlocks)
			{
				int nEndOffset;
				if (Compare (strIn, nOffset, pBlockType->m_strOpen, nEndOffset))
				{
					Lexeme lexem (i, LT_BlockStart, nOffset, nEndOffset);
					nOffset += pBlockType->m_strOpen.GetLength ();
					return lexem;
				}
				else if (Compare (strIn, nOffset, pBlockType->m_strClose, nEndOffset))
				{
					Lexeme lexem (i, LT_BlockEnd, nOffset, nEndOffset);
					nOffset += pBlockType->m_strClose.GetLength ();
					return lexem;
				}
			}
			// NonNested blocks:
			else
			{
				int nEndOffset;
				if (Compare (strIn, nOffset, pBlockType->m_strOpen, nEndOffset))
				{
					Lexeme lexem (i, LT_CompleteBlock, nOffset, nEndOffset);
					nOffset += pBlockType->m_strOpen.GetLength ();

					if (!pBlockType->m_strClose.IsEmpty ())
					{
						// find close token skipping escape sequences:
						while  (nOffset >= 0 && 
								nOffset < strIn.GetLength () && 
								nOffset <= nSearchTo)
						{
							if (IsEscapeSequence (strIn, nOffset))
							{
								continue;
							}

							if (Compare (strIn, nOffset, pBlockType->m_strClose, nEndOffset))
							{
								nOffset += pBlockType->m_strClose.GetLength ();
								if (pBlockType->m_strClose == _T("\n"))
								{
									nOffset--;
								}

								lexem.m_nEnd = nOffset - 1;
								return lexem;
							}

							nOffset++;
						}
					}
					
					if (pBlockType->m_bIgnore)
					{
						nOffset = lexem.m_nStart;
					}
					else
					{
						lexem.m_nEnd = strIn.GetLength () - 1;
						return lexem;
					}
				}
			}

		}

		nOffset++;
	}

	return Lexeme (0, LT_EndOfText, 0, 0);
}
BOOL
ISAPI_STRING::Escape(
    BOOL    fAllowDoubleEscaping
    )
/*++

Purpose:

    Escape encodes the ISAPI_STRING's data per RFC2396

Arguments:

    fAllowDoubleEscaping - If FALSE, then this function will not encode
                           any '%' characters that are part of an escape
                           sequence.  If TRUE, all '%' characters will
                           be encoded.

Returns:

    TRUE on success, FALSE on failure

--*/
{
    ISAPI_STRING    strCooked;
    DWORD           dwNumEscapes = 0;
    CHAR            szHex[3] = {0};
    BYTE *          pRead;
    BYTE *          pWrite;

    //
    // Walk through the string once.  If there
    // are no escapes, then we can just return.
    //

    pRead = (BYTE*)_Buffer.QueryPtr();

    while ( *pRead != '\0' )
    {
        if ( ( fAllowDoubleEscaping ||
               !IsEscapeSequence( (CHAR*)pRead ) ) &&
             ShouldEscape( *pRead ) )
        {
            dwNumEscapes++;
        }

        pRead++;
    }

    if ( dwNumEscapes == 0 )
    {
        return TRUE;
    }

    //
    // Make sure that our cooked string buffer is big enough, so
    // we can manipulate its pointer directly.
    //

    if ( strCooked.ResizeBuffer( QueryCB() + dwNumEscapes * 2 + 1 ) == FALSE )
    {
        goto Failed;
    }

    pRead = (BYTE*)_Buffer.QueryPtr();
    pWrite = (BYTE*)strCooked.QueryStr();

    while ( *pRead != '\0' )
    {
        if ( ( fAllowDoubleEscaping ||
               !IsEscapeSequence( (CHAR*)pRead ) ) &&
             ShouldEscape( *pRead ) )
        {
            itoa( *pRead, szHex, 16 );

            *pWrite = '%';
            *(pWrite+1) = szHex[0];
            *(pWrite+2) = szHex[1];

            pRead++;
            pWrite += 3;

            continue;
        }

        *pWrite = *pRead;

        pRead++;
        pWrite++;
    }

    *pWrite = '\0';

    if ( Copy( strCooked.QueryStr() ) == FALSE )
    {
        goto Failed;
    }

    return TRUE;

Failed:

    return FALSE;
}