Dash Core  0.12.2.1
P2P Digital Currency
utilstrencodings.cpp File Reference
#include "utilstrencodings.h"
#include "tinyformat.h"
#include <cstdlib>
#include <cstring>
#include <errno.h>
#include <limits>

Go to the source code of this file.

Functions

string SanitizeString (const string &str, int rule)
 
signed char HexDigit (char c)
 
bool IsHex (const string &str)
 
vector< unsigned char > ParseHex (const char *psz)
 
vector< unsigned char > ParseHex (const string &str)
 
string EncodeBase64 (const unsigned char *pch, size_t len)
 
string EncodeBase64 (const string &str)
 
vector< unsigned char > DecodeBase64 (const char *p, bool *pfInvalid)
 
string DecodeBase64 (const string &str)
 
string EncodeBase32 (const unsigned char *pch, size_t len)
 
string EncodeBase32 (const string &str)
 
vector< unsigned char > DecodeBase32 (const char *p, bool *pfInvalid)
 
string DecodeBase32 (const string &str)
 
static bool ParsePrechecks (const std::string &str)
 
bool ParseInt32 (const std::string &str, int32_t *out)
 
bool ParseInt64 (const std::string &str, int64_t *out)
 
bool ParseDouble (const std::string &str, double *out)
 
std::string FormatParagraph (const std::string &in, size_t width, size_t indent)
 
std::string i64tostr (int64_t n)
 
std::string itostr (int n)
 
int64_t atoi64 (const char *psz)
 
int64_t atoi64 (const std::string &str)
 
int atoi (const std::string &str)
 
static bool ProcessMantissaDigit (char ch, int64_t &mantissa, int &mantissa_tzeros)
 
bool ParseFixedPoint (const std::string &val, int decimals, int64_t *amount_out)
 

Variables

static const string CHARS_ALPHA_NUM = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
 
static const string SAFE_CHARS []
 
const signed char p_util_hexdigit [256]
 
static const int64_t UPPER_BOUND = 1000000000000000000LL - 1LL
 

Function Documentation

◆ atoi()

◆ atoi64() [1/2]

int64_t atoi64 ( const char *  psz)

◆ atoi64() [2/2]

int64_t atoi64 ( const std::string &  str)

Definition at line 532 of file utilstrencodings.cpp.

◆ DecodeBase32() [1/2]

vector<unsigned char> DecodeBase32 ( const char *  p,
bool *  pfInvalid 
)

Definition at line 299 of file utilstrencodings.cpp.

Referenced by DecodeBase32(), and CNetAddr::SetSpecial().

◆ DecodeBase32() [2/2]

string DecodeBase32 ( const string &  str)

Definition at line 416 of file utilstrencodings.cpp.

◆ DecodeBase64() [1/2]

◆ DecodeBase64() [2/2]

string DecodeBase64 ( const string &  str)

Definition at line 229 of file utilstrencodings.cpp.

◆ EncodeBase32() [1/2]

string EncodeBase32 ( const unsigned char *  pch,
size_t  len 
)

Definition at line 235 of file utilstrencodings.cpp.

Referenced by EncodeBase32(), and CNetAddr::ToStringIP().

◆ EncodeBase32() [2/2]

string EncodeBase32 ( const string &  str)

Definition at line 294 of file utilstrencodings.cpp.

◆ EncodeBase64() [1/2]

◆ EncodeBase64() [2/2]

string EncodeBase64 ( const string &  str)

Definition at line 141 of file utilstrencodings.cpp.

◆ FormatParagraph()

std::string FormatParagraph ( const std::string &  in,
size_t  width = 79,
size_t  indent = 0 
)

Format a paragraph of text to a fixed width, adding spaces for indentation to any added line.

Definition at line 478 of file utilstrencodings.cpp.

Referenced by HelpMessageOpt(), and LicenseInfo().

◆ HexDigit()

signed char HexDigit ( char  c)

Definition at line 54 of file utilstrencodings.cpp.

Referenced by IsHex(), ParseHex(), and base_blob< 512 >::SetHex().

◆ i64tostr()

