// OpenSTA, Static Timing Analyzer
// Copyright (c) 2025, Parallax Software, 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 .
//
// The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software.
//
// Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// This notice may not be removed or altered from any source distribution.
#pragma once
#include
#include
#include
#include
#include
#include // for strncasecmp
#include
#include
#include "Machine.hh" // __attribute__
namespace sta {
using StringSeq = std::vector;
using StringSet = std::set;
inline bool
stringEq(const char *str1,
const char *str2)
{
return strcmp(str1, str2) == 0;
}
// Compare the first length characters.
inline bool
stringEq(const char *str1,
const char *str2,
size_t length)
{
return strncmp(str1, str2, length) == 0;
}
// Case sensitive compare the beginning of str1 to str2.
inline bool
stringBeginEq(const char *str1,
const char *str2)
{
return strncmp(str1, str2, strlen(str2)) == 0;
}
// Case insensitive compare the beginning of str1 to str2.
inline bool
stringBeginEqual(std::string_view str,
std::string_view prefix)
{
if (str.size() < prefix.size())
return false;
return strncasecmp(str.data(), prefix.data(), prefix.size()) == 0;
}
// Case insensitive compare.
inline bool
stringEqual(std::string_view s1,
std::string_view s2)
{
return std::ranges::equal(s1, s2, [](unsigned char c1, unsigned char c2) {
return std::tolower(c1) == std::tolower(c2);
});
}
void
stringDeleteCheck(const char *str);
// Delete for strings allocated with new char[].
inline void
stringDelete(const char *str)
{
delete [] str;
}
std::pair
stringFloat(const std::string &str);
bool
isDigits(const char *str);
bool
isDigits(std::string_view str);
////////////////////////////////////////////////////////////////
// Trim right spaces.
void
trimRight(std::string &str);
// Parse text into delimiter separated tokens and skip whitepace.
StringSeq
parseTokens(const std::string &text,
std::string_view delims = " \t");
} // namespace