28 # error This is a userspace-only header, not allowed by the current build.
31 #include <sifteo/abi.h>
56 Fixed(
int value,
unsigned width,
bool leadingZeroes=
false)
57 : value(value), width(width), leadingZeroes(leadingZeroes) {}
80 FixedFP(
float value,
unsigned left,
unsigned right,
bool leadingZeroes=
false)
81 : widthL(left), widthR(right), leadingZeroes(leadingZeroes)
96 case 0: valueR = value * 0;
break;
97 case 1: valueR = value * 10;
break;
98 case 2: valueR = value * 100;
break;
99 case 3: valueR = value * 1000;
break;
100 case 4: valueR = value * 10000;
break;
101 case 5: valueR = value * 100000;
break;
102 case 6: valueR = value * 1000000;
break;
103 case 7: valueR = value * 10000000;
break;
104 case 8: valueR = value * 100000000;
break;
105 case 9: valueR = value * 1000000000;
break;
111 unsigned widthL, widthR;
128 Hex(uint32_t value,
unsigned width=8,
bool leadingZeroes=
true)
129 : value(value), width(width), leadingZeroes(leadingZeroes) {}
148 Hex64(uint64_t value,
unsigned width=16,
bool leadingZeroes=
true)
149 : value(value), width(width), leadingZeroes(leadingZeroes) {}
165 inline int strncmp(
const char *a,
const char *b,
unsigned count)
167 return _SYS_strncmp(a, b, count);
176 inline unsigned strnlen(
const char *str, uint32_t maxLen) {
177 return _SYS_strnlen(str, maxLen);
190 template <
unsigned tCapacity>
194 typedef char* iterator;
195 typedef const char* const_iterator;
218 operator const char *()
const {
229 return _SYS_strnlen(buffer, tCapacity-1);
239 return &buffer[
size()];
248 const_iterator
end()
const {
249 return &buffer[
size()];
259 return buffer[0] ==
'\0';
271 template <
class T>
int compare(
const T &other)
const {
290 _SYS_strlcpy(buffer, src, tCapacity);
296 _SYS_strlcat(buffer, src, tCapacity);
302 return buffer[index];
307 return buffer[index];
312 return buffer[index];
317 return buffer[index];
322 _SYS_strlcat(buffer, src, tCapacity);
328 _SYS_strlcat_int(buffer, src, tCapacity);
334 _SYS_strlcat_int_fixed(buffer, src.value, src.width, src.leadingZeroes, tCapacity);
340 _SYS_strlcat_int_fixed(buffer, src.valueL, src.widthL, src.leadingZeroes, tCapacity);
341 _SYS_strlcat(buffer,
".", tCapacity);
342 _SYS_strlcat_int_fixed(buffer, src.valueR, src.widthR,
true, tCapacity);
348 _SYS_strlcat_int_hex(buffer, src.value, src.width, src.leadingZeroes, tCapacity);
354 uint32_t high = src.value >> 32;
355 uint32_t low = src.value;
356 if (src.width > 8 || high != 0) {
357 _SYS_strlcat_int_hex(buffer, high, src.width - 8, src.leadingZeroes, tCapacity);
358 _SYS_strlcat_int_hex(buffer, low, 8,
true, tCapacity);
360 _SYS_strlcat_int_hex(buffer, low, src.width, src.leadingZeroes, tCapacity);
396 char buffer[tCapacity];
String & operator<<(const Fixed &src)
STL-style formatting operator, append a fixed-width decimal integer.
Definition: string.h:333
Hex64(uint64_t value, unsigned width=16, bool leadingZeroes=true)
Format 'value' using exactly 'width' characters.
Definition: string.h:148
bool empty() const
Is the string empty? (Faster than size() == 0)
Definition: string.h:258
String & operator<<(const FixedFP &src)
STL-style formatting operator, append a fixed-width floating point number.
Definition: string.h:339
String & operator<<(const Hex64 &src)
STL-style formatting operator, append a fixed-width hexadecimal 64-bit integer.
Definition: string.h:353
FixedFP(float value, unsigned left, unsigned right, bool leadingZeroes=false)
Format 'value' using exactly 'left' digits to the left of the decimal, and 'right' digits to the righ...
Definition: string.h:80
Hex(uint32_t value, unsigned width=8, bool leadingZeroes=true)
Format 'value' using exactly 'width' characters.
Definition: string.h:128
String formatting wrapper for fixed-width hexadecimal 64-bit integers.
Definition: string.h:141
iterator end()
Return an iterator, pointing just past the end of the string (at the NUL)
Definition: string.h:238
String & operator<<(const Hex &src)
STL-style formatting operator, append a fixed-width hexadecimal integer.
Definition: string.h:347
char & operator[](int index)
Indexing operator, to get or set one character.
Definition: string.h:306
String & operator<<(int src)
STL-style formatting operator, append a decimal integer.
Definition: string.h:327
const char * c_str() const
Return a C-style constant character pointer.
Definition: string.h:208
const_iterator begin() const
Const version of begin()
Definition: string.h:243
int compare(const char *other) const
Compare this string against a C-style string.
Definition: string.h:284
#define ASSERT(_x)
Runtime debug assertion.
Definition: macros.h:205
String & operator=(const char *src)
Overwrite this with another string.
Definition: string.h:289
String & operator+=(const char *src)
Append another string to this one.
Definition: string.h:295
const_iterator end() const
Const version of end()
Definition: string.h:248
int compare(const T &other) const
Compare this string against another.
Definition: string.h:271
A statically sized character buffer, with output formatting support.
Definition: string.h:191
String()
Initialize a new empty string.
Definition: string.h:198
bool operator!=(const T &other)
Is this string different from another?
Definition: string.h:371
static unsigned capacity()
Retrieve the size of the buffer, in bytes, including space for NUL termination.
Definition: string.h:223
char & operator[](unsigned index)
Indexing operator, to get or set one character.
Definition: string.h:301
bool operator==(const T &other)
Is this string equal to another?
Definition: string.h:366
char * c_str()
Return a C-style character pointer.
Definition: string.h:203
char operator[](int index) const
Const indexing operator.
Definition: string.h:316
bool operator<=(const T &other)
Is this string before another or equal, in ASCII order?
Definition: string.h:381
void clear()
Overwrite this with the empty string.
Definition: string.h:253
String formatting wrapper for fixed-width integers.
Definition: string.h:49
unsigned size() const
Get the current size of the string, in characters, excluding NUL termination.
Definition: string.h:228
#define MIN(a, b)
Definition: macros.h:347
String & operator<<(const char *src)
STL-style formatting operator, append a string.
Definition: string.h:321
iterator begin()
Return an iterator, pointing to the first character in the string.
Definition: string.h:233
bool operator>(const T &other)
Is this string after another, in ASCII order?
Definition: string.h:386
int strncmp(const char *a, const char *b, unsigned count)
Compare two C-style strings.
Definition: string.h:165
Format a floating point number using fixed precision.
Definition: string.h:73
Fixed(int value, unsigned width, bool leadingZeroes=false)
Format 'value' using exactly 'width' characters.
Definition: string.h:56
String formatting wrapper for fixed-width hexadecimal integers.
Definition: string.h:121
unsigned strnlen(const char *str, uint32_t maxLen)
Get the length of a C-style string.
Definition: string.h:176
bool operator>=(const T &other)
Is this string after another or equal, in ASCII order?
Definition: string.h:391
char operator[](unsigned index) const
Const indexing operator.
Definition: string.h:311
bool operator<(const T &other)
Is this string before another, in ASCII order?
Definition: string.h:376