Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
Gray::StrNum Struct Reference

#include <StrNum.h>

Static Public Member Functions

static StrLen_t __stdcall GetTrimCharsLen (const char *pStr, StrLen_t nLen, char ch)
 
static StrLen_t __stdcall GetNumberString (OUT char *pszOut, const wchar_t *pszInp, StrLen_t iStrMax=k_LEN_MAX_DIGITS)
 
static UINT64 __stdcall toUL (const char *pszInp, const char **ppszInpEnd=(const char **) nullptr, RADIX_t nBaseRadix=0)
 
static INT64 __stdcall toIL (const char *pszInp, const char **ppszInpEnd=(const char **) nullptr, RADIX_t nBaseRadix=10)
 
static UINT32 __stdcall toU (const char *pszInp, const char **ppszInpEnd=(const char **) nullptr, RADIX_t nBaseRadix=0)
 
static INT32 __stdcall toI (const char *pszInp, const char **ppszInpEnd=(const char **) nullptr, RADIX_t nBaseRadix=10)
 
static StrLen_t __stdcall ULtoAK (UINT64 uVal, OUT char *pszOut, StrLen_t iStrMax, UINT nKUnit, bool bSpace)
 
static char *__stdcall ULtoA2 (UINT64 uVal, OUT char *pszOut, StrLen_t iStrMax, RADIX_t nBaseRadix=10, char chRadixA='A')
 
static StrLen_t __stdcall ULtoA (UINT64 nVal, OUT char *pszOut, StrLen_t iStrMax, RADIX_t nBaseRadix=10)
 
static StrLen_t __stdcall ILtoA (INT64 nVal, OUT char *pszOut, StrLen_t iStrMax, RADIX_t nBaseRadix=10)
 
static StrLen_t __stdcall UtoA (UINT32 nVal, OUT char *pszOut, StrLen_t iStrMax, RADIX_t nBaseRadix=10)
 
static StrLen_t __stdcall ItoA (INT32 nVal, OUT char *pszOut, StrLen_t iStrMax, RADIX_t nBaseRadix=10)
 
static double __stdcall toDouble (const char *pszInp, const char **ppszInpEnd=(const char **) nullptr)
 
static StrLen_t __stdcall DtoAG2 (double dVal, OUT char *pszOut, int iDecPlacesWanted=-1, char chE=- 'e')
 
static StrLen_t __stdcall DtoAG (double dVal, OUT char *pszOut, StrLen_t iStrMax, int iDecPlacesWanted=-1, char chE=- 'e')
 
template<typename _TYPE >
static _TYPE toValue (const char *pszInp, const char **ppszInpEnd=(const char **) nullptr)
 
template<typename _TYPE >
static StrLen_t ValueToA (_TYPE val, OUT char *pszOut, StrLen_t iStrMax)
 
template<typename _TYPE >
static size_t __stdcall ToValArray (OUT _TYPE *pOut, size_t iQtyMax, const char *pszInp)
 
template<typename _TYPE >
static StrLen_t __stdcall ValArrayToA (OUT char *pszOut, StrLen_t nDstMax, const _TYPE *pSrc, size_t nSrcSize)
 
template<typename _TYPE >
static StrLen_t _cdecl ValArrayToAF (OUT char *pszDst, StrLen_t iSizeDstMax, size_t nSrcQty,...)
 
template<>
INT32 toValue (const char *pszInp, const char **ppszInpEnd)
 
template<>
UINT32 toValue (const char *pszInp, const char **ppszInpEnd)
 
template<>
INT64 toValue (const char *pszInp, const char **ppszInpEnd)
 
template<>
UINT64 toValue (const char *pszInp, const char **ppszInpEnd)
 
template<>
float toValue (const char *pszInp, const char **ppszInpEnd)
 
template<>
double toValue (const char *pszInp, const char **ppszInpEnd)
 
template<>
StrLen_t ValueToA (INT32 val, OUT char *pszOut, StrLen_t iStrMax)
 
template<>
StrLen_t ValueToA (UINT32 val, OUT char *pszOut, StrLen_t iStrMax)
 
template<>
StrLen_t ValueToA (INT64 val, OUT char *pszOut, StrLen_t iStrMax)
 
