Browse Source

added long long equivalents to several int conversion functions.

release/0.19
JustinAJ 10 years ago
parent
commit
9bff3fa82c
  1. 161
      Jupiter/Functions.c
  2. 8
      Jupiter/Functions.h
  3. 2
      Jupiter/Readable_String.h
  4. 20
      Jupiter/Readable_String_Imp.h
  5. BIN
      Release/Jupiter.lib

161
Jupiter/Functions.c

@ -598,12 +598,24 @@ int Jupiter_strtoi(const char *str, int base)
return Jupiter_strtoi_nospace(str, base);
}
long long Jupiter_strtoll(const char *str, int base)
{
while (isspace(*str)) str++;
return Jupiter_strtoll_nospace(str, base);
}
unsigned int Jupiter_strtoui(const char *str, int base)
{
while (isspace(*str)) str++;
return Jupiter_strtoui_nospace(str, base);
}
unsigned long long Jupiter_strtoull(const char *str, int base)
{
while (isspace(*str)) str++;
return Jupiter_strtoull_nospace(str, base);
}
double Jupiter_strtod(const char *str)
{
while (isspace(*str)) str++;
@ -616,6 +628,12 @@ int Jupiter_strtoi_nospace(const char *str, int base)
return -1 * Jupiter_strtoui_nospace(++str, base);
}
long long Jupiter_strtoll_nospace(const char *str, int base)
{
if (*str != '-') return Jupiter_strtoull_nospace(str, base);
return -1 * Jupiter_strtoull_nospace(++str, base);
}
unsigned int Jupiter_strtoui_nospace(const char *str, int base)
{
unsigned int total = 0;
@ -666,6 +684,56 @@ unsigned int Jupiter_strtoui_nospace(const char *str, int base)
return total;
}
unsigned long long Jupiter_strtoull_nospace(const char *str, int base)
{
unsigned long long total = 0;
int tval;
if (*str == '-') return Jupiter_strtoi_nospace(str, base);
if (*str == '+') str++;
if (base == 0) // Guess a base.
{
if (*str == '0')
{
str++;
switch (*str)
{
case 'X':
case 'x':
str++;
base = 16;
break;
case 'B':
case 'b':
str++;
base = 2;
break;
default:
base = 8;
break;
}
}
else base = 10;
}
else if (base == 16) // check for optional preceeding hexadecimal prefix.
{
if (*str == '0')
{
str++;
if (*str == 'x' || *str == 'X') str++;
}
}
while ((tval = Jupiter_getBase(*str, base)) != -1)
{
total = base * total + tval;
str++;
}
return total;
}
double Jupiter_strtod_nospace(const char *str)
{
const int base = 10;
@ -711,6 +779,16 @@ int Jupiter_strtoi_s(const char *str, size_t length, int base)
return Jupiter_strtoi_nospace_s(str, length, base);
}
long long Jupiter_strtoll_s(const char *str, size_t length, int base)
{
while (length != 0 && isspace(*str))
{
str++;
length--;
}
return Jupiter_strtoll_nospace_s(str, length, base);
}
unsigned int Jupiter_strtoui_s(const char *str, size_t length, int base)
{
while (length != 0 && isspace(*str))
@ -721,6 +799,16 @@ unsigned int Jupiter_strtoui_s(const char *str, size_t length, int base)
return Jupiter_strtoui_nospace_s(str, length, base);
}
unsigned long long Jupiter_strtoull_s(const char *str, size_t length, int base)
{
while (length != 0 && isspace(*str))
{
str++;
length--;
}
return Jupiter_strtoull_nospace_s(str, length, base);
}
double Jupiter_strtod_s(const char *str, size_t length)
{
while (length != 0 && isspace(*str))
@ -731,7 +819,7 @@ double Jupiter_strtod_s(const char *str, size_t length)
return Jupiter_strtod_nospace_s(str, length);
}
signed int Jupiter_strtoi_nospace_s(const char *str, size_t length, int base)
int Jupiter_strtoi_nospace_s(const char *str, size_t length, int base)
{
if (length == 0) return 0;
if (*str != '-') return Jupiter_strtoui_nospace_s(str, length, base);
@ -802,6 +890,77 @@ unsigned int Jupiter_strtoui_nospace_s(const char *str, size_t length, int base)
return total;
}
long long Jupiter_strtoll_nospace_s(const char *str, size_t length, int base)
{
if (length == 0) return 0;
if (*str != '-') return Jupiter_strtoull_nospace_s(str, length, base);
return -1 * Jupiter_strtoull_nospace_s(++str, --length, base);
}
unsigned long long Jupiter_strtoull_nospace_s(const char *str, size_t length, int base)
{
unsigned long long total = 0;
int tval;
if (length == 0) return total;
if (*str == '-') return Jupiter_strtoi_nospace(str, base);
if (*str == '+')
{
if (--length == 0) return total;
str++;
}
if (base == 0) // Guess a base.
{
if (*str == '0')
{
if (--length == 0) return total;
str++;
switch (*str)
{
case 'X':
case 'x':
if (--length == 0) return total;
str++;
base = 16;
break;
case 'B':
case 'b':
if (--length == 0) return total;
str++;
base = 2;
break;
default:
base = 8;
break;
}
}
else base = 10;
}
else if (base == 16) // check for optional preceeding hexadecimal prefix.
{
if (*str == '0')
{
if (--length == 0) return total;
str++;
if (*str == 'x' || *str == 'X')
{
if (--length == 0) return total;
str++;
}
}
}
while ((tval = Jupiter_getBase(*str, base)) != -1)
{
total = base * total + tval;
if (--length == 0) return total;
str++;
}
return total;
}
double Jupiter_strtod_nospace_s(const char *str, size_t length)
{
const int base = 10;

8
Jupiter/Functions.h

@ -355,7 +355,9 @@ JUPITER_API int Jupiter_getBase(unsigned char c, int base);
* @return Interpretation of the string as an integer on success, 0 otherwise.
*/
JUPITER_API int Jupiter_strtoi(const char *str, int base);
JUPITER_API long long Jupiter_strtoll(const char *str, int base);
JUPITER_API unsigned int Jupiter_strtoui(const char *str, int base);
JUPITER_API unsigned long long Jupiter_strtoull(const char *str, int base);
/**
* @brief Interpets a string into a floating point decimal number.
@ -375,7 +377,9 @@ JUPITER_API double Jupiter_strtod(const char *str);
* @return Interpretation of the string as an integer on success, 0 otherwise.
*/
JUPITER_API int Jupiter_strtoi_nospace(const char *str, int base);
JUPITER_API long long Jupiter_strtoll_nospace(const char *str, int base);
JUPITER_API unsigned int Jupiter_strtoui_nospace(const char *str, int base);
JUPITER_API unsigned long long Jupiter_strtoull_nospace(const char *str, int base);
/**
* @brief Interpets a string into a floating point decimal number.
@ -396,7 +400,9 @@ JUPITER_API double Jupiter_strtod_nospace(const char *str);
* @return Interpretation of the string as an integer on success, 0 otherwise.
*/
JUPITER_API int Jupiter_strtoi_s(const char *str, size_t length, int base);
JUPITER_API long long Jupiter_strtoll_s(const char *str, size_t length, int base);
JUPITER_API unsigned int Jupiter_strtoui_s(const char *str, size_t length, int base);
JUPITER_API unsigned long long Jupiter_strtoull_s(const char *str, size_t length, int base);
/**
* @brief Interpets a string into a floating point decimal number.
@ -417,7 +423,9 @@ JUPITER_API double Jupiter_strtod_s(const char *str, size_t length);
* @return Interpretation of the string as an integer on success, 0 otherwise.
*/
JUPITER_API int Jupiter_strtoi_nospace_s(const char *str, size_t length, int base);
JUPITER_API long long Jupiter_strtoll_nospace_s(const char *str, size_t length, int base);
JUPITER_API unsigned int Jupiter_strtoui_nospace_s(const char *str, size_t length, int base);
JUPITER_API unsigned long long Jupiter_strtoull_nospace_s(const char *str, size_t length, int base);
/**
* @brief Interpets a string into a floating point decimal number.

2
Jupiter/Readable_String.h

@ -204,7 +204,9 @@ namespace Jupiter
* @return Integer representation of the string.
*/
int asInt(int base = 0) const;
long long asLongLong(int base = 0) const;
unsigned int asUnsignedInt(int base = 0) const;
unsigned long long asUnsignedLongLong(int base = 0) const;
/**
* @brief Interprets the string as a floating-point decimal number.

20
Jupiter/Readable_String_Imp.h

@ -878,6 +878,16 @@ template<typename T> int Jupiter::Readable_String<T>::asInt(int base) const
return 0;
}
template<> long long inline Jupiter::Readable_String<char>::asLongLong(int base) const
{
return Jupiter_strtoll_s(this->ptr(), this->size(), base);
}
template<typename T> long long Jupiter::Readable_String<T>::asLongLong(int base) const
{
return 0;
}
template<> unsigned int inline Jupiter::Readable_String<char>::asUnsignedInt(int base) const
{
return Jupiter_strtoui_s(this->ptr(), this->size(), base);
@ -888,6 +898,16 @@ template<typename T> unsigned int Jupiter::Readable_String<T>::asUnsignedInt(int
return 0;
}
template<> unsigned long long inline Jupiter::Readable_String<char>::asUnsignedLongLong(int base) const
{
return Jupiter_strtoull_s(this->ptr(), this->size(), base);
}
template<typename T> unsigned long long Jupiter::Readable_String<T>::asUnsignedLongLong(int base) const
{
return 0;
}
template<> double inline Jupiter::Readable_String<char>::asDouble() const
{
return Jupiter_strtod_s(this->ptr(), this->size());

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save