mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Persistence for Validators
This commit is contained in:
@@ -170,4 +170,85 @@ void Utilities::parseResultLine (
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
String Utilities::itos (int i, int fieldSize)
|
||||
{
|
||||
return String::fromNumber (i).paddedLeft (beast_wchar('0'), fieldSize);
|
||||
}
|
||||
|
||||
String Utilities::timeToString (Time const& t)
|
||||
{
|
||||
if (t.isNotNull ())
|
||||
{
|
||||
return
|
||||
itos (t.getYear(), 4) + "-" +
|
||||
itos (t.getMonth(), 2) + "-" +
|
||||
itos (t.getDayOfMonth (), 2) + " " +
|
||||
itos (t.getHours () , 2) + ":" +
|
||||
itos (t.getMinutes (), 2) + ":" +
|
||||
itos (t.getSeconds(), 2);
|
||||
}
|
||||
|
||||
return String::empty;
|
||||
}
|
||||
|
||||
int Utilities::stoi (String& s, int fieldSize, int minValue, int maxValue, beast_wchar delimiter)
|
||||
{
|
||||
int const needed (fieldSize + ((delimiter != 0) ? 1 : 0));
|
||||
String const v (s.substring (0, needed));
|
||||
s = s.substring (v.length ());
|
||||
if (s.length() == needed)
|
||||
{
|
||||
int const v (s.getIntValue());
|
||||
if (s.startsWith (itos (v, fieldSize)) &&
|
||||
v >= minValue && v <= maxValue &&
|
||||
(delimiter == 0 || s.endsWithChar (delimiter)))
|
||||
{
|
||||
return v;
|
||||
}
|
||||
}
|
||||
return -1; // fail
|
||||
}
|
||||
|
||||
Time Utilities::stringToTime (String s)
|
||||
{
|
||||
if (s.isNotEmpty ())
|
||||
{
|
||||
int const year (stoi (s, 4, 1970, 9999, '-'));
|
||||
int const mon (stoi (s, 2, 0, 11, '-'));
|
||||
int const day (stoi (s, 2, 1, 31, ' '));
|
||||
int const hour (stoi (s, 2, 0, 23, ':'));
|
||||
int const min (stoi (s, 2, 0, 59, ':'));
|
||||
int const sec (stoi (s, 2, 0, 59, 0 ));
|
||||
if (year != -1 &&
|
||||
mon != -1 &&
|
||||
day != -1 &&
|
||||
hour != -1 &&
|
||||
min != -1 &&
|
||||
sec != -1)
|
||||
{
|
||||
// local time
|
||||
return Time (year, mon, day, hour, min, sec, 0, true);
|
||||
}
|
||||
}
|
||||
|
||||
return Time (0);
|
||||
}
|
||||
|
||||
std::string Utilities::publicKeyToString (PublicKey const& publicKey)
|
||||
{
|
||||
std::string s (PublicKey::sizeInBytes, ' ');
|
||||
std::copy (publicKey.cbegin(), publicKey.cend(), s.begin());
|
||||
return s;
|
||||
}
|
||||
|
||||
PublicKey Utilities::stringToPublicKey (std::string const& s)
|
||||
{
|
||||
bassert (s.size() == PublicKey::sizeInBytes);
|
||||
return PublicKey (&s.front());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user