Rename & reorder readed bytes arg in string funcs
This commit is contained in:
@@ -239,11 +239,11 @@ If successful, it returns 0 or an error code.
|
|||||||
=head2 BH_StringToDouble
|
=head2 BH_StringToDouble
|
||||||
|
|
||||||
double BH_StringToDouble(const char *string,
|
double BH_StringToDouble(const char *string,
|
||||||
size_t *size);
|
size_t *actual);
|
||||||
|
|
||||||
Converts the string I<string> to a real number.
|
Converts the string I<string> to a real number.
|
||||||
|
|
||||||
The optional parameter I<size> returns the number of characters read from the
|
The optional parameter I<actual> returns the number of characters read from the
|
||||||
string.
|
string.
|
||||||
|
|
||||||
If successful, it returns the converted number or 0.
|
If successful, it returns the converted number or 0.
|
||||||
@@ -252,128 +252,128 @@ If successful, it returns the converted number or 0.
|
|||||||
=head2 BH_StringToInt8s
|
=head2 BH_StringToInt8s
|
||||||
|
|
||||||
int8_t BH_StringToInt8s(const char *string,
|
int8_t BH_StringToInt8s(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
Converts the string I<string> to an 8-bit signed integer.
|
Converts the string I<string> to an 8-bit signed integer.
|
||||||
|
|
||||||
The optional parameter I<size> returns the number of characters read from the
|
|
||||||
string.
|
|
||||||
|
|
||||||
The optional parameter I<base> specifies the base of the number.
|
The optional parameter I<base> specifies the base of the number.
|
||||||
|
|
||||||
|
The optional parameter I<actual> returns the number of characters read from the
|
||||||
|
string.
|
||||||
|
|
||||||
If successful, it returns the converted number or 0.
|
If successful, it returns the converted number or 0.
|
||||||
|
|
||||||
|
|
||||||
=head2 BH_StringToInt16s
|
=head2 BH_StringToInt16s
|
||||||
|
|
||||||
int16_t BH_StringToInt16s(const char *string,
|
int16_t BH_StringToInt16s(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
Converts the string I<string> to a signed 16-bit integer.
|
Converts the string I<string> to a signed 16-bit integer.
|
||||||
|
|
||||||
The optional parameter I<size> returns the number of characters read from the
|
|
||||||
string.
|
|
||||||
|
|
||||||
The optional parameter I<base> specifies the base of the number.
|
The optional parameter I<base> specifies the base of the number.
|
||||||
|
|
||||||
|
The optional parameter I<actual> returns the number of characters read from the
|
||||||
|
string.
|
||||||
|
|
||||||
If successful, it returns the converted number or 0.
|
If successful, it returns the converted number or 0.
|
||||||
|
|
||||||
|
|
||||||
=head2 BH_StringToInt32s
|
=head2 BH_StringToInt32s
|
||||||
|
|
||||||
int32_t BH_StringToInt32s(const char *string,
|
int32_t BH_StringToInt32s(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
Converts the string I<string> to a signed 32-bit integer.
|
Converts the string I<string> to a signed 32-bit integer.
|
||||||
|
|
||||||
The optional parameter I<size> returns the number of characters read from the
|
|
||||||
string.
|
|
||||||
|
|
||||||
The optional parameter I<base> specifies the base of the number.
|
The optional parameter I<base> specifies the base of the number.
|
||||||
|
|
||||||
|
The optional parameter I<actual> returns the number of characters read from the
|
||||||
|
string.
|
||||||
|
|
||||||
If successful, it returns the converted number or 0.
|
If successful, it returns the converted number or 0.
|
||||||
|
|
||||||
|
|
||||||
=head2 BH_StringToInt64s
|
=head2 BH_StringToInt64s
|
||||||
|
|
||||||
int64_t BH_StringToInt64s(const char *string,
|
int64_t BH_StringToInt64s(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
Converts the string I<string> to a signed 64-bit integer.
|
Converts the string I<string> to a signed 64-bit integer.
|
||||||
|
|
||||||
The optional parameter I<size> returns the number of characters read from the
|
|
||||||
string.
|
|
||||||
|
|
||||||
The optional parameter I<base> specifies the base of the number.
|
The optional parameter I<base> specifies the base of the number.
|
||||||
|
|
||||||
|
The optional parameter I<actual> returns the number of characters read from the
|
||||||
|
string.
|
||||||
|
|
||||||
If successful, it returns the converted number or 0.
|
If successful, it returns the converted number or 0.
|
||||||
|
|
||||||
|
|
||||||
=head2 BH_StringToInt8u
|
=head2 BH_StringToInt8u
|
||||||
|
|
||||||
uint8_t BH_StringToInt8u(const char *string,
|
uint8_t BH_StringToInt8u(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
Converts the string I<string> to an unsigned 8-bit integer.
|
Converts the string I<string> to an unsigned 8-bit integer.
|
||||||
|
|
||||||
The optional parameter I<size> returns the number of characters read from the
|
|
||||||
string.
|
|
||||||
|
|
||||||
The optional parameter I<base> specifies the base of the number.
|
The optional parameter I<base> specifies the base of the number.
|
||||||
|
|
||||||
|
The optional parameter I<actual> returns the number of characters read from the
|
||||||
|
string.
|
||||||
|
|
||||||
If successful, it returns the converted number or 0.
|
If successful, it returns the converted number or 0.
|
||||||
|
|
||||||
|
|
||||||
=head2 BH_StringToInt16u
|
=head2 BH_StringToInt16u
|
||||||
|
|
||||||
uint16_t BH_StringToInt16u(const char *string,
|
uint16_t BH_StringToInt16u(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
Converts the string I<string> to an unsigned 16-bit integer.
|
Converts the string I<string> to an unsigned 16-bit integer.
|
||||||
|
|
||||||
The optional parameter I<size> returns the number of characters read from the
|
|
||||||
string.
|
|
||||||
|
|
||||||
The optional parameter I<base> specifies the base of the number.
|
The optional parameter I<base> specifies the base of the number.
|
||||||
|
|
||||||
|
The optional parameter I<actual> returns the number of characters read from the
|
||||||
|
string.
|
||||||
|
|
||||||
If successful, it returns the converted number or 0.
|
If successful, it returns the converted number or 0.
|
||||||
|
|
||||||
|
|
||||||
=head2 BH_StringToInt32u
|
=head2 BH_StringToInt32u
|
||||||
|
|
||||||
uint32_t BH_StringToInt32u(const char *string,
|
uint32_t BH_StringToInt32u(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
Converts the string I<string> to an unsigned 32-bit integer.
|
Converts the string I<string> to an unsigned 32-bit integer.
|
||||||
|
|
||||||
The optional parameter I<size> returns the number of characters read from the
|
|
||||||
string.
|
|
||||||
|
|
||||||
The optional parameter I<base> specifies the base of the number.
|
The optional parameter I<base> specifies the base of the number.
|
||||||
|
|
||||||
|
The optional parameter I<actual> returns the number of characters read from the
|
||||||
|
string.
|
||||||
|
|
||||||
If successful, it returns the converted number or 0.
|
If successful, it returns the converted number or 0.
|
||||||
|
|
||||||
|
|
||||||
=head2 BH_StringToInt64u
|
=head2 BH_StringToInt64u
|
||||||
|
|
||||||
uint64_t BH_StringToInt64u(const char *string,
|
uint64_t BH_StringToInt64u(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
Converts the string I<string> to an unsigned 64-bit integer.
|
Converts the string I<string> to an unsigned 64-bit integer.
|
||||||
|
|
||||||
The optional parameter I<size> returns the number of characters read from the
|
|
||||||
string.
|
|
||||||
|
|
||||||
The optional parameter I<base> specifies the base of the number.
|
The optional parameter I<base> specifies the base of the number.
|
||||||
|
|
||||||
|
The optional parameter I<actual> returns the number of characters read from the
|
||||||
|
string.
|
||||||
|
|
||||||
If successful, it returns the converted number or 0.
|
If successful, it returns the converted number or 0.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ I<string> (с ограничением по длинне I<size>).
|
|||||||
|
|
||||||
Преобразовывает строку I<string> в вещественное число.
|
Преобразовывает строку I<string> в вещественное число.
|
||||||
|
|
||||||
Опциональный параметр I<size> возвращает число прочитанных символов из строки.
|
Опциональный параметр I<actual> возвращает число прочитанных символов из строки.
|
||||||
|
|
||||||
В случае успеха, возвращает преобразованное число или 0.
|
В случае успеха, возвращает преобразованное число или 0.
|
||||||
|
|
||||||
@@ -251,120 +251,120 @@ I<string> (с ограничением по длинне I<size>).
|
|||||||
=head2 BH_StringToInt8s
|
=head2 BH_StringToInt8s
|
||||||
|
|
||||||
int8_t BH_StringToInt8s(const char *string,
|
int8_t BH_StringToInt8s(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
Преобразовывает строку I<string> в целое знаковое 8-битное число.
|
Преобразовывает строку I<string> в целое знаковое 8-битное число.
|
||||||
|
|
||||||
Опциональный параметр I<size> возвращает число прочитанных символов из строки.
|
|
||||||
|
|
||||||
Опциональный параметр I<base> задает основание числа.
|
Опциональный параметр I<base> задает основание числа.
|
||||||
|
|
||||||
|
Опциональный параметр I<actual> возвращает число прочитанных символов из строки.
|
||||||
|
|
||||||
В случае успеха, возвращает преобразованное число или 0.
|
В случае успеха, возвращает преобразованное число или 0.
|
||||||
|
|
||||||
|
|
||||||
=head2 BH_StringToInt16s
|
=head2 BH_StringToInt16s
|
||||||
|
|
||||||
int16_t BH_StringToInt16s(const char *string,
|
int16_t BH_StringToInt16s(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
Преобразовывает строку I<string> в целое знаковое 16-битное число.
|
Преобразовывает строку I<string> в целое знаковое 16-битное число.
|
||||||
|
|
||||||
Опциональный параметр I<size> возвращает число прочитанных символов из строки.
|
|
||||||
|
|
||||||
Опциональный параметр I<base> задает основание числа.
|
Опциональный параметр I<base> задает основание числа.
|
||||||
|
|
||||||
|
Опциональный параметр I<actual> возвращает число прочитанных символов из строки.
|
||||||
|
|
||||||
В случае успеха, возвращает преобразованное число или 0.
|
В случае успеха, возвращает преобразованное число или 0.
|
||||||
|
|
||||||
|
|
||||||
=head2 BH_StringToInt32s
|
=head2 BH_StringToInt32s
|
||||||
|
|
||||||
int32_t BH_StringToInt32s(const char *string,
|
int32_t BH_StringToInt32s(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
Преобразовывает строку I<string> в целое знаковое 32-битное число.
|
Преобразовывает строку I<string> в целое знаковое 32-битное число.
|
||||||
|
|
||||||
Опциональный параметр I<size> возвращает число прочитанных символов из строки.
|
|
||||||
|
|
||||||
Опциональный параметр I<base> задает основание числа.
|
Опциональный параметр I<base> задает основание числа.
|
||||||
|
|
||||||
|
Опциональный параметр I<actual> возвращает число прочитанных символов из строки.
|
||||||
|
|
||||||
В случае успеха, возвращает преобразованное число или 0.
|
В случае успеха, возвращает преобразованное число или 0.
|
||||||
|
|
||||||
|
|
||||||
=head2 BH_StringToInt64s
|
=head2 BH_StringToInt64s
|
||||||
|
|
||||||
int64_t BH_StringToInt64s(const char *string,
|
int64_t BH_StringToInt64s(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
Преобразовывает строку I<string> в целое знаковое 64-битное число.
|
Преобразовывает строку I<string> в целое знаковое 64-битное число.
|
||||||
|
|
||||||
Опциональный параметр I<size> возвращает число прочитанных символов из строки.
|
|
||||||
|
|
||||||
Опциональный параметр I<base> задает основание числа.
|
Опциональный параметр I<base> задает основание числа.
|
||||||
|
|
||||||
|
Опциональный параметр I<actual> возвращает число прочитанных символов из строки.
|
||||||
|
|
||||||
В случае успеха, возвращает преобразованное число или 0.
|
В случае успеха, возвращает преобразованное число или 0.
|
||||||
|
|
||||||
|
|
||||||
=head2 BH_StringToInt8u
|
=head2 BH_StringToInt8u
|
||||||
|
|
||||||
uint8_t BH_StringToInt8u(const char *string,
|
uint8_t BH_StringToInt8u(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
Преобразовывает строку I<string> в целое беззнаковое 8-битное число.
|
Преобразовывает строку I<string> в целое беззнаковое 8-битное число.
|
||||||
|
|
||||||
Опциональный параметр I<size> возвращает число прочитанных символов из строки.
|
|
||||||
|
|
||||||
Опциональный параметр I<base> задает основание числа.
|
Опциональный параметр I<base> задает основание числа.
|
||||||
|
|
||||||
|
Опциональный параметр I<actual> возвращает число прочитанных символов из строки.
|
||||||
|
|
||||||
В случае успеха, возвращает преобразованное число или 0.
|
В случае успеха, возвращает преобразованное число или 0.
|
||||||
|
|
||||||
|
|
||||||
=head2 BH_StringToInt16u
|
=head2 BH_StringToInt16u
|
||||||
|
|
||||||
uint16_t BH_StringToInt16u(const char *string,
|
uint16_t BH_StringToInt16u(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
Преобразовывает строку I<string> в целое беззнаковое 16-битное число.
|
Преобразовывает строку I<string> в целое беззнаковое 16-битное число.
|
||||||
|
|
||||||
Опциональный параметр I<size> возвращает число прочитанных символов из строки.
|
|
||||||
|
|
||||||
Опциональный параметр I<base> задает основание числа.
|
Опциональный параметр I<base> задает основание числа.
|
||||||
|
|
||||||
|
Опциональный параметр I<actual> возвращает число прочитанных символов из строки.
|
||||||
|
|
||||||
В случае успеха, возвращает преобразованное число или 0.
|
В случае успеха, возвращает преобразованное число или 0.
|
||||||
|
|
||||||
|
|
||||||
=head2 BH_StringToInt32u
|
=head2 BH_StringToInt32u
|
||||||
|
|
||||||
uint32_t BH_StringToInt32u(const char *string,
|
uint32_t BH_StringToInt32u(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
Преобразовывает строку I<string> в целое беззнаковое 32-битное число.
|
Преобразовывает строку I<string> в целое беззнаковое 32-битное число.
|
||||||
|
|
||||||
Опциональный параметр I<size> возвращает число прочитанных символов из строки.
|
|
||||||
|
|
||||||
Опциональный параметр I<base> задает основание числа.
|
Опциональный параметр I<base> задает основание числа.
|
||||||
|
|
||||||
|
Опциональный параметр I<actual> возвращает число прочитанных символов из строки.
|
||||||
|
|
||||||
В случае успеха, возвращает преобразованное число или 0.
|
В случае успеха, возвращает преобразованное число или 0.
|
||||||
|
|
||||||
|
|
||||||
=head2 BH_StringToInt64u
|
=head2 BH_StringToInt64u
|
||||||
|
|
||||||
uint64_t BH_StringToInt64u(const char *string,
|
uint64_t BH_StringToInt64u(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
Преобразовывает строку I<string> в целое беззнаковое 64-битное число.
|
Преобразовывает строку I<string> в целое беззнаковое 64-битное число.
|
||||||
|
|
||||||
Опциональный параметр I<size> возвращает число прочитанных символов из строки.
|
|
||||||
|
|
||||||
Опциональный параметр I<base> задает основание числа.
|
Опциональный параметр I<base> задает основание числа.
|
||||||
|
|
||||||
|
Опциональный параметр I<actual> возвращает число прочитанных символов из строки.
|
||||||
|
|
||||||
В случае успеха, возвращает преобразованное число или 0.
|
В случае успеха, возвращает преобразованное число или 0.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
76
include/BH/Ini.h
Normal file
76
include/BH/Ini.h
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
#ifndef BH_INI_H
|
||||||
|
#define BH_INI_H
|
||||||
|
|
||||||
|
#include "IO.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct BH_Ini BH_Ini;
|
||||||
|
|
||||||
|
BH_Ini *BH_IniNew(void);
|
||||||
|
|
||||||
|
|
||||||
|
void BH_IniFree(BH_Ini *ini);
|
||||||
|
|
||||||
|
|
||||||
|
int BH_IniLoad(BH_Ini *ini,
|
||||||
|
BH_IO *io);
|
||||||
|
|
||||||
|
|
||||||
|
int BH_IniSave(BH_Ini *ini,
|
||||||
|
BH_IO *io);
|
||||||
|
|
||||||
|
|
||||||
|
int BH_IniSetString(BH_Ini *ini,
|
||||||
|
const char *section,
|
||||||
|
const char *key,
|
||||||
|
const char *value);
|
||||||
|
|
||||||
|
|
||||||
|
const char *BH_IniString(BH_Ini *ini,
|
||||||
|
const char *section,
|
||||||
|
const char *key);
|
||||||
|
|
||||||
|
|
||||||
|
void BH_IniRemoveSection(BH_Ini *ini,
|
||||||
|
const char *section);
|
||||||
|
|
||||||
|
|
||||||
|
void BH_IniRemoveKey(BH_Ini *ini,
|
||||||
|
const char *section,
|
||||||
|
const char *key);
|
||||||
|
|
||||||
|
|
||||||
|
void *BH_IniSectionIterNext(BH_Ini *ini,
|
||||||
|
void *iter);
|
||||||
|
|
||||||
|
|
||||||
|
void *BH_IniSectionIterAt(BH_Ini *ini,
|
||||||
|
const char *section);
|
||||||
|
|
||||||
|
|
||||||
|
const char *BH_IniSectionIterName(void *iter);
|
||||||
|
|
||||||
|
|
||||||
|
void BH_IniSectionIterRemove(BH_Ini *ini,
|
||||||
|
void *iter);
|
||||||
|
|
||||||
|
|
||||||
|
void *BH_IniKVIterNext(void *section,
|
||||||
|
void *iter);
|
||||||
|
|
||||||
|
|
||||||
|
void *BH_IniKVIterAt(void *section,
|
||||||
|
const char *key);
|
||||||
|
|
||||||
|
|
||||||
|
const char *BH_IniKVIterKey(void *iter);
|
||||||
|
|
||||||
|
|
||||||
|
const char *BH_IniKVIterValue(void *iter);
|
||||||
|
|
||||||
|
|
||||||
|
void BH_IniKVIterRemove(void *section,
|
||||||
|
void *iter);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BH_INI_H */
|
||||||
@@ -70,47 +70,47 @@ int BH_StringFromInt64u(char *string,
|
|||||||
|
|
||||||
|
|
||||||
double BH_StringToDouble(const char *string,
|
double BH_StringToDouble(const char *string,
|
||||||
size_t *size);
|
size_t *actual);
|
||||||
|
|
||||||
|
|
||||||
int8_t BH_StringToInt8s(const char *string,
|
int8_t BH_StringToInt8s(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
|
|
||||||
int16_t BH_StringToInt16s(const char *string,
|
int16_t BH_StringToInt16s(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
|
|
||||||
int32_t BH_StringToInt32s(const char *string,
|
int32_t BH_StringToInt32s(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
|
|
||||||
int64_t BH_StringToInt64s(const char *string,
|
int64_t BH_StringToInt64s(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
|
|
||||||
uint8_t BH_StringToInt8u(const char *string,
|
uint8_t BH_StringToInt8u(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
|
|
||||||
uint16_t BH_StringToInt16u(const char *string,
|
uint16_t BH_StringToInt16u(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
|
|
||||||
uint32_t BH_StringToInt32u(const char *string,
|
uint32_t BH_StringToInt32u(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
|
|
||||||
uint64_t BH_StringToInt64u(const char *string,
|
uint64_t BH_StringToInt64u(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base);
|
size_t *actual);
|
||||||
|
|
||||||
|
|
||||||
char *BH_StringDup(const char *string);
|
char *BH_StringDup(const char *string);
|
||||||
|
|||||||
@@ -515,11 +515,11 @@ static int caselessCompare(const char *src,
|
|||||||
|
|
||||||
|
|
||||||
static int parseFormat(const char *string,
|
static int parseFormat(const char *string,
|
||||||
size_t *size,
|
|
||||||
char *buffer,
|
char *buffer,
|
||||||
int *sign,
|
int *sign,
|
||||||
int *e,
|
int *e,
|
||||||
int *type)
|
int *type,
|
||||||
|
size_t *actual)
|
||||||
{
|
{
|
||||||
const char *current;
|
const char *current;
|
||||||
int esign, dot, count;
|
int esign, dot, count;
|
||||||
@@ -607,15 +607,15 @@ static int parseFormat(const char *string,
|
|||||||
*e -= dot;
|
*e -= dot;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (size)
|
if (actual)
|
||||||
*size = current - string;
|
*actual = current - string;
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
double BH_StringToDouble(const char *string,
|
double BH_StringToDouble(const char *string,
|
||||||
size_t *size)
|
size_t *actual)
|
||||||
{
|
{
|
||||||
int type, e, sign, i, count, shift;
|
int type, e, sign, i, count, shift;
|
||||||
Mpi r, s, tmp[5];
|
Mpi r, s, tmp[5];
|
||||||
@@ -627,7 +627,7 @@ double BH_StringToDouble(const char *string,
|
|||||||
assert(string != NULL);
|
assert(string != NULL);
|
||||||
|
|
||||||
/* Parse from string format */
|
/* Parse from string format */
|
||||||
count = parseFormat(string, size, buffer, &sign, &e, &type);
|
count = parseFormat(string, buffer, &sign, &e, &type, actual);
|
||||||
|
|
||||||
/* Handle special values */
|
/* Handle special values */
|
||||||
if (type == BH_FP_INFINITE)
|
if (type == BH_FP_INFINITE)
|
||||||
@@ -641,8 +641,8 @@ double BH_StringToDouble(const char *string,
|
|||||||
else if (type == BH_FP_ZERO)
|
else if (type == BH_FP_ZERO)
|
||||||
{
|
{
|
||||||
/* Hacky solution to indicate we haven't seen any digit */
|
/* Hacky solution to indicate we haven't seen any digit */
|
||||||
if (size)
|
if (actual)
|
||||||
*size = 0;
|
*actual = 0;
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,15 +3,15 @@ signed char sym;
|
|||||||
|
|
||||||
/* Check for valid base and zero out read size */
|
/* Check for valid base and zero out read size */
|
||||||
result = 0;
|
result = 0;
|
||||||
if (size)
|
if (actual)
|
||||||
*size = 0;
|
*actual = 0;
|
||||||
if (base != 0 && (base < 2 || base > 36))
|
if (base != 0 && (base < 2 || base > 36))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Handle space, sign and base */
|
/* Handle space, sign and base */
|
||||||
skipSpace(&string, size);
|
skipSpace(&string, actual);
|
||||||
handleSign(&string, size, &sign);
|
handleSign(&string, actual, &sign);
|
||||||
guessBase(&string, size, &base);
|
guessBase(&string, actual, &base);
|
||||||
|
|
||||||
/* Read digits */
|
/* Read digits */
|
||||||
while(*string)
|
while(*string)
|
||||||
@@ -21,14 +21,14 @@ while(*string)
|
|||||||
if (sym >= base || sym == -1)
|
if (sym >= base || sym == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (size)
|
if (actual)
|
||||||
(*size)++;
|
(*actual)++;
|
||||||
result = result * base + sym;
|
result = result * base + sym;
|
||||||
flag = 1;
|
flag = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Zero out size on error */
|
/* Zero out size on error */
|
||||||
if (!result && !flag && size)
|
if (!result && !flag && actual)
|
||||||
*size = 0;
|
*actual = 0;
|
||||||
|
|
||||||
return result * sign;
|
return result * sign;
|
||||||
|
|||||||
@@ -160,8 +160,8 @@ int BH_StringFromInt64u(char *string,
|
|||||||
|
|
||||||
|
|
||||||
int8_t BH_StringToInt8s(const char *string,
|
int8_t BH_StringToInt8s(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base)
|
size_t *actual)
|
||||||
{
|
{
|
||||||
int8_t result;
|
int8_t result;
|
||||||
#include "Inline/Int.h"
|
#include "Inline/Int.h"
|
||||||
@@ -169,8 +169,8 @@ int8_t BH_StringToInt8s(const char *string,
|
|||||||
|
|
||||||
|
|
||||||
int16_t BH_StringToInt16s(const char *string,
|
int16_t BH_StringToInt16s(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base)
|
size_t *actual)
|
||||||
{
|
{
|
||||||
int16_t result;
|
int16_t result;
|
||||||
#include "Inline/Int.h"
|
#include "Inline/Int.h"
|
||||||
@@ -178,8 +178,8 @@ int16_t BH_StringToInt16s(const char *string,
|
|||||||
|
|
||||||
|
|
||||||
int32_t BH_StringToInt32s(const char *string,
|
int32_t BH_StringToInt32s(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base)
|
size_t *actual)
|
||||||
{
|
{
|
||||||
int32_t result;
|
int32_t result;
|
||||||
#include "Inline/Int.h"
|
#include "Inline/Int.h"
|
||||||
@@ -187,8 +187,8 @@ int32_t BH_StringToInt32s(const char *string,
|
|||||||
|
|
||||||
|
|
||||||
int64_t BH_StringToInt64s(const char *string,
|
int64_t BH_StringToInt64s(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base)
|
size_t *actual)
|
||||||
{
|
{
|
||||||
int64_t result;
|
int64_t result;
|
||||||
#include "Inline/Int.h"
|
#include "Inline/Int.h"
|
||||||
@@ -196,8 +196,8 @@ int64_t BH_StringToInt64s(const char *string,
|
|||||||
|
|
||||||
|
|
||||||
uint8_t BH_StringToInt8u(const char *string,
|
uint8_t BH_StringToInt8u(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base)
|
size_t *actual)
|
||||||
{
|
{
|
||||||
uint8_t result;
|
uint8_t result;
|
||||||
#include "Inline/Int.h"
|
#include "Inline/Int.h"
|
||||||
@@ -205,8 +205,8 @@ uint8_t BH_StringToInt8u(const char *string,
|
|||||||
|
|
||||||
|
|
||||||
uint16_t BH_StringToInt16u(const char *string,
|
uint16_t BH_StringToInt16u(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base)
|
size_t *actual)
|
||||||
{
|
{
|
||||||
uint16_t result;
|
uint16_t result;
|
||||||
#include "Inline/Int.h"
|
#include "Inline/Int.h"
|
||||||
@@ -214,8 +214,8 @@ uint16_t BH_StringToInt16u(const char *string,
|
|||||||
|
|
||||||
|
|
||||||
uint32_t BH_StringToInt32u(const char *string,
|
uint32_t BH_StringToInt32u(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base)
|
size_t *actual)
|
||||||
{
|
{
|
||||||
uint32_t result;
|
uint32_t result;
|
||||||
#include "Inline/Int.h"
|
#include "Inline/Int.h"
|
||||||
@@ -223,8 +223,8 @@ uint32_t BH_StringToInt32u(const char *string,
|
|||||||
|
|
||||||
|
|
||||||
uint64_t BH_StringToInt64u(const char *string,
|
uint64_t BH_StringToInt64u(const char *string,
|
||||||
size_t *size,
|
int base,
|
||||||
int base)
|
size_t *actual)
|
||||||
{
|
{
|
||||||
uint64_t result;
|
uint64_t result;
|
||||||
#include "Inline/Int.h"
|
#include "Inline/Int.h"
|
||||||
|
|||||||
@@ -8,35 +8,35 @@ BH_UNIT_TEST(Int8)
|
|||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt8s(str, 9, -13, 16, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt8s(str, 9, -13, 16, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt8s(str, &size, 16) == -13);
|
BH_VERIFY(BH_StringToInt8s(str, 16, &size) == -13);
|
||||||
BH_VERIFY(size == 2);
|
BH_VERIFY(size == 2);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt8s(str, 9, -13, 10, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt8s(str, 9, -13, 10, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt8s(str, &size, 10) == -13);
|
BH_VERIFY(BH_StringToInt8s(str, 10, &size) == -13);
|
||||||
BH_VERIFY(size == 3);
|
BH_VERIFY(size == 3);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt8s(str, 9, -13, 8, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt8s(str, 9, -13, 8, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt8s(str, &size, 8) == -13);
|
BH_VERIFY(BH_StringToInt8s(str, 8, &size) == -13);
|
||||||
BH_VERIFY(size == 3);
|
BH_VERIFY(size == 3);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt8s(str, 9, -13, 2, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt8s(str, 9, -13, 2, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt8s(str, &size, 2) == -13);
|
BH_VERIFY(BH_StringToInt8s(str, 2, &size) == -13);
|
||||||
BH_VERIFY(size == 5);
|
BH_VERIFY(size == 5);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt8u(str, 9, 200, 16, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt8u(str, 9, 200, 16, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt8u(str, &size, 16) == 200);
|
BH_VERIFY(BH_StringToInt8u(str, 16, &size) == 200);
|
||||||
BH_VERIFY(size == 2);
|
BH_VERIFY(size == 2);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt8u(str, 9, 200, 10, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt8u(str, 9, 200, 10, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt8u(str, &size, 10) == 200);
|
BH_VERIFY(BH_StringToInt8u(str, 10, &size) == 200);
|
||||||
BH_VERIFY(size == 3);
|
BH_VERIFY(size == 3);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt8u(str, 9, 200, 8, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt8u(str, 9, 200, 8, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt8u(str, &size, 8) == 200);
|
BH_VERIFY(BH_StringToInt8u(str, 8, &size) == 200);
|
||||||
BH_VERIFY(size == 3);
|
BH_VERIFY(size == 3);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt8u(str, 9, 200, 2, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt8u(str, 9, 200, 2, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt8u(str, &size, 2) == 200);
|
BH_VERIFY(BH_StringToInt8u(str, 2, &size) == 200);
|
||||||
BH_VERIFY(size == 8);
|
BH_VERIFY(size == 8);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -49,35 +49,35 @@ BH_UNIT_TEST(Int16)
|
|||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt16s(str, 17, -1234, 16, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt16s(str, 17, -1234, 16, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt16s(str, &size, 16) == -1234);
|
BH_VERIFY(BH_StringToInt16s(str, 16, &size) == -1234);
|
||||||
BH_VERIFY(size == 4);
|
BH_VERIFY(size == 4);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt16s(str, 17, -1234, 10, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt16s(str, 17, -1234, 10, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt16s(str, &size, 10) == -1234);
|
BH_VERIFY(BH_StringToInt16s(str, 10, &size) == -1234);
|
||||||
BH_VERIFY(size == 5);
|
BH_VERIFY(size == 5);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt16s(str, 17, -1234, 8, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt16s(str, 17, -1234, 8, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt16s(str, &size, 8) == -1234);
|
BH_VERIFY(BH_StringToInt16s(str, 8, &size) == -1234);
|
||||||
BH_VERIFY(size == 5);
|
BH_VERIFY(size == 5);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt16s(str, 17, -1234, 2, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt16s(str, 17, -1234, 2, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt16s(str, &size, 2) == -1234);
|
BH_VERIFY(BH_StringToInt16s(str, 2, &size) == -1234);
|
||||||
BH_VERIFY(size == 12);
|
BH_VERIFY(size == 12);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt16u(str, 17, 43210, 16, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt16u(str, 17, 43210, 16, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt16u(str, &size, 16) == 43210);
|
BH_VERIFY(BH_StringToInt16u(str, 16, &size) == 43210);
|
||||||
BH_VERIFY(size == 4);
|
BH_VERIFY(size == 4);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt16u(str, 17, 43210, 10, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt16u(str, 17, 43210, 10, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt16u(str, &size, 10) == 43210);
|
BH_VERIFY(BH_StringToInt16u(str, 10, &size) == 43210);
|
||||||
BH_VERIFY(size == 5);
|
BH_VERIFY(size == 5);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt16u(str, 17, 43210, 8, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt16u(str, 17, 43210, 8, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt16u(str, &size, 8) == 43210);
|
BH_VERIFY(BH_StringToInt16u(str, 8, &size) == 43210);
|
||||||
BH_VERIFY(size == 6);
|
BH_VERIFY(size == 6);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt16u(str, 17, 43210, 2, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt16u(str, 17, 43210, 2, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt16u(str, &size, 2) == 43210);
|
BH_VERIFY(BH_StringToInt16u(str, 2, &size) == 43210);
|
||||||
BH_VERIFY(size == 16);
|
BH_VERIFY(size == 16);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -90,35 +90,35 @@ BH_UNIT_TEST(Int32)
|
|||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt32s(str, 33, -1234567890l, 16, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt32s(str, 33, -1234567890l, 16, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt32s(str, &size, 16) == -1234567890l);
|
BH_VERIFY(BH_StringToInt32s(str, 16, &size) == -1234567890l);
|
||||||
BH_VERIFY(size == 9);
|
BH_VERIFY(size == 9);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt32s(str, 33, -1234567890l, 10, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt32s(str, 33, -1234567890l, 10, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt32s(str, &size, 10) == -1234567890l);
|
BH_VERIFY(BH_StringToInt32s(str, 10, &size) == -1234567890l);
|
||||||
BH_VERIFY(size == 11);
|
BH_VERIFY(size == 11);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt32s(str, 33, -1234567890l, 8, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt32s(str, 33, -1234567890l, 8, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt32s(str, &size, 8) == -1234567890l);
|
BH_VERIFY(BH_StringToInt32s(str, 8, &size) == -1234567890l);
|
||||||
BH_VERIFY(size == 12);
|
BH_VERIFY(size == 12);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt32s(str, 33, -1234567890l, 2, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt32s(str, 33, -1234567890l, 2, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt32s(str, &size, 2) == -1234567890l);
|
BH_VERIFY(BH_StringToInt32s(str, 2, &size) == -1234567890l);
|
||||||
BH_VERIFY(size == 32);
|
BH_VERIFY(size == 32);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt32u(str, 33, 3456789012ul, 16, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt32u(str, 33, 3456789012ul, 16, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt32u(str, &size, 16) == 3456789012ul);
|
BH_VERIFY(BH_StringToInt32u(str, 16, &size) == 3456789012ul);
|
||||||
BH_VERIFY(size == 8);
|
BH_VERIFY(size == 8);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt32u(str, 33, 3456789012ul, 10, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt32u(str, 33, 3456789012ul, 10, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt32u(str, &size, 10) == 3456789012ul);
|
BH_VERIFY(BH_StringToInt32u(str, 10, &size) == 3456789012ul);
|
||||||
BH_VERIFY(size == 10);
|
BH_VERIFY(size == 10);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt32u(str, 33, 3456789012ul, 8, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt32u(str, 33, 3456789012ul, 8, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt32u(str, &size, 8) == 3456789012ul);
|
BH_VERIFY(BH_StringToInt32u(str, 8, &size) == 3456789012ul);
|
||||||
BH_VERIFY(size == 11);
|
BH_VERIFY(size == 11);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringFromInt32u(str, 33, 3456789012ul, 2, NULL) == BH_OK);
|
BH_VERIFY(BH_StringFromInt32u(str, 33, 3456789012ul, 2, NULL) == BH_OK);
|
||||||
BH_VERIFY(BH_StringToInt32u(str, &size, 2) == 3456789012ul);
|
BH_VERIFY(BH_StringToInt32u(str, 2, &size) == 3456789012ul);
|
||||||
BH_VERIFY(size == 32);
|
BH_VERIFY(size == 32);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -129,34 +129,34 @@ BH_UNIT_TEST(Parsing)
|
|||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
BH_VERIFY(BH_StringToInt32s(" 0x1234", &size, 16) == 0x1234);
|
BH_VERIFY(BH_StringToInt32s(" 0x1234", 16, &size) == 0x1234);
|
||||||
BH_VERIFY(size == 9);
|
BH_VERIFY(size == 9);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringToInt32s(" 12345", &size, 10) == 12345);
|
BH_VERIFY(BH_StringToInt32s(" 12345", 10, &size) == 12345);
|
||||||
BH_VERIFY(size == 8);
|
BH_VERIFY(size == 8);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringToInt32s(" 0123", &size, 8) == 0123);
|
BH_VERIFY(BH_StringToInt32s(" 0123", 8, &size) == 0123);
|
||||||
BH_VERIFY(size == 7);
|
BH_VERIFY(size == 7);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringToInt32s(" 0b1111Hello", &size, 2) == 15);
|
BH_VERIFY(BH_StringToInt32s(" 0b1111Hello", 2, &size) == 15);
|
||||||
BH_VERIFY(size == 9);
|
BH_VERIFY(size == 9);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringToInt32s(" 0x1234", &size, 0) == 0x1234);
|
BH_VERIFY(BH_StringToInt32s(" 0x1234", 0, &size) == 0x1234);
|
||||||
BH_VERIFY(size == 9);
|
BH_VERIFY(size == 9);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringToInt32s(" 0123", &size, 0) == 0123);
|
BH_VERIFY(BH_StringToInt32s(" 0123", 0, &size) == 0123);
|
||||||
BH_VERIFY(size == 7);
|
BH_VERIFY(size == 7);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringToInt32s(" 123", &size, 0) == 123);
|
BH_VERIFY(BH_StringToInt32s(" 123", 0, &size) == 123);
|
||||||
BH_VERIFY(size == 6);
|
BH_VERIFY(size == 6);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringToInt32s(" 0b1111", &size, 0) == 15);
|
BH_VERIFY(BH_StringToInt32s(" 0b1111", 0, &size) == 15);
|
||||||
BH_VERIFY(size == 9);
|
BH_VERIFY(size == 9);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringToInt32s(" 12345Hello", &size, 10) == 12345);
|
BH_VERIFY(BH_StringToInt32s(" 12345Hello", 10, &size) == 12345);
|
||||||
BH_VERIFY(size == 8);
|
BH_VERIFY(size == 8);
|
||||||
|
|
||||||
BH_VERIFY(BH_StringToInt32s(" Hello", &size, 10) == 0);
|
BH_VERIFY(BH_StringToInt32s(" Hello", 10, &size) == 0);
|
||||||
BH_VERIFY(size == 0);
|
BH_VERIFY(size == 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user