Example #1
0
//--------------------------------------------------------------------------
uint32_t JSONElement::size() const
{
	if (m_at == NULL)
	{
		return 0;
	}

	switch(json::type(m_at))
	{
		case JSONType::NIL:
		{
			return 1;
		}
		case JSONType::OBJECT:
		{
			Map<DynamicString, const char*> object(default_allocator());
			json::parse_object(m_at, object);
			return map::size(object);
		}
		case JSONType::ARRAY:
		{
			Array<const char*> array(default_allocator());
			json::parse_array(m_at, array);
			return array::size(array);
		}
		case JSONType::STRING:
		{
			DynamicString string;
			json::parse_string(m_at, string);
			return string.length();
		}
		case JSONType::NUMBER:
		{
			return 1;
		}
		case JSONType::BOOL:
		{
			return 1;
		}
		default:
		{
			CE_FATAL("Oops, unknown value type");
			return 0;
		}
	}
}
Example #2
0
bool LocalizableStringManager::ParseResourceFile( const BazisLib::String &fp )
{
	ManagedPointer<TextANSIFileReader> pRdr = new TextANSIFileReader(new ACFile(fp, FileModes::OpenReadOnly));
	if (!pRdr->Valid())
	{
		_tprintf(_T("ERROR: cannot open %s\n"), fp.c_str());
		return false;
	}
	_tprintf(_T("  %s\n"), DynamicString(Path::GetFileName((fp))).c_str());

	DynamicString dialogName;
	bool insideDialogDescription = false;
	size_t spacingBeforeDlgitem = -1;

	unsigned lineNum = 0;

	while (!pRdr->IsEOF())
	{
		lineNum++;
		DynamicStringA line = pRdr->ReadLine();
		_FixedCharacterSplitString<2, TempStringA> tokens(line, ' ');
		if (!tokens.count())
			continue;
		if (!tokens[0].icompare("BEGIN"))
			insideDialogDescription = true;
		else if (!tokens[0].icompare("END"))
			dialogName.clear(), insideDialogDescription = false;
		else if (!tokens[1].icompare("DIALOGEX"))
		{
			dialogName = ANSIStringToString(tokens[0]), insideDialogDescription = false;
			m_Dialogs[dialogName].FileAndLine.Format(_T("%s(%d)"), GetFullPath(fp).c_str(), lineNum);
		}
		else if (!line.substr(0, 8).icompare("CAPTION ") && !dialogName.empty() && !insideDialogDescription)
		{
			TempStringA dlgCaption = line.substr(9);
			size_t lastQuote = dlgCaption.find_last_of('\"');
			if (lastQuote != -1)
				dlgCaption = dlgCaption.substr(0, lastQuote);

			DynamicString translatedCaption = ANSIStringToString(dlgCaption);
			for (size_t idx = 0; idx < (translatedCaption.length() - 1); idx++)
			{
				if ((translatedCaption[idx] == '\"') && (translatedCaption[idx + 1] == '\"'))
					translatedCaption.erase(idx, 1);
			}
			m_Dialogs[dialogName].Caption = FormatStringASCString(translatedCaption);
		}
		else if (insideDialogDescription && !dialogName.empty())
		{
			if (spacingBeforeDlgitem == -1)
				spacingBeforeDlgitem = line.find_first_not_of(" \t");
			if (spacingBeforeDlgitem == -1)
				continue;

			if ((line.length() <= spacingBeforeDlgitem) || (line[spacingBeforeDlgitem] == ' ') || (line[spacingBeforeDlgitem] == '\t'))
				continue;

			_FixedSetOfCharsSplitString<1, TempStringA> tokens2(line.substr(spacingBeforeDlgitem), " \t");
			if (tokens2.count() < 1)
				continue;

			if (!tokens2[0].length())
				continue;

			size_t nameStart = tokens2.GetRemainderOffset();
			if (nameStart == -1)
				continue;

			nameStart = line.find_first_not_of(" \t", nameStart + spacingBeforeDlgitem);

			if ((nameStart == -1) || (line[nameStart] != '\"'))
				continue;

			nameStart++;

			char prevChar = 0;
			size_t nameEnd;
			for (nameEnd = nameStart; nameEnd < line.length(); nameEnd++)
			{
				if (line[nameEnd] == '\"')
				{
					if (((nameEnd + 1) < line.length()) && (line[nameEnd + 1] == '\"'))
					{
						nameEnd++;
						continue;
					}
					else
						break;
				}
			}

			DynamicStringA itemText = line.substr(nameStart, nameEnd - nameStart);

			for (size_t idx = 0; (idx + 1) < itemText.length(); idx++)
			{
				if ((itemText[idx] == '\"') && (itemText[idx + 1] == '\"'))
					itemText.erase(idx, 1);
			}


			size_t IDOffset = line.find_first_not_of(" \t,", nameEnd + 1);
			if (IDOffset == -1)
				continue;
			size_t IDEnd = line.find_first_of(" \t,", IDOffset);

			TempStringA itemID = line.substr(IDOffset, (IDEnd == -1) ? -1 : IDEnd - IDOffset);

			m_Dialogs[dialogName].DialogMembers[ANSIStringToString(itemID)].Name = FormatStringASCString(ANSIStringToString(itemText));
			
		}
	}
	return true;
}