/** * @brief KeyVals::SetKeyVal * @param[in] _key * @param[in] _ud * @return */ bool KeyVals::SetKeyVal(const char *_key, const obUserData &_ud) { if (!_key) { return false; } int ifree = -1; for (int i = 0; i < MaxArgs; ++i) { if (ifree == -1 && m_Key[i][0] == 0) { ifree = i; } if (!_stricmp(m_Key[i], _key)) { m_Value[i] = _ud; return true; } } if (ifree != -1) { Omnibot_strncpy(&m_Key[ifree][0], _key, MaxArgLength - 1); m_Value[ifree] = _ud; return true; } return false; }
/** * @brief Omnibot_FixPath * @param[in] _path * @return */ const char *Omnibot_FixPath(const char *_path) { const int iBufferSize = 512; static char pathstr[iBufferSize] = { 0 }; Omnibot_strncpy(pathstr, _path, iBufferSize); pathstr[iBufferSize - 1] = '\0'; // unixify the path slashes char *pC = pathstr; while (*pC != '\0') { if (*pC == '\\') { *pC = '/'; } ++pC; } // trim any trailing slash while (*pC == '/' && pC > pathstr) { *pC = '\0'; --pC; } return pathstr; }
bool KeyVals::SetString(const char *_key, const char *_value) { _value = _value?_value:""; for(int a = 0; a < MaxArgs; ++a) { // look for the first null string if(m_String[a][0] == '\0') { Omnibot_strncpy(&m_String[a][0],_value,MaxStringLength-1); return SetKeyVal(_key,obUserData(&m_String[a][0])); } } assert(false); return false; }