template<>
StrLen_t ValueToA (UINT64 val, OUT char *pszOut, StrLen_t iStrMax)
 
template<>
StrLen_t ValueToA (float val, OUT char *pszOut, StrLen_t iStrMax)
 
template<>
StrLen_t ValueToA (double val, OUT char *pszOut, StrLen_t iStrMax)
 

Static Public Attributes

static const StrLen_t k_LEN_MAX_DIGITS = (309 + 40)
 Largest number we can represent in double format + some extra places for post decimal. (). like _CVTBUFSIZE or StrT::k_LEN_MAX_KEY. More...
 
static const StrLen_t k_LEN_MAX_DIGITS_INT = 64
 Largest 64 bits base 2 not including sign or '\0' is only 64 digits. More...
 

Friends

class StrNumTests
 

Detailed Description

Convert ASCII (8 bit) string to/from numbers. Numbers are in a restricted set of ASCII (8 bit) characters. It doesn't make sense to have UTF8 and UNICODE versions of these. All actions are in 'char' type. Just convert to/from UNICODE as needed using StrU::UTF8toUNICODE and GetNumberString.

Member Function Documentation

◆ DtoAG()

StrLen_t GRAYCALL Gray::StrNum::DtoAG ( double  dVal,
OUT char *  pszOut,
StrLen_t  iStrMax,
int  iDecPlacesWanted = -1,
char  chE = -'e' 
)
static

◆ DtoAG2()

StrLen_t GRAYCALL Gray::StrNum::DtoAG2 ( double  dVal,
OUT char *  pszOut,
int  iDecPlacesWanted = -1,
char  chE = -'e' 
)
static

Make a string from a double float number. like _gcvt() or "%g" like dtoa(), gcvt(), fcvt(), ecvt(), _fcvt() and the opposite of toDouble(),

  • pszOut ASSUME size >= k_LEN_MAX_DIGITS iDecPlacesWanted = count of decimal places i desire. Number of digits after the decimal point. -1 = don't care. chE = 0=f,<0=g,>0=e
    Returns
    length of the string. pszOut = 'inf' or 'NaN' e.g. 123.449997 should equal "123.45" ?
    Note
    _WIN32 wsprintf() does NOT do floats of any sort!!! there is no UNICODE version of fcvt()
    g looks nice but can lose precision! Non reversible.

◆ GetNumberString()

StrLen_t GRAYCALL Gray::StrNum::GetNumberString ( OUT char *  pszOut,
const wchar_t *  pszInp,
StrLen_t  iStrMax = k_LEN_MAX_DIGITS 
)
static

Get a string in ASCII from UNICODE that represents a number. Only get numeric type chars. Like a simple version of StrU::UNICODEtoUTF8() and Opposite of StrU::UTF8toUNICODE()

Note
ASSUME pszOut[k_LEN_MAX_DIGITS]

◆ GetTrimCharsLen()

StrLen_t GRAYCALL Gray::StrNum::GetTrimCharsLen ( const char *  pStr,
StrLen_t  nLen,
char  ch 
)
static

Get Length of string if all ch chars are trimmed from the end.

◆ ILtoA()

StrLen_t GRAYCALL Gray::StrNum::ILtoA ( INT64  nVal,
OUT char *  pszOut,
StrLen_t  iStrMax,
RADIX_t  nBaseRadix = 10 
)
static

Make a string from a number. like ltoa(). upper case radix default.

  • iStrMax = _countof(Dst) = includes room for '\0'. (just like memcpy)
    Returns
    length of the string.

◆ ItoA()

static StrLen_t __stdcall Gray::StrNum::ItoA ( INT32  nVal,
OUT char *  pszOut,
StrLen_t  iStrMax,
RADIX_t  nBaseRadix = 10 
)
inlinestatic

Just cast up to 64.

◆ toDouble()

double GRAYCALL Gray::StrNum::toDouble ( const char *  pszInp,
const char **  ppszInpEnd = (const char**) nullptr 
)
static

Convert a string to a double precision decimal value. MUST emulate/match the C compiler. The C++ compiler will generate a double value from a string in code. MUST be reversible using DtoA(). like atof(), wcstod() or strtod() and opposite of DtoA(), dtoa() don't bother with toFloat() since it will do the same thing. e.g. decode stuff in format. "12.2", ".12", "123e234",

