コード例 #1
0
bool JS4D::StringToVString( StringRef inJSString, VString& outString)
{
	bool ok;
	if (inJSString != NULL)
	{
		size_t length = JSStringGetLength( inJSString);
		UniChar *p = outString.GetCPointerForWrite( length);
		if (p != NULL)
		{
			::memcpy( p, JSStringGetCharactersPtr( inJSString), length * sizeof( UniChar));
			ok = outString.Validate( length);
		}
		else
		{
			outString.Clear();
			ok = false;
		}
	}
	else
	{
		ok = false;
		outString.Clear();
	}
	return ok;
}
コード例 #2
0
VError VJSONValue::GetString( VString& outString) const
{
    VError err = VE_OK;
    switch( fType)
    {
    case JSON_undefined:
    {
        outString.Clear();	// not 'undefined'. toString() returns an empty string on an undefined value in a javascript array
        break;
    }

    case JSON_null:
    {
        outString.Clear();	// not 'null'. toString() returns an empty string on a null value in a javascript array
        break;
    }

    case JSON_true:
    {
        outString = sTrueString;
        break;
    }

    case JSON_false:
    {
        outString = sFalseString;
        break;
    }

    case JSON_string:
    {
        outString.FromString( fString);
        break;
    }

    case JSON_number:
    {
        VReal r( fNumber);
        err = r.GetJSONString( outString, JSON_Default);
        break;
    }

    case JSON_array:
    {
        err = fArray->GetString( outString);
        break;
    }

    case JSON_object:
    {
        err = fObject->GetString( outString);
        break;
    }

    default:
        xbox_assert( false);
    }

    return err;
}
コード例 #3
0
void AXMLElement::GetData( VString &pCData)
{
	AXMLGenericElement	*elem;
	VString			vCData;

	vCData.Clear();
	pCData.Clear();
	elem = Get_FirstChild();
	while (elem) {
		elem->GetData(vCData);
		pCData.AppendString(vCData);
//		pCData.AppendChar((uBYTE)0x0D);
		elem = elem->GetNext();
	}
}
コード例 #4
0
Boolean VMacResFile::GetString(VString& outString, sLONG inID) const
{
	outString.Clear();

	if (!testAssert(fRefNum != -1))
		return false;
	
	if (!testAssert(inID >= -32768 && inID <= 32767))
		return false;

	sWORD	curres = ::CurResFile();
	if (curres != fRefNum)
		::UseResFile(fRefNum);

	Handle data = fUseResourceChain ? ::GetResource('STR ', (short) inID) : ::Get1Resource('STR ', (short) inID);

	if (curres != fRefNum)
		::UseResFile(curres);
		
	Boolean isOK = false;
	if (testAssert(data != NULL))
	{
		if (testAssert(*data != NULL))
		{
			::HLock(data);
			outString.MAC_FromMacPString((StringPtr) *data);
			::HUnlock(data);
			isOK = true;
		}
	}
	return isOK;
}
コード例 #5
0
void VJSPropertyIterator::GetPropertyName( VString& outName) const
{
	if (testAssert( fIndex < fCount))
		JS4D::StringToVString( JSPropertyNameArrayGetNameAtIndex( fNameArray, fIndex), outName);
	else
		outName.Clear();
}
コード例 #6
0
void XMacFontMgr::GetStdFont( StdFont inFont, VString& outName, VFontFace& outFace, GReal& outSize)
{
	// on risque de perdre des infos, il faudrait retourner une VFont
	
	CTFontUIFontType fontType = StdFontToThemeFontID( inFont);
	CTFontRef fontRef = ::CTFontCreateUIFontForLanguage( fontType, 0 /*size*/, NULL /*language*/ );

	if (testAssert( fontRef != NULL))
	{
		outSize = ::CTFontGetSize( fontRef);

		CFStringRef cfName = ::CTFontCopyFamilyName( fontRef);
		if (cfName != NULL)
		{
			outName.MAC_FromCFString( cfName);
			::CFRelease( cfName);
		}
		else
		{
			outName.Clear();
		}
		
		CTFontSymbolicTraits traits = ::CTFontGetSymbolicTraits( fontRef);
		outFace = 0;
		
		if (traits & kCTFontItalicTrait)
			outFace |= KFS_ITALIC;
		
		if (traits & kCTFontBoldTrait)
			outFace |= KFS_BOLD;
		
		if (traits & kCTFontExpandedTrait)
			outFace |= KFS_EXTENDED;
		
		if (traits & kCTFontCondensedTrait)
			outFace |= KFS_CONDENSED;

		CFRelease( fontRef); 
	}
	else
	{
		outName.Clear();
		outSize = 0;
		outFace = 0;
	}
}
コード例 #7
0
Boolean IPropertyCollector::GetName(VString& outName) const
{
	Boolean succeed = GetString(CVSTR("name"), outName);
	
	if (!succeed)
		outName.Clear();
	
	return succeed;
}
コード例 #8
0
bool XWinIntlMgr::GetLocaleInfo( LCTYPE inType, VString& outInfo) const
{
	UniChar info[256];
	int r = ::GetLocaleInfoW( fDialect, inType, info, sizeof( info) / sizeof( UniChar));
	if (testAssert( r != 0))
		outInfo = info;
	else
		outInfo.Clear();
	return r != 0;
}
コード例 #9
0
bool VJSObject::GetPropertyAsString(const VString& inPropertyName, JS4D::ExceptionRef *outException, VString& outResult) const
{
	bool ok = false;
	VJSValue result(GetProperty(inPropertyName, outException));
	outResult.Clear();
	if (!result.IsNull() && !result.IsUndefined())
	{
		ok = result.GetString(outResult, outException);
	}
	return ok;
}
コード例 #10
0
void AXMLElement::GetAttribute(const VString &pAttributename,VString &pValue) {
	AXMLAttribute	*attribute = NULL;
	attribute = fFirstAttribute;
	while (attribute)
	{
		if (attribute->GetName() == pAttributename) break;
		attribute = attribute->GetNext();
	}
	if (attribute) pValue.FromString(attribute->GetValue());
	else pValue.Clear();
}
コード例 #11
0
Boolean VMacResFile::GetString(VString& outString, sLONG inID, sLONG inIndex) const
{
	outString.Clear();

	if (!testAssert(fRefNum != -1))
		return false;
	
	if (!testAssert(inID >= -32768 && inID <= 32767 && inIndex > 0))
		return false;

	Boolean isOK = false;

	sWORD	curres = ::CurResFile();
	if (curres != fRefNum)
		::UseResFile(fRefNum);
		
	if (fReadOnly && (fLastStringListID == inID) && (fLastStringList != NULL))
	{
		if (*fLastStringList == NULL)
			::LoadResource(fLastStringList);
	}
	else
	{
		fLastStringListID = (short) inID;
		fLastStringList = fUseResourceChain ? ::GetResource('STR#', fLastStringListID) : ::Get1Resource('STR#', fLastStringListID);
	}
	
	if (curres != fRefNum)
		::UseResFile(curres);

	if (testAssert(fLastStringList != NULL))
	{
		if (testAssert(*fLastStringList != NULL))
		{
			::HLock(fLastStringList);
	
			sLONG count = **(sWORD**) fLastStringList;
			if (count >= inIndex)
			{
				StringPtr strs = (StringPtr) *fLastStringList + sizeof(sWORD);
				while(--inIndex)
					strs += strs[0] + 1;
				outString.MAC_FromMacPString(strs);
				isOK = true;
			}
	
			::HUnlock(fLastStringList);
		}
	}
	return isOK;
}
コード例 #12
0
void VProcess::GetBuildNumber( VString& outName) const
{
	// product version string should be formatted as follows: 1.0 build 2.108412
	VIndex pos = fProductVersion.Find( "build ");
	if (pos > 0)
	{
		fProductVersion.GetSubString( pos + 6, fProductVersion.GetLength() - pos - 5, outName); 
		outName.RemoveWhiteSpaces();
	}
	else
	{
		outName.Clear();
	}
}
コード例 #13
0
	virtual	VError HandleRequest( IHTTPResponse* inResponse)
			{
				if (inResponse == NULL)
					return VE_INVALID_PARAMETER;

				VError err = VE_OK;
				bool done = false;

				// First, extract the relative path from the url
				VString path = inResponse->GetRequest().GetURLPath();
				VRegexMatcher *matcher = VRegexMatcher::Create( fPattern, &err);
				if ((matcher != NULL) && (err == VE_OK))
				{
					bool match = matcher->Find( path, 1, false, &err);
					if (match && (err == VE_OK))
					{
						// Remove the pattern from the path
						path.Remove( matcher->GetGroupStart(0), matcher->GetGroupLength(0));

						// Check whether a namespace is specified
						VString lNamespaceKey( L"namespace=");
						VString lNamespace = inResponse->GetRequest().GetURLQuery();
						if (lNamespace.BeginsWith( lNamespaceKey))
							lNamespace.Remove( 1, lNamespaceKey.GetLength());
						else
							lNamespace.Clear();

						// Now, we have a relative  module path
						VString proxy;
						err = fService->GetProxy( proxy, path, lNamespace, &inResponse->GetRequest(), inResponse);
						if (err == VE_OK)
						{
							VString contentType( L"application/javascript");
							err = SetHTTPResponseString( inResponse, proxy, &contentType);
							done = true;
						}
					}
				}
				ReleaseRefCountable( &matcher);

				if (!done)
					err = inResponse->ReplyWithStatusCode( HTTP_NOT_FOUND);

				return err;
			}
コード例 #14
0
bool VEnvironmentVariables::GetEnvironmentVariableValue(const VString &inEnvName, VString &outEnvValue, bool inAndRemoveIt)
{
	bool	gotIt = false;
	
	outEnvValue.Clear();
	if(!inEnvName.IsEmpty() && !fEnvVars.empty())
	{
		EnvVarNamesAndValuesMap::iterator	envVarIt = fEnvVars.find(inEnvName);
		if(envVarIt != fEnvVars.end())
		{
			outEnvValue = envVarIt->second;
			gotIt = true;
			if(inAndRemoveIt)
				fEnvVars.erase(envVarIt);
		}
	}
	
	return gotIt;
}
コード例 #15
0
VError VMacResFile::GetResourceName(const VString& inType, sLONG inID, VString& outName) const
{
	outName.Clear();
	Handle data = NULL;
	VError error = _GetResource(inType, inID, &data);
	if (error == VE_OK)
	{
		ResType type;
		sWORD	id;
		Str255 spName;
		::GetResInfo(data, &id, &type, spName);
		OSErr macError = ::ResError();
		if (testAssert(macError == noErr))
		{
			outName.MAC_FromMacPString(spName);
		} else
			error = VErrorBase::NativeErrorToVError((VNativeError)macError);
	}
	return error;
}
コード例 #16
0
VError VJSONArray::GetString( VString& outString) const
{
    VError err = VE_OK;

    if (fVector.empty())
    {
        outString.Clear();
    }
    else
    {
        VectorOfVString array;
        array.resize( fVector.size());
        VectorOfVString::iterator j = array.begin();
        for( VectorType::const_iterator i = fVector.begin() ; (i != fVector.end()) && (err == VE_OK) ; ++i, ++j)
        {
            err = i->GetString( *j);
        }
        err = outString.Join( array, ',') ? VE_OK : vThrowError( VE_STRING_ALLOC_FAILED);
    }
    return err;
}
コード例 #17
0
void XWinIntlMgr::FormatTime( const VTime& inTime, VString& outTime, EOSFormats inFormat, bool inUseGMTTimeZoneForDisplay)
{
	// 1:system short time; 2:system medium time; 3:system long time

	DWORD timeFormat=0;
	switch(inFormat)
	{
		case eOS_SHORT_FORMAT:// No signs
		case eOS_MEDIUM_FORMAT:// No signs
			timeFormat=TIME_NOTIMEMARKER;
			break;
		case eOS_LONG_FORMAT://all
			break;
		default:
			break;
	};

	// Prepare SYSTEMTIME for windows.
	sWORD YY=0,MM=0,DD=0,hh=0,mm=0,ss=0,ms=0;
	SYSTEMTIME osTime={0};
	if (inUseGMTTimeZoneForDisplay)
		inTime.GetUTCTime (YY,MM,DD,hh,mm,ss,ms);
	else
		inTime.GetLocalTime (YY,MM,DD,hh,mm,ss,ms);
	osTime.wYear=YY;
	osTime.wMonth=MM;
	osTime.wDay=DD;
	osTime.wHour=hh;
	osTime.wMinute=mm;
	osTime.wSecond=ss;
	osTime.wMilliseconds=ms;

	// Let the OS do the stuff.
	UniChar acBuffer[256];
	if (::GetTimeFormatW( fDialect,timeFormat,&osTime,NULL,acBuffer,sizeof(acBuffer)))
		outTime=acBuffer;
	else
		outTime.Clear();
}
コード例 #18
0
void VFolder::GetPath( VString &outPath, FilePathStyle inPathStyle) const
{
	switch (inPathStyle)
	{
		case FPS_SYSTEM :
			fPath.GetPath( outPath );
			break;

		case FPS_POSIX :
			{
				VError err = fFolder.GetPosixPath( outPath);
				if (err != VE_OK)
					fPath.GetPosixPath( outPath);	// boff
				break;
			}
			break;

		default:
			xbox_assert( false);
			outPath.Clear();
			break;
	}
}
コード例 #19
0
void AXMLAttribute::GetRawData(VString &pDestination) const
{
	pDestination.Clear();
	AppendRawData(pDestination);
}
コード例 #20
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;
}
コード例 #21
0
void AXMLDocument::GetRawData(VString &pDestination,bool pIndented) const
{
	pDestination.Clear();
	AppendRawData(pDestination,pIndented);
}
コード例 #22
0
ファイル: VValueBag.cpp プロジェクト: StephaneH/core-XToolbox
VError VValueBag::GetJSONString(VString& outJSONString, JSONOption inModifier) const
{
	outJSONString.Clear();
	sLONG curlevel = 0;
	return _GetJSONString(outJSONString, curlevel, (inModifier & JSON_PrettyFormatting) != 0, inModifier);
}