コード例 #1
0
ファイル: VValueBag.cpp プロジェクト: StephaneH/core-XToolbox
VError VValueBag::_GetJSONString(VString& outJSONString, sLONG& curlevel, bool prettyformat, JSONOption inModifier) const
{
	AppendBeginJSONObject(outJSONString, curlevel, prettyformat);

	VIndex nbatt = GetAttributesCount();
	VIndex nbelem = GetElementNamesCount();
	bool first = true;
	for (VIndex i = 1; i <= nbatt; i++)
	{
		VStr255 s;
		const VValueSingle* val = GetNthAttribute(i, &s);
		if ( !s.EqualToUSASCIICString( "____objectunic") && !s.EqualToUSASCIICString( "____property_name_in_jsarray"))
		{
			if (first)
				first = false;
			else
				outJSONString.AppendUniChar(',');
			if (s.EqualToUSASCIICString( "<>"))
				s = "__CDATA";
			AppendJSONPropertyName(outJSONString, curlevel, prettyformat, s);
			if (val == NULL || val->IsNull())
				outJSONString += "null";
			else
			{
				val->GetJSONString(s, JSON_WithQuotesIfNecessary);
				outJSONString += s;
			}
		}
	}

	for (VIndex i = 1; i <= nbelem; i++)
	{
		if (first)
			first = false;
		else
			outJSONString.AppendUniChar(',');

		VStr255 s;
		const VBagArray* subelems = GetNthElementName(i, &s);
		AppendJSONPropertyName(outJSONString, curlevel, prettyformat, s);
		
		if ((inModifier & JSON_UniqueSubElementsAreNotArrays) != 0 && subelems->GetCount() == 1)
		{
			subelems->GetNth(1)->_GetJSONString(outJSONString, curlevel, prettyformat, inModifier);
		}
		else if (subelems->GetNth(1)->GetAttribute("____objectunic"))
		{
			subelems->GetNth(1)->_GetJSONString(outJSONString, curlevel, prettyformat, inModifier);
		}
		else
			subelems->_GetJSONString(outJSONString, curlevel, prettyformat, inModifier);

	}

	AppendEndJSONObject(outJSONString, curlevel, prettyformat);
	return VE_OK;
}
コード例 #2
0
ファイル: VValueBag.cpp プロジェクト: StephaneH/core-XToolbox
void AppendEndJSONArray(VString& outJSONString, sLONG& curlevel, bool prettyformat)
{
	AppendJSONNewline(outJSONString, prettyformat);
	curlevel--;
	AjustJSONTab(outJSONString, curlevel, prettyformat);
	outJSONString.AppendUniChar(']');
}
コード例 #3
0
bool ScriptDocLexer::ConsumeName( VString &outName, bool &outIsOptional, bool &outDoFurtherProcessing )
{
	outIsOptional = false;
	outDoFurtherProcessing = true;
	while (true) {
		if (!fLexerInput->HasMoreChars())	return false;
		UniChar ch = fLexerInput->MoveToNextChar();

		if (CHAR_LEFT_SQUARE_BRACKET == ch) {
			// If the name is enclosed in [], then it's considered to be an optional
			// parameter.
			if (outName.GetLength() == 0) {
				outIsOptional = true;
			} else {
				return false;
			}
		} else if (IsLineEnding( ch )) {
			// We've reached the end of the tag, and the user has not specified a comment, which
			// is fine.  We'll just break out now and not do any further processing.
			ConsumeLineEnding( ch );
			outDoFurtherProcessing = false;
			break;
		} else if (IsWhitespace( ch ) || (outIsOptional && CHAR_RIGHT_SQUARE_BRACKET == ch)) {
			break;
		} else {
			outName.AppendUniChar( ch );
		}
	}
	return true; 
}
コード例 #4
0
bool ScriptDocLexer::ConsumeExceptionTag()
{
	// The exception tag takes the form: @exception {name} description, and we've already
	// handled the @exception clause.  So we want to skip over whitespace and look for the
	// {name} clause next.
	UniChar ch;
	bool toss;
	if (!SkipWhitespaces( toss ))		return false;
	if (!fLexerInput->HasMoreChars())	return false;

	// We expect the next character to be an open curly bracket.
	if (CHAR_LEFT_CURLY_BRACKET != fLexerInput->MoveToNextChar())	return false;
	if (!fLexerInput->HasMoreChars())	return false;

	// Now we expect to read the name of the exception
	VString exceptionName;
	while (true) {
		if (!fLexerInput->HasMoreChars())	return false;
		ch = fLexerInput->MoveToNextChar();

		if (IsLineEnding( ch )) { ConsumeLineEnding( ch ); return false; }
		if (CHAR_RIGHT_CURLY_BRACKET == ch) break;
		exceptionName.AppendUniChar( ch );
	}

	// Now that we have the exception name clause, we can skip whitespaces and look
	// for the description
	if (!SkipWhitespaces( toss ))		return false;

	VString description;
	if (!ConsumeComment( description ))	return false;

	fLastElement = new ExceptionElement( exceptionName, description );
	return true;
}
コード例 #5
0
VString XLinuxIntlMgr::GetTimeSeparator() const
{
	VString timeSeparator;

	VString timePattern=GetDateOrTimePattern(SHORT_TIME);

	bool isQuoted=false;

	for(int i=0 ; i<timePattern.GetLength() ; i++)
	{
		UniChar c=timePattern[i];

		if(c=='\'')
			isQuoted=!isQuoted;

		if(isQuoted)
			continue;

		if(!(c>='A' && c<='Z') && !(c>='a' && c<='z'))
		{
			timeSeparator.AppendUniChar(c);
			break;
		}
	}

	if(timeSeparator.IsEmpty())
		return VString(":");

	return timeSeparator;
}
コード例 #6
0
ファイル: VValueBag.cpp プロジェクト: StephaneH/core-XToolbox
void AppendBeginJSONObject(VString& outJSONString, sLONG& curlevel, bool prettyformat)
{
	AppendJSONNewline(outJSONString, prettyformat);
	AjustJSONTab(outJSONString, curlevel, prettyformat);
	outJSONString.AppendUniChar('{');
	curlevel++;
	//AppendJSONNewline(outJSONString, prettyformat);
}
コード例 #7
0
VFolder::VFolder( const FSRef& inRef)
{
	VString fullPath;
	XMacFile::FSRefToHFSPath( inRef, fullPath);
	fullPath.AppendUniChar( FOLDER_SEPARATOR);
	fPath.FromFullPath(fullPath);
	xbox_assert( fPath.IsFolder());
	fFolder.Init( this);
}
コード例 #8
0
ファイル: JsUAG.cpp プロジェクト: StephaneH/core-Components
void VJSGroup::_filterParents( XBOX::VJSParms_callStaticFunction& ioParms, CUAGGroup* inGroup)
{
	VString s;
	ioParms.GetStringParam(1,s);
	s.AppendUniChar(ioParms.GetWildChar());
	CUAGGroupVector groups;
	bool firstlevel = ioParms.GetBoolParam(2, "firstLevel", "allLevels");
	inGroup->RetainOwners(groups, firstlevel);
	ioParms.ReturnValue(buildArrFromGroups(ioParms, groups, &s));
}
コード例 #9
0
ファイル: VValueBag.cpp プロジェクト: StephaneH/core-XToolbox
void AppendJSONPropertyName(VString& outJSONString, sLONG& curlevel, bool prettyformat, const VString name)
{
	VString name2;
	AppendJSONNewline(outJSONString, prettyformat);
	AjustJSONTab(outJSONString, curlevel, prettyformat);
	name.GetJSONString(name2, JSON_WithQuotesIfNecessary);
	outJSONString += name2;
	if (prettyformat)
		outJSONString += " : ";
	else
		outJSONString.AppendUniChar(':');
}
コード例 #10
0
VString XLinuxIntlMgr::GetDateSeparator() const
{
	VString dateSeparator;

	icu::DateFormat* dateFmt=icu::DateFormat::createDateInstance(icu::DateFormat::SHORT, fLocale);
	xbox_assert(dateFmt!=NULL);

	icu::SimpleDateFormat* simpleDateFmt=reinterpret_cast<icu::SimpleDateFormat*>(dateFmt);
	xbox_assert(simpleDateFmt!=NULL);

	if(simpleDateFmt!=NULL)
	{
		UErrorCode err=U_ZERO_ERROR;

		UnicodeString tmpPattern;
		simpleDateFmt->toLocalizedPattern(tmpPattern, err);
		xbox_assert(err==U_ZERO_ERROR);

		VString datePattern(tmpPattern.getTerminatedBuffer());
		bool isQuoted=false;

		for(int i=0 ; i<datePattern.GetLength() ; i++)
		{
			UniChar c=datePattern[i];

			if(c=='\'')
				isQuoted=!isQuoted;

			if(isQuoted)
				continue;

			//ICU works with patterns ("M/d/yy" for ex.) and doesn't have a notion of date separator.
			//As a work around, we try to get a localized date pattern and pick the first char that looks like a separator.
			if(!(c>='A' && c<='Z') && !(c>='a' && c<='z'))
			{
				dateSeparator.AppendUniChar(c);
				break;
			}
		}
	}

	if(dateFmt!=NULL)
		delete dateFmt;

	xbox_assert(!dateSeparator.IsEmpty());

	if(dateSeparator.IsEmpty())
		return VString("/");

	return dateSeparator;
}
コード例 #11
0
ファイル: VValueBag.cpp プロジェクト: StephaneH/core-XToolbox
VError VBagArray::_GetJSONString(VString& outJSONString, sLONG& curlevel, bool prettyformat, JSONOption inModifier) const
{
	AppendBeginJSONArray(outJSONString, curlevel, prettyformat);

	VIndex nbelem = GetCount();
	for (VIndex i = 1; i <= nbelem; i++)
	{
		GetNth(i)->_GetJSONString(outJSONString, curlevel, prettyformat, inModifier);
		if (i != nbelem)
			outJSONString.AppendUniChar(',');
	}

	AppendEndJSONArray(outJSONString, curlevel, prettyformat);
	return VE_OK;
}
コード例 #12
0
bool ScriptDocLexer::ConsumeReturnTag()
{
	UniChar	ch;
	bool	toss;

	if ( ! SkipWhitespaces( toss ) )
		return false;

	if ( ! fLexerInput->HasMoreChars() )
		return false;

	// We expect the next character to be an open curly bracket.
	if ( CHAR_LEFT_CURLY_BRACKET != fLexerInput->MoveToNextChar() )
		return false;

	if ( ! fLexerInput->HasMoreChars() )
		return false;

	// Now we expect to read the type list
	VString typeList;
	while (true)
	{
		if ( ! fLexerInput->HasMoreChars() )
			return false;

		ch = fLexerInput->MoveToNextChar();

		if ( IsLineEnding( ch ) )
		{
			ConsumeLineEnding( ch );
			return false; 
		}

		if (CHAR_RIGHT_CURLY_BRACKET == ch)
			break;
		typeList.AppendUniChar( ch );
	}

	if ( ! SkipWhitespaces( toss ) )
		return false;

	// Now we can find the description of the return value
	VString description;
	ConsumeComment( description );

	fLastElement = new ReturnElement( typeList, description );
	return true;
}
コード例 #13
0
bool ScriptDocLexer::ConsumeTypes( VString &outTypes, bool &outDoFurtherProcessing )
{
	outDoFurtherProcessing = true;

	// We expect the next character to be an open curly bracket if the user has specified
	// type information for the parameter
	bool curlyBracketMode = CHAR_LEFT_CURLY_BRACKET == fLexerInput->PeekAtNextChar();

	if ( curlyBracketMode )
	{
		fLexerInput->MoveToNextChar();
		if ( ! fLexerInput->HasMoreChars() )
			return false;
	}

	// Now we expect to read the type list
	while (true)
	{
		if ( ! fLexerInput->HasMoreChars() )
			return false;

		UniChar ch = fLexerInput->MoveToNextChar();

		if ( IsLineEnding( ch ) )
		{ 
			ConsumeLineEnding( ch );
			if (curlyBracketMode)
				outDoFurtherProcessing = false; 
			break;
		}

		if (curlyBracketMode && CHAR_RIGHT_CURLY_BRACKET == ch)
			break;

		outTypes.AppendUniChar( ch );
	}
	return true;
}
コード例 #14
0
BEGIN_TOOLBOX_NAMESPACE

// ===========================================================
#pragma mark -
#pragma mark VJSONImporter
// ===========================================================
/* WARNING: this GetNextJSONToken(VString&, bool*) is the same as the GetNextJSONToken() with no parameters,
			except it fills outString and withQuotes.

		=> if something must be changed here, think about changing the parsing also in the other GetNextJSONToken()

	It looks better to write 2 routines instead of filling this one with more parameter and testing, such as writting
	a lot of if(!doNotFillString) or something
*/
VJSONImporter::JsonToken VJSONImporter::GetNextJSONToken(VString& outString, bool* withQuotes)
{
	outString.Clear();
	
	bool		eof;
	
	if (withQuotes != NULL)
		*withQuotes = false;
	
	UniChar c;
	
	do 
	{
		c = _GetNextChar(eof);
		if (c > 32)
		{
			switch (c)
			{
				case '{':
					return jsonBeginObject;
					break;
					
				case '}':
					return jsonEndObject;
					break;
					
				case '[':
					return jsonBeginArray;
					break;
					
				case ']':
					return jsonEndArray;
					break;
					
				case ',':
					return jsonSeparator;
					break;
					
				case ':':
					return jsonAssigne;
					break;
					
				case '"':
				{
					if (withQuotes != NULL)
						*withQuotes = true;
					
					do 
					{
						c = _GetNextChar(eof);
						if (c != 0)
						{
							if (c == '\\')
							{
								c = _GetNextChar(eof);
								switch(c)
								{
									case '\\':
									case '"':
									case '/':
										//  c is the same
										break;
										
									case 't':
										c = 9;
										break;
										
									case 'r':
										c = 13;
										break;
										
									case 'n':
										c = 10;
										break;
										
									case 'b':
										c = 8;
										break;
										
									case 'f':
										c = 12;
										break;
										
									case 'u':
								/*	2010-02-22 - T.A.
									http://www.ietf.org/rfc/rfc4627.txt
									. . .
									The application/json Media Type for JavaScript Object Notation (JSON)
									. . .
									Any character may be escaped.  If the character is in the Basic
									Multilingual Plane (U+0000 through U+FFFF), then it may be
									represented as a six-character sequence: a reverse solidus, followed
									by the lowercase letter u, followed by four hexadecimal digits that
									encode the character's code point.  The hexadecimal letters A though
									F can be upper or lowercase.  So, for example, a string containing
									only a single reverse solidus character may be represented as
									"\u005C".
									. . .
							   */
										if ( testAssert( fCurChar - fStartChar + 4 <= fInputLen))
										{
											c = 0;
											for(sLONG i_fromHex = 1; i_fromHex <= 4; ++i_fromHex)
											{
												UniChar theChar = *fCurChar++;
												if (theChar >= CHAR_DIGIT_ZERO && theChar <= CHAR_DIGIT_NINE)
												{
													c *= 16L;
													c += (theChar - CHAR_DIGIT_ZERO);
												}
												else if (theChar >= CHAR_LATIN_CAPITAL_LETTER_A && theChar <= CHAR_LATIN_CAPITAL_LETTER_F)
												{
													c *= 16L;
													c += (theChar - CHAR_LATIN_CAPITAL_LETTER_A) + 10L;
												}
												else if (theChar >= CHAR_LATIN_SMALL_LETTER_A && theChar <= CHAR_LATIN_SMALL_LETTER_F)
												{
													c *= 16L;
													c += (theChar - CHAR_LATIN_SMALL_LETTER_A) + 10L;
												}
											}
										}
										else
										{
											eof = true;
											c = 0;
										}
										break;
								}
								if (c != 0)
									outString.AppendUniChar(c);
							}
							else if (c == '"')
							{
								return jsonString;
							}
							else
							{
								outString.AppendUniChar(c);
							}
						}							
					} while(!eof);
					return jsonString;
				}
					break;
					
				default:
				{
					outString.AppendUniChar(c);
					do 
					{
						const UniChar* oldpos = fCurChar;
						c = _GetNextChar(eof);
						if (c <= 32)
						{
							return jsonString;
						}
						else
						{
							switch(c)
							{
								case '{':
								case '}':
								case '[':
								case ']':
								case ',':
								case ':':
								case '"':
									fCurChar = oldpos;
									return jsonString;
									break;
									
								default:
									outString.AppendUniChar(c);
									break;
							}
						}
					} while(!eof);
					return jsonString;
				}
					break;
			}
		}
	} while(!eof);
	
	return jsonNone;
}
コード例 #15
0
int HTMLLexer::ConsumePossiblePunctuation( UniChar inChar, TokenList *outTokens )
{
	VIndex nStartingPosition = fLexerInput->GetCurrentPosition();
	int tk = 0;
	VString tokenStr;
	switch (inChar) {
		case CHAR_AMPERSAND: {
			VString entity;
			UniChar ch;
			if (ConsumePossibleEntity( entity, ch )) {
				tk = HTMLLexemes::TEXT;
				if (outTokens) {
					outTokens->push_back( new HTMLLexerToken( ILexerToken::TT_HTML_ENTITY, nStartingPosition, entity.GetLength(), entity, ch ) );
				}
				return tk;
			}
		} break;
		case CHAR_EQUALS_SIGN: {
			tokenStr.AppendUniChar( fLexerInput->MoveToNextChar() );
			tk = (int)inChar;
		} break;
		case CHAR_SOLIDUS: {
			fLexerInput->MoveToNextChar();
			if (fLexerInput->HasMoreChars()) {
				if (fLexerInput->PeekAtNextChar() == CHAR_GREATER_THAN_SIGN) {
					tk = HTMLLexemes::SELF_CLOSE;
					tokenStr = "/>";
					fLexerInput->MoveToNextChar();	// Eat the >
				}
			}
			if (!tk)	fLexerInput->MoveToPreviousChar();
		} break;
		case CHAR_LESS_THAN_SIGN: {
			tokenStr.AppendUniChar( fLexerInput->MoveToNextChar() );
			tk = (int)inChar;
			if (fLexerInput->HasMoreChars()) {
				if (fLexerInput->PeekAtNextChar() == CHAR_SOLIDUS) {
					tk = HTMLLexemes::START_OF_CLOSE_TAG;
					tokenStr = "</";
					fLexerInput->MoveToNextChar();	// Eat the /
				} else if (fLexerInput->PeekAtNextChar() == CHAR_EXCLAMATION_MARK) {
					tk = HTMLLexemes::BANG_START;
					tokenStr = "<!";
					fLexerInput->MoveToNextChar();
				} else if (fLexerInput->PeekAtNextChar() == CHAR_QUESTION_MARK) {
					tk = HTMLLexemes::QUESTION_START;
					tokenStr = "<?";
					fLexerInput->MoveToNextChar();
				}
			} 
		} break;
		case CHAR_GREATER_THAN_SIGN: {
			tokenStr.AppendUniChar( fLexerInput->MoveToNextChar() );
			tk = (int)inChar;
		} break;
	}

	if (tk && outTokens) {
		outTokens->push_back( new HTMLLexerToken( ILexerToken::TT_PUNCTUATION, 
									nStartingPosition, tokenStr.GetLength(), tokenStr, tk ) );
	}
	return tk;
}
コード例 #16
0
void XWinIntlMgr::FormatDate( const VTime& inDate, VString& outDate, EOSFormats inFormat, bool inUseGMTTimeZoneForDisplay)
{
	// Prepare SYSTEMTIME for windows.
	sWORD YY = 0;
	sWORD MM = 0;
	sWORD DD = 0;
	sWORD hh = 0;
	sWORD mm = 0;
	sWORD ss = 0;
	sWORD ms = 0;
	if (inUseGMTTimeZoneForDisplay)
		inDate.GetUTCTime (YY,MM,DD,hh,mm,ss,ms);
	else
		inDate.GetLocalTime (YY,MM,DD,hh,mm,ss,ms);

	// Verify if date >1st Jan 1601 (GetDateFormat doesn't support earlier dates.
	if (YY>=1601)
	{
		// Let the OS do it's job.
		UniChar acBuffer[256];

		SYSTEMTIME osDate={0};
		osDate.wYear=YY;
		osDate.wMonth=MM;
		osDate.wDay=DD;
		osDate.wHour=hh;
		osDate.wMinute=mm;
		osDate.wSecond=ss;
		osDate.wMilliseconds=ms;

		if (inFormat == eOS_MEDIUM_FORMAT)
		{
			VString pattern;
			if (GetLocaleInfo( LOCALE_SLONGDATE, pattern))
			{
				// replace long month and date by medium ones
				pattern.ExchangeRawString( CVSTR( "MMMM"), CVSTR( "MMM"));
				pattern.ExchangeRawString( CVSTR( "dddd"), CVSTR( "ddd"));
				if (::GetDateFormatW( fDialect, 0, &osDate, pattern.GetCPointer(), acBuffer, sizeof(acBuffer)))
					outDate = acBuffer;
			}
		}
		else
		{
			// Let the OS do the stuff.
			DWORD dateFormat = (inFormat == eOS_SHORT_FORMAT) ? DATE_SHORTDATE : DATE_LONGDATE;
			if (::GetDateFormatW(fDialect,dateFormat,&osDate,NULL,acBuffer,sizeof(acBuffer)))
				outDate = acBuffer;
		}
	}
	else
	{
		// Get the date pattern
		VString pattern;
		if (GetLocaleInfo( (inFormat == eOS_LONG_FORMAT) ? LOCALE_SLONGDATE : LOCALE_SSHORTDATE, pattern))
		{
			XBOX::VString tokens="gyMd";
			UniChar oldToken=0;
			sLONG count=0;
			pattern.AppendChar(' ');
			sLONG YY2=YY%100;
			XBOX::VString oneName;
			for (int pos=0;pos<pattern.GetLength();pos++)
			{
				UniChar token=pattern[pos];
				if (tokens.FindUniChar(token)>=1)
				{
					if (token==oldToken)
						count++;
					else
					{
						if (!count)
						{
							count=1;
							oldToken=token;
						}
					}
				}

				if (count && token!=oldToken)
				{
					switch(oldToken)
					{
					case 'g':
						if (count==2)
						{
							// TODO: ERA will be added if really wanted.
						}
						else
						{
							for (int i=0;i<count;i++)
								outDate.AppendUniChar(oldToken);
						}
						break;

					case 'y':	// YEAR
						switch(count)
						{
						case 5:
						case 4:		// 4 or more digits date
							outDate.AppendLong(YY);
							break;

						case 2:		// 2 digits with starting 0.
							if (YY2<=9)
								outDate.AppendLong(0);
						case 1:		// 1 or 2 digits
							outDate.AppendLong(YY2);
							break;

						default:
							for (int i=0;i<count;i++)
								outDate.AppendUniChar(oldToken);
							break;
						}
						break;

					case 'M':	// MONTH
						switch(count)
						{
						case 4:	// Long name
						case 3:	// Abbreviated name
							if (GetLocaleInfo( ((count==4) ? LOCALE_SMONTHNAME1 : LOCALE_SABBREVMONTHNAME1) + MM - 1, oneName))
								outDate += oneName;
							break;

						case 2:	// 2 digits number (leading 0)
							if (MM<=9)
								outDate.AppendLong(0);
						case 1:	// 1 or 2 digits number
							outDate.AppendLong(MM);
							break;

						default:
							for (int i=0;i<count;i++)
								outDate.AppendUniChar(oldToken);
							break;
						}
						break;

					case 'd':	// DAY
						switch(count)
						{
						case 4:	// Weekday long name
						case 3:	// Weekday abbreviated name
							if (GetLocaleInfo( ((count==4) ? LOCALE_SDAYNAME1 : LOCALE_SABBREVDAYNAME1) + (inDate.GetWeekDay() + 6) % 7, oneName))
								outDate += oneName;
							break;

						case 2:	// Month day on 2 digits (leading 0)
							if (DD<=9)
								outDate.AppendLong(0);
						case 1:	// Month day on 1 or 2 digits.
							outDate.AppendLong(DD);
							break;

						default:
							for (int i=0;i<count;i++)
								outDate.AppendUniChar(oldToken);
							break;
						}
						break;

					}
					count=0;
				}

				if (!count)
					outDate.AppendUniChar(token);
				oldToken=token;
			}

			// Remove the extra space at end of pattern.
			if (outDate.GetLength()>1)
				outDate.SubString(1,outDate.GetLength()-1);
		}
	}
}
コード例 #17
0
ファイル: VValueBag.cpp プロジェクト: StephaneH/core-XToolbox
void AjustJSONTab(VString& outJSONString, sLONG& curlevel, bool prettyformat)
{
	if (prettyformat)
		for (sLONG i = 0; i < curlevel; i++)
			outJSONString.AppendUniChar(9);
}
コード例 #18
0
bool HTMLLexer::ConsumePossibleEntity( VString &outEntityConsumed, UniChar &outCharacterToAdd )
{
	if (!fLexerInput->HasMoreChars())	return false;
	xbox_assert( fLexerInput->PeekAtNextChar() == CHAR_AMPERSAND );

	// In HTML, escape sequences come in one of three forms:
	//	&#DDDD; (where D is decimal number)
	//	&#xHHHH; (where H is hexidecimal number -- case insensitive)
	//	&entity; (where entity is a common entity reference)
	// We've already read the ampersand, so now we want to figure out which of
	// the three cases we're dealing with.  If we don't match any of the three
	// cases, then we just assume we really had regular text and the user just
	// screwed up.

	// Consume the current character to see what sort of escape sequence we're dealing with
	fLexerInput->MoveToNextChar();	// Eat the &
	if (!fLexerInput->HasMoreChars()) {
		fLexerInput->MoveToPreviousChar();
		return false;
	}
	UniChar escapeType = fLexerInput->MoveToNextChar();
	sLONG charactersToRevert = 2;
	outEntityConsumed = "&";
	outEntityConsumed.AppendUniChar( escapeType );
	switch (escapeType) {
		case CHAR_NUMBER_SIGN: {
			// We either have a hex literal or a decimal literal following the # sign.  So we
			// will check to see which we've got and go from there
			if (!fLexerInput->HasMoreChars())	break;
			UniChar literalType = fLexerInput->MoveToNextChar();
			outEntityConsumed.AppendUniChar( literalType );
			charactersToRevert++;
			switch (literalType) {
				case CHAR_LATIN_CAPITAL_LETTER_X:
				case CHAR_LATIN_SMALL_LETTER_X: {
					// We now want to add any number of hex digits to the stream.  Though, if we go over
					// four hex digits, then we're outside of the range of any legal unicode code point, and
					// so I am going to do a hard-coded stop there.
					unsigned short value = 0;

					for (sLONG i = 0; i < 4; i++) {
						UniChar c = CHAR_CONTROL_0000;
						if (fLexerInput->HasMoreChars()) {
							c = fLexerInput->MoveToNextChar();
							charactersToRevert++;
							if (!isHexDigit( c ))	break;
							// Now we want to add the hex digit we got into our ultimate value
							value += sixteenToThePowerOf( i ) * getHexValueFromCharacter( c );
							outEntityConsumed.AppendUniChar( c );
						} else break;
					}

					// The last character needs to be a semi-colon, or else it's not a legal entity
					if (!fLexerInput->HasMoreChars()) break;
					if (fLexerInput->MoveToNextChar() != CHAR_SEMICOLON) {
						charactersToRevert++;
						break;
					}

					outEntityConsumed.AppendUniChar( ';' );

					// Add the value as a UniChar to our stream
					outCharacterToAdd = (UniChar)value;
					return true;
				} break;
				default: {
					// We want to test to see whether the character we read is a legal decimal digit.  If it
					// is, then we have a character literal.  If not, the user screwed up and we can just bail.
					if (isDecimalDigit( literalType )) {
						// We're going to put the character back just to parse it again.  It makes the logic easier
						fLexerInput->MoveToPreviousChar();

						// We know that we've got some digits we care about.  Now we need to find out how many,
						// and we'll put the cap at something sensible, like 5 characters (which can cover all of
						// the unicode code points in existence).
						unsigned short value = 0;

						for (sLONG i = 0; i < 5; i++) {
							UniChar c = CHAR_CONTROL_0000;
							if (fLexerInput->HasMoreChars()) {
								c = fLexerInput->MoveToNextChar();
								charactersToRevert++;
								if (!isDecimalDigit( c ))	break;
								// Now we want to add the decimal digit we got into our ultimate value
								value += tenToThePowerOf( i ) * (c - '0');
								outEntityConsumed.AppendUniChar( c );
							} else break;
						}

						// The last character needs to be a semi-colon, or else it's not a legal entity
						if (!fLexerInput->HasMoreChars()) break;
						if (fLexerInput->MoveToNextChar() != CHAR_SEMICOLON) {
							charactersToRevert++;
							break;
						}

						outEntityConsumed.AppendUniChar( ';' );

						// Add the value as a UniChar to our stream
						outCharacterToAdd = (UniChar)value;
						return true;
					} else break;
				} break;
			}
		} break;
		default: {
			// We found an ampersand and know it's not a numeric literal.  Now we need to see whether it's an
			// entity made to be a bit more human readable.  We're going to grab a bunch of characters from the
			// stream without actually shifting them in.  We cut them off at the semi-colon because all entities
			// must end with one to be legal.  Then, if it matches a known entity, we're set -- otherwise it's just
			// a stream of random characters.  We need a whopping nine character to be able to support &thetasym;
			VString entityName;
			fLexerInput->GetSubString( fLexerInput->GetCurrentPosition(), 9, entityName );

			// Now, let's see where the semi-colon is, and strip it off (as well as everything past it).  If we don't
			// find a semi-colon, then we know we don't have an entity
			VectorOfVString subStrs;
			if (!entityName.GetSubStrings( CHAR_SEMICOLON, subStrs ))	break;

			// The first sub string is the entity name we care about
			if (GetEntityValue( subStrs.front(), outCharacterToAdd )) {
				// We want to eat up as many characters as the entity was consuming
				VIndex size = subStrs.front().GetLength();
				for (VIndex i = 0; i < size; i++) {
					outEntityConsumed.AppendUniChar( fLexerInput->MoveToNextChar() );
				}
				return true;
			}
		} break;
	}

	// Put back the characters we screwed up on
	for (sLONG i = 0; i < charactersToRevert; i++)	fLexerInput->MoveToPreviousChar();

	return false;
}
コード例 #19
0
bool ScriptDocLexer::ConsumeScriptDocTag()
{
	// We need to consume the @ token for the tag.  We know it exists because
	// we've already peeked at it
	if (!testAssert( fLexerInput->MoveToNextChar() == CHAR_COMMERCIAL_AT ))	return false;

	// After the @ symbol comes the name of the tag, followed by some whitespace.  Any
	// whitespace between the @ and the tag name will be eaten
	bool toss = false;
	if (!SkipWhitespaces( toss ))	return false;

	UniChar ch;
	VString text;
	bool bLineEnded = false;
	while (true) {
		if (!fLexerInput->HasMoreChars())	return false;
		ch = fLexerInput->MoveToNextChar();
		if (IsWhitespace( ch )) break;
		if (IsLineEnding( ch )) {
			ConsumeLineEnding( ch );
			bLineEnded = true;
			break;
		}
		text.AppendUniChar( ch );
	}

	// Skip any whitespace between the tag name and the tag contents
	if (!SkipWhitespaces( toss ))	return false;

	// Now that we have the tag name, we can create the appropriate class to represent
	// it.
	VString simpleText;
	if (text == "author" && ConsumeComment( simpleText ))
	{
		fLastElement = new AuthorElement( simpleText );
	}
	else if (text == "alias" && ConsumeComment( simpleText ))
	{
		fLastElement = new AliasElement( simpleText );
	} 
	else if (text == "attributes" && ConsumeComment( simpleText ))
	{
		fLastElement = new AttributesElement( simpleText );
	}
	else if (text == "class" && ConsumeComment( simpleText ))
	{
		fLastElement = new ClassElement( simpleText );
	}
	else if (text == "classDescription" && ConsumeComment( simpleText ))
	{
		fLastElement = new ClassDescriptionElement( simpleText );
	}
	else if (text == "constructor")
	{
		fLastElement = new ConstructorElement();
	}
	else if (text == "default" && ConsumeComment( simpleText ))
	{
		fLastElement = new DefaultElement(simpleText);
	}
	else if (text == "deprecated" && ConsumeComment( simpleText ))
	{
		fLastElement = new DeprecatedElement(simpleText);
	}
	else if (text == "exception")
	{
		return ConsumeExceptionTag();
	}
	else if ( (text == "extends" || text == "augments" || text == "inherits") && ConsumeComment( simpleText ))
	{
		fLastElement = new ExtendsElement(simpleText);
	}
	else if (text == "id" && ConsumeComment( simpleText ))
	{
		fLastElement = new IdElement( simpleText );
	}
	else if (text == "inherits" && ConsumeComment( simpleText ))
	{
		fLastElement = new InheritsElement( simpleText );
	}
	else if (text == "memberOf" && ConsumeComment( simpleText ))
	{
		fLastElement = new MemberOfElement( simpleText );
	}
	else if (text == "method")
	{
		return ConsumeMethodTag();
	}
	else if (text == "module" && ConsumeComment( simpleText ))
	{
		fLastElement = new ModuleElement( simpleText );
	}
	else if (text == "namespace" && ConsumeComment( simpleText ))
	{
		fLastElement = new NamespaceElement( simpleText );
	}
	else if (text == "param")
	{
		return ConsumeParamTag();
	}
	else if (text == "paramValue")
	{
		return ConsumeParamValueTag();
	}
	else if (text == "private")
	{
		fLastElement = new PrivateElement();
	}
	else if (text == "projectDescription" && ConsumeComment( simpleText ))
	{
		fLastElement = new ProjectDescriptionElement( simpleText );
	}
	else if (text == "property")
	{
		return ConsumePropertyTag();
	}
	else if ( (text == "require" ||text == "requires") && ConsumeComment( simpleText ))
	{
		fLastElement = new RequiresElement( simpleText );
	}
	else if (text == "return" || text == "returns" || text == "result")
	{
		return ConsumeReturnTag();
	}
	else if (text == "sdoc" && ConsumeComment( simpleText ))
	{
		fLastElement = new SDocElement( simpleText );
	}
	else if (text == "see")
	{
		return ConsumeSeeTag();
	}
	else if (text == "since" && ConsumeComment( simpleText ))
	{
		fLastElement = new SinceElement( simpleText );
	}
	else if (text == "static")
	{
		fLastElement = new StaticElement();
	}
	else if (text == "throws" || text == "throw")
	{
		return ConsumeThrowsTag();
	}
	else if (text == "type")
	{
		return ConsumeTypeTag();
	}
	else if (text == "version" && ConsumeComment( simpleText ))
	{
		fLastElement = new VersionElement( simpleText );
	}
	else
	{
		// This is an unsupported tag, so make an Unknown tag to handle it.  Unknown tags can
		// have comments following them, or just a newline signifying it's time for another tag.
		// We don't know which it is supposed to be, so we will skip whitespaces and check to see
		// if there's a newline.  If there is, then it's assumed to be a tag with no comments.
		if (bLineEnded || ConsumeComment( simpleText ))
		{
			fLastElement = new UnknownElement( text, simpleText );
		}
		else
		{
			return false;
		}
	}
	return true;
}
コード例 #20
0
void VSysLogOutput::Put( std::vector< const XBOX::VValueBag* >& inValuesVector)
{
	for (std::vector< const XBOX::VValueBag* >::iterator bagIter = inValuesVector.begin() ; bagIter != inValuesVector.end() ; ++bagIter)
	{
		EMessageLevel bagLevel = ILoggerBagKeys::level.Get( *bagIter);
		if ((fFilter & (1 << bagLevel)) != 0)
		{
			VString logMsg;
						
			VError errorCode = VE_OK;
			ILoggerBagKeys::error_code.Get( *bagIter, errorCode);
		
			VString loggerID;
			ILoggerBagKeys::source.Get( *bagIter, loggerID);
			
			OsType componentSignature = 0;
			if (!ILoggerBagKeys::component_signature.Get( *bagIter, componentSignature))
				componentSignature = COMPONENT_FROM_VERROR( errorCode);
			
			if (componentSignature != 0)
			{
				if (!loggerID.IsEmpty())
					loggerID.AppendUniChar( L'.');
				loggerID.AppendOsType( componentSignature);
			}
			
			if (!loggerID.IsEmpty())
				logMsg.Printf( "[%S]", &loggerID);
			
			// build message string
			VString message;
			
			if (errorCode != VE_OK)
				message.AppendPrintf( "error %d", ERRCODE_FROM_VERROR( errorCode));
			
			VString bagMsg;
			if (ILoggerBagKeys::message.Get( *bagIter, bagMsg))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( bagMsg);
			}
						
			sLONG taskId=-1;
			if (ILoggerBagKeys::task_id.Get( *bagIter, taskId))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"task #");
				message.AppendLong( taskId);
			}
			
			VString taskName;
			if (!ILoggerBagKeys::task_name.Get( *bagIter, taskName))
				VTask::GetCurrent()->GetName( taskName);
			if (!taskName.IsEmpty())
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( taskName);
			}
			
			sLONG socketDescriptor=-1;
			if (ILoggerBagKeys::socket.Get( *bagIter, socketDescriptor))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"socket ");
				message.AppendLong(socketDescriptor);
			}
			
			VString localAddr;
			if (ILoggerBagKeys::local_addr.Get( *bagIter, localAddr))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"local addr is ");
				message.AppendString( localAddr);
			}
			
			VString peerAddr;
			if (ILoggerBagKeys::peer_addr.Get( *bagIter, peerAddr))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"peer addr is ");
				message.AppendString( peerAddr);
			}
			
			bool exchangeEndPointID=false;
			if (ILoggerBagKeys::exchange_id.Get( *bagIter, exchangeEndPointID))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( (exchangeEndPointID) ? L"exchange endpoint id" : L"do not exchange endpoint id");
			}
			
			bool isBlocking=false;
			if (ILoggerBagKeys::is_blocking.Get( *bagIter, isBlocking))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( (isBlocking) ? L"is blocking" : L"is not blocking");
			}
			
			bool isSSL=false;
			if (ILoggerBagKeys::is_ssl.Get( *bagIter, isSSL))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( (isSSL) ? L"with SSL" : L"without SSL");
			}
			
			bool isSelectIO=false;
			if (ILoggerBagKeys::is_select_io.Get( *bagIter, isSelectIO))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( (isSelectIO) ? L"with SelectIO" : L"without SelectIO");
			}
			
			sLONG ioTimeout=-1;
			if (ILoggerBagKeys::ms_timeout.Get( *bagIter, ioTimeout))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"with ");
				message.AppendLong( ioTimeout);
				message.AppendString( L"ms timeout");
			}
			
			sLONG askedCount=-1;
			if (ILoggerBagKeys::count_bytes_asked.Get( *bagIter, askedCount))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"asked for ");
				message.AppendLong( askedCount);
				message.AppendString( L" byte(s)");
			}
			
			sLONG sentCount=-1;
			if (ILoggerBagKeys::count_bytes_sent.Get(*bagIter, sentCount))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"sent ");
				message.AppendLong( sentCount);
				message.AppendString( L" byte(s)");
			}
			
			sLONG receivedCount=-1;
			if (ILoggerBagKeys::count_bytes_received.Get( *bagIter, receivedCount))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"received ");
				message.AppendLong( receivedCount);
				message.AppendString( L" byte(s)");
			}
			
			sLONG ioSpent=-1;
			if (ILoggerBagKeys::ms_spent.Get( *bagIter, ioSpent))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"done in ");
				message.AppendLong( ioSpent);
				message.AppendString( L"ms");
			}
			
			sLONG dumpOffset=-1;
			if (ILoggerBagKeys::dump_offset.Get( *bagIter, dumpOffset))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"offset ");
				message.AppendLong( dumpOffset);
			}
			
			VString dumpBuffer;
			if (ILoggerBagKeys::dump_buffer.Get( *bagIter, dumpBuffer))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"data : ");
				message.AppendString( dumpBuffer);
			}
			
			VString fileName;
			if (ILoggerBagKeys::file_name.Get( *bagIter, fileName))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( fileName);
			}
			
			sLONG lineNumber;
			if (ILoggerBagKeys::line_number.Get( *bagIter, lineNumber))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendLong( lineNumber);
			}
			
			VString stackCrawl;
			if (ILoggerBagKeys::stack_crawl.Get( *bagIter, stackCrawl))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L", {");
				stackCrawl.ExchangeAll( L"\n", L" ; ");
				message.AppendString( stackCrawl);
				message.AppendUniChar( L'}');
			}
			
			if (!logMsg.IsEmpty())
				logMsg.AppendUniChar( L' ');
			logMsg.AppendString( message);
			
			if (!logMsg.IsEmpty())
			{
				StStringConverter<char> messageConverter( VTC_StdLib_char);
		
				switch( bagLevel)
				{
					case EML_Dump:
					case EML_Assert:
					case EML_Debug:
						syslog( LOG_DEBUG, messageConverter.ConvertString( logMsg));
						break;
						
					case EML_Trace:
						syslog( LOG_NOTICE, messageConverter.ConvertString( logMsg));
						break;

					case EML_Information:
						syslog( LOG_INFO, messageConverter.ConvertString( logMsg));
						break;
							   
					case EML_Warning:
						syslog( LOG_WARNING, messageConverter.ConvertString( logMsg));
						break;
							   
					case EML_Error:
						syslog( LOG_ERR, messageConverter.ConvertString( logMsg));
						break;
						
					case EML_Fatal:
						syslog( LOG_CRIT, messageConverter.ConvertString( logMsg));
						break;
							   
				   default:
					   assert(false);
					   break;
				}
			}
		}
	}
}
コード例 #21
0
ファイル: VValueBag.cpp プロジェクト: StephaneH/core-XToolbox
void AppendJSONNewline(VString& outJSONString, bool prettyformat)
{
	if (prettyformat)
		outJSONString.AppendUniChar(10);
}