std::string i64tostr ( int64_t  n)

Definition at line 513 of file utilstrencodings.cpp.

Referenced by getblocktemplate(), and WriteOrderPos().

◆ IsHex()

◆ itostr()

◆ ParseDouble()

bool ParseDouble ( const std::string &  str,
double *  out 
)

Convert string to double with strict parse error feedback.

Returns
true if the entire string could be parsed as valid double, false if not the entire string could be parsed or when overflow or underflow occurred.

Definition at line 464 of file utilstrencodings.cpp.

Referenced by UniValue::get_real().

◆ ParseFixedPoint()

bool ParseFixedPoint ( const std::string &  val,
int  decimals,
int64_t *  amount_out 
)

Parse number as fixed point according to JSON number syntax. See http://json.org/number.gif

Returns
true on success, false on error.
Note
The result must be in the range (-10^18,10^18), otherwise an overflow error will trigger.

Definition at line 573 of file utilstrencodings.cpp.

Referenced by AmountFromValue(), and ParsePaymentAmount().

◆ ParseHex() [1/2]

◆ ParseHex() [2/2]

vector<unsigned char> ParseHex ( const string &  str)

Definition at line 90 of file utilstrencodings.cpp.

◆ ParseInt32()

bool ParseInt32 ( const std::string &  str,
int32_t *  out 
)

Convert string to signed 32-bit integer with strict parse error feedback.

Returns
true if the entire string could be parsed as valid integer, false if not the entire string could be parsed or when overflow or underflow occurred.

Definition at line 433 of file utilstrencodings.cpp.

Referenced by UniValue::get_int(), gobject(), LookupSubNet(), rest_getutxos(), SplitHostPort(), MasternodeList::StartAll(), and MasternodeList::updateMyNodeList().

◆ ParseInt64()

bool ParseInt64 ( const std::string &  str,
int64_t *  out 
)

Convert string to signed 64-bit integer with strict parse error feedback.

Returns
true if the entire string could be parsed as valid integer, false if not the entire string could be parsed or when overflow or underflow occurred.

Definition at line 449 of file utilstrencodings.cpp.

Referenced by UniValue::get_int64().

◆ ParsePrechecks()

static bool ParsePrechecks ( const std::string &  str)
static

Definition at line 422 of file utilstrencodings.cpp.

Referenced by ParseDouble(), ParseInt32(), and ParseInt64().

◆ ProcessMantissaDigit()

static bool ProcessMantissaDigit ( char  ch,
int64_t &  mantissa,
int &  mantissa_tzeros 
)
inlinestatic

Helper function for ParseFixedPoint

Definition at line 557 of file utilstrencodings.cpp.

Referenced by ParseFixedPoint().

◆ SanitizeString()

string SanitizeString ( const string &  str,
int  rule 
)

Variable Documentation

◆ CHARS_ALPHA_NUM

const string CHARS_ALPHA_NUM = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
static

Definition at line 17 of file utilstrencodings.cpp.

◆ p_util_hexdigit

const signed char p_util_hexdigit[256]
Initial value:
=
{ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,
-1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, }

Definition at line 36 of file utilstrencodings.cpp.

Referenced by HexDigit().

◆ SAFE_CHARS

const string SAFE_CHARS[]
static
Initial value:
=
{
CHARS_ALPHA_NUM + " .,;-_/:?@()",
CHARS_ALPHA_NUM + " .,;-_?@"
}
static const string CHARS_ALPHA_NUM

Definition at line 19 of file utilstrencodings.cpp.

Referenced by SanitizeString().

◆ UPPER_BOUND

const int64_t UPPER_BOUND = 1000000000000000000LL - 1LL
static

Upper bound for mantissa. 10^18-1 is the largest arbitrary decimal that will fit in a signed 64-bit integer. Larger integers cannot consist of arbitrary combinations of 0-9:

999999999999999999 1^18-1 9223372036854775807 (1<<63)-1 (max int64_t) 9999999999999999999 1^19-1 (would overflow)

Definition at line 554 of file utilstrencodings.cpp.

Referenced by ParseFixedPoint(), and ProcessMantissaDigit().