http://www.cplusplus.com/reference/cstdlib/strtod/ see http://www.exploringbinary.com/how-strtod-works-and-sometimes-doesnt/ for why this is dangerous/difficult. http://www.opensource.apple.com/source/tcl/tcl-10/tcl/compat/strtod.c It can have rounding problems? e.g. "3.1416" = 3.1415999999999999. Deal with this issue on conversion to string. http://www.ampl.com/netlib/fp/dtoa.c (David Gay)

◆ toI()

static INT32 __stdcall Gray::StrNum::toI ( const char *  pszInp,
const char **  ppszInpEnd = (const char**)nullptr,
RADIX_t  nBaseRadix = 10 
)
inlinestatic

Just cast down from 64.

◆ toIL()

INT64 GRAYCALL Gray::StrNum::toIL ( const char *  pszInp,
const char **  ppszInpEnd = (const char**)nullptr,
RADIX_t  nBaseRadix = 10 
)
static

convert string to integer value. like strtol(), or a bit like atoi() May have 0x# prefix to indicate hex

◆ toU()

static UINT32 __stdcall Gray::StrNum::toU ( const char *  pszInp,
const char **  ppszInpEnd = (const char**)nullptr,
RADIX_t  nBaseRadix = 0 
)
inlinestatic

Just cast down from 64.

◆ toUL()

UINT64 GRAYCALL Gray::StrNum::toUL ( const char *  pszInp,
const char **  ppszInpEnd = (const char**)nullptr,
RADIX_t  nBaseRadix = 0 
)
static

Similar to ::strtoul(). skip leading spaces. BUT NOT newlines. We should use StrNum::GetNumberString ? May have 0x# prefix to indicate hex

  • nBaseRadix = Radix, 0 = default to 10 and allow the string to override this. '0x' prefix will override. ppszInpEnd = the non number digit at the end . might be '\0';
    Note
    TYPE* ppszInpEnd; return( ::strtol( pszInp, &ppszInpEnd, nBaseRadix ));

    X digits is an overflow ?

◆ ToValArray()

template<typename _TYPE >
size_t __stdcall Gray::StrNum::ToValArray ( OUT _TYPE *  pOut,
size_t  iQtyMax,
const char *  pszInp 
)
static

◆ toValue() [1/7]

template<>
INT32 Gray::StrNum::toValue ( const char *  pszInp,
const char **  ppszInpEnd 
)
inlinestatic

◆ toValue() [2/7]

template<>
UINT32 Gray::StrNum::toValue ( const char *  pszInp,
const char **  ppszInpEnd 
)
inlinestatic

◆ toValue() [3/7]

template<>
INT64 Gray::StrNum::toValue ( const char *  pszInp,
const char **  ppszInpEnd 
)
inlinestatic

◆ toValue() [4/7]

template<>
UINT64 Gray::StrNum::toValue ( const char *  pszInp,
const char **  ppszInpEnd 
)
inlinestatic

◆ toValue() [5/7]

template<>
float Gray::StrNum::toValue ( const char *  pszInp,
const char **  ppszInpEnd 
)
inlinestatic

◆ toValue() [6/7]

template<>
double Gray::StrNum::toValue ( const char *  pszInp,
const char **  ppszInpEnd 
)
inlinestatic

◆ toValue() [7/7]

template<typename _TYPE >
static _TYPE Gray::StrNum::toValue ( const char *  pszInp,
const char **  ppszInpEnd = (const char **) nullptr 
)
inlinestatic

◆ ULtoA()

StrLen_t GRAYCALL Gray::StrNum::ULtoA ( UINT64  nVal,
OUT char *  pszOut,
StrLen_t  iStrMax,
RADIX_t  nBaseRadix = 10 
)
static

Format a number as a string similar to sprintf("%u") upper case radix default. like _itoa(iValue,pszOut,iRadix), FromInteger() and RtlIntegerToUnicodeString() or _itoa_s() Leading zero on hex string. (if room)

  • nBaseRadix = 10 default iStrMax = _CVTBUFSIZE = _countof(Dst) = includes room for '\0'. (just like memcpy)
    Returns
    length of the string.

