Esempio n. 1
0
static int GetStringValue(lua_State* L)
{
	CMeasure* self = GetSelf(L);

	int top = lua_gettop(L);
	AUTOSCALE autoScale = (top > 1) ? (AUTOSCALE)(int)lua_tonumber(L, 2) : AUTOSCALE_OFF;
	double scale = (top > 2) ? lua_tonumber(L, 3) : 1.0;
	int decimals = (int)lua_tonumber(L, 4);
	bool percentual = lua_toboolean(L, 5);

	const WCHAR* val = self->GetStringValue(autoScale, scale, decimals, percentual);
	LuaManager::PushWide(L, val);

	return 1;
}
Esempio n. 2
0
/*
** Replaces measures in the given string.
**
*/
bool CConfigParser::ReplaceMeasures(std::wstring& result)
{
    bool replaced = false;

    size_t start = 0;
    while ((start = result.find(L'[', start)) != std::wstring::npos)
    {
        size_t si = start + 1;
        size_t end = result.find(L']', si);
        if (end == std::wstring::npos)
        {
            break;
        }

        size_t next = result.find(L'[', si);
        if (next == std::wstring::npos || end < next)
        {
            size_t ei = end - 1;
            if (si != ei && result[si] == L'*' && result[ei] == L'*')
            {
                result.erase(ei, 1);
                result.erase(si, 1);
                start = ei;
            }
            else
            {
                std::wstring var = result.substr(si, end - si);

                CMeasure* measure = GetMeasure(var);
                if (measure)
                {
                    const WCHAR* value = measure->GetStringValue(AUTOSCALE_OFF, 1, -1, false);
                    size_t valueLen = wcslen(value);

                    // Measure found, replace it with the value
                    result.replace(start, end - start + 1, value, valueLen);
                    start += valueLen;
                    replaced = true;
                }
                else
                {
                    std::wstring value;
                    if (GetSectionVariable(var, value))
                    {
                        // Replace section variable with the value.
                        result.replace(start, end - start + 1, value);
                        start += value.length();
                        replaced = true;
                    }
                    else
                    {
                        start = end;
                    }
                }
            }
        }
        else
        {
            start = next;
        }
    }

    return replaced;
}
Esempio n. 3
0
/*
** Replaces measures in the given string.
**
*/
bool CConfigParser::ReplaceMeasures(std::wstring& result)
{
	bool replaced = false;

	// Check for measures ([Measure])
	if (!m_Measures.empty())
	{
		size_t start = 0, end, next;
		bool loop = true;

		do
		{
			start = result.find(L'[', start);
			if (start != std::wstring::npos)
			{
				size_t si = start + 1;
				end = result.find(L']', si);
				if (end != std::wstring::npos)
				{
					next = result.find(L'[', si);
					if (next == std::wstring::npos || end < next)
					{
						size_t ei = end - 1;
						if (si != ei && result[si] == L'*' && result[ei] == L'*')
						{
							result.erase(ei, 1);
							result.erase(si, 1);
							start = ei;
						}
						else
						{
							std::wstring var = result.substr(si, end - si);

							CMeasure* measure = GetMeasure(var);
							if (measure)
							{
								const std::wstring& value = measure->GetStringValue(AUTOSCALE_OFF, 1, -1, false);

								// Measure found, replace it with the value
								result.replace(start, end - start + 1, value);
								start += value.length();
								replaced = true;
							}
							else
							{
								start = end;
							}
						}
					}
					else
					{
						start = next;
					}
				}
				else
				{
					loop = false;
				}
			}
			else
			{
				loop = false;
			}
		}
		while (loop);
	}

	return replaced;
}