/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see .
*/
// ---------------------------------------------------------------------------
// File: KVPair.cpp
// Author: Matthew D. Campbell
// Creation Date: 9/4/2002
// Description: Key/Value Pair class
// ---------------------------------------------------------------------------
#include "misc.h"
#include "KVPair.h"
#include "debug.h"
#include
std::string intToString(int val)
{
std::string s = "";
bool neg = (val < 0);
if (val < 0)
{
val = -val;
}
if (val == 0)
return "0";
char buf[2];
buf[1] = 0;
while (val)
{
buf[0] = '0' + val%10;
val /= 10;
s.insert(0, buf);
}
if (neg)
s.insert(0, "-");
return s;
}
static std::string trim(std::string s, const std::string& delim)
{
unsigned int i;
i = s.find_first_not_of(delim);
if (i != s.npos)
{
s = s.substr(i);
}
i = s.find_last_not_of(delim);
if (i>=0 && isecond;
}
bool KVPairClass::getString( const std::string& key, std::string& val ) const
{
std::string tmp = getStringVal(key);
if (tmp.empty())
{
return false;
}
val = tmp;
return true;
}
bool KVPairClass::getInt( const std::string& key, int& val ) const
{
std::string tmp = getStringVal(key);
if (tmp.empty())
{
return false;
}
val = atoi(tmp.c_str());
return true;
}
bool KVPairClass::getUnsignedInt( const std::string& key, unsigned int& val ) const
{
std::string tmp = getStringVal(key);
if (tmp.empty())
{
return false;
}
val = atoi(tmp.c_str());
return true;
}