◆ ULtoA2()

char *GRAYCALL Gray::StrNum::ULtoA2 ( UINT64  uVal,
OUT char *  pszOut,
StrLen_t  iStrMax,
RADIX_t  nBaseRadix = 10,
char  chRadixA = 'A' 
)
static

Internal function to format a number BACKWARDS as a string similar to sprintf("%u") padded from right. Padded from right. No lead padding. upper case radix default.

  • iStrMax must include space for null.
    Returns
    First digit (most significant)

◆ ULtoAK()

StrLen_t GRAYCALL Gray::StrNum::ULtoAK ( UINT64  uVal,
OUT char *  pszOut,
StrLen_t  iStrMax,
UINT  nKUnit,
bool  bSpace 
)
static

Make string describing a value in K/M/G/T/P/E/Z/Y units. (Kilo,Mega,Giga,Tera,Peta,Exa,Zetta,Yotta)

◆ UtoA()

static StrLen_t __stdcall Gray::StrNum::UtoA ( UINT32  nVal,
OUT char *  pszOut,
StrLen_t  iStrMax,
RADIX_t  nBaseRadix = 10 
)
inlinestatic

Just cast up to 64.

◆ ValArrayToA()

template<typename _TYPE >
StrLen_t __stdcall Gray::StrNum::ValArrayToA ( OUT char *  pszOut,
StrLen_t  nDstMax,
const _TYPE *  pSrc,
size_t  nSrcSize 
)
static
Todo:
Merge with cMem::ConvertToString Write bytes out to a string as comma separated base 10 number values. Try to use SetHexDigest() instead. opposite of cMem::ReadFromString().
Returns
the actual size of the string.
Note
using Base64 would be better.

◆ ValArrayToAF()

template<typename _TYPE >
StrLen_t _cdecl Gray::StrNum::ValArrayToAF ( OUT char *  pszDst,
StrLen_t  iSizeDstMax,
size_t  nSrcQty,
  ... 
)
static
Todo:
ValArrayToAF

◆ ValueToA() [1/7]

template<typename _TYPE >
static StrLen_t Gray::StrNum::ValueToA ( _TYPE  val,
OUT char *  pszOut,
StrLen_t  iStrMax 
)
inlinestatic

◆ ValueToA() [2/7]

template<>
StrLen_t Gray::StrNum::ValueToA ( double  val,
OUT char *  pszOut,
StrLen_t  iStrMax 
)
inlinestatic

◆ ValueToA() [3/7]

template<>
StrLen_t Gray::StrNum::ValueToA ( float  val,
OUT char *  pszOut,
StrLen_t  iStrMax 
)
inlinestatic

◆ ValueToA() [4/7]

template<>
StrLen_t Gray::StrNum::ValueToA ( INT32  val,
OUT char *  pszOut,
StrLen_t  iStrMax 
)
inlinestatic

◆ ValueToA() [5/7]

template<>
StrLen_t Gray::StrNum::ValueToA ( INT64  val,
OUT char *  pszOut,
StrLen_t  iStrMax 
)
inlinestatic

◆ ValueToA() [6/7]

template<>
StrLen_t Gray::StrNum::ValueToA ( UINT32  val,
OUT char *  pszOut,
StrLen_t  iStrMax 
)
inlinestatic

◆ ValueToA() [7/7]

template<>
StrLen_t Gray::StrNum::ValueToA ( UINT64  val,
OUT char *  pszOut,
StrLen_t  iStrMax 
)
inlinestatic

Friends And Related Function Documentation

◆ StrNumTests

friend class StrNumTests
friend

Member Data Documentation

◆ k_LEN_MAX_DIGITS

const StrLen_t Gray::StrNum::k_LEN_MAX_DIGITS = (309 + 40)
static

Largest number we can represent in double format + some extra places for post decimal. (). like _CVTBUFSIZE or StrT::k_LEN_MAX_KEY.

◆ k_LEN_MAX_DIGITS_INT

const StrLen_t Gray::StrNum::k_LEN_MAX_DIGITS_INT = 64
static

Largest 64 bits base 2 not including sign or '\0' is only 64 digits.


The documentation for this struct was generated from the following files: