Audacity 3.2.0
Classes | Functions
ToChars.h File Reference

Define functions to convert numeric types to string representation. More...

#include <system_error>
Include dependency graph for ToChars.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ToCharsResult
 Result of the conversion, similar to std::to_chars_result. More...
 

Functions

STRING_UTILS_API ToCharsResult ToChars (char *buffer, char *last, float value, int digitsAfterDecimalPoint=-1) noexcept
 Convert a single precision floating point number to a string, always uses the dot as decimal. More...
 
STRING_UTILS_API ToCharsResult ToChars (char *buffer, char *last, double value, int digitsAfterDecimalPoint=-1) noexcept
 Convert a double precision floating point number to a string, always uses the dot as decimal. More...
 
STRING_UTILS_API ToCharsResult ToChars (char *buffer, char *last, long long value) noexcept
 Convert a signed 64 bit integer value to string. More...
 
STRING_UTILS_API ToCharsResult ToChars (char *buffer, char *last, unsigned long long value) noexcept
 Convert a unsigned 64 bit integer value to string. More...
 

Detailed Description

Define functions to convert numeric types to string representation.

Declare functions to convert numeric types to string representation.


Audacity: A Digital Audio Editor

Dmitry Vedenko

Definition in file ToChars.h.

Function Documentation

◆ ToChars() [1/4]

STRING_UTILS_API ToCharsResult ToChars ( char *  buffer,
char *  last,
double  value,
int  digitsAfterDecimalPoint = -1 
)
noexcept

Convert a double precision floating point number to a string, always uses the dot as decimal.

Definition at line 1233 of file ToChars.cpp.

1236{
1238 buffer, last, value, digitsAfterDecimalPoint);
1239}
ToCharsResult float_to_chars(char *first, char *last, T value, int digitsAfterDecimalPoint)
Definition: ToChars.cpp:1178

References internal::float_to_chars().

Here is the call graph for this function:

◆ ToChars() [2/4]

STRING_UTILS_API ToCharsResult ToChars ( char *  buffer,
char *  last,
float  value,
int  digitsAfterDecimalPoint = -1 
)
noexcept

Convert a single precision floating point number to a string, always uses the dot as decimal.

Definition at line 1225 of file ToChars.cpp.

1228{
1230 buffer, last, value, digitsAfterDecimalPoint);
1231}

References internal::float_to_chars().

Referenced by ToChars(), and XMLUtf8BufferWriter::WriteAttr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToChars() [3/4]

STRING_UTILS_API ToCharsResult ToChars ( char *  buffer,
char *  last,
long long  value 
)
noexcept

Convert a signed 64 bit integer value to string.

Definition at line 1242 of file ToChars.cpp.

1243{
1244 if (buffer >= last || buffer == nullptr)
1245 return { last, std::errc::value_too_large };
1246
1247 if (value < 0)
1248 {
1249 *buffer++ = '-';
1250 value = -value;
1251 }
1252
1253 return ToChars(buffer, last, static_cast<unsigned long long>(value));
1254}
STRING_UTILS_API ToCharsResult ToChars(char *buffer, char *last, float value, int digitsAfterDecimalPoint) noexcept
Convert a single precision floating point number to a string, always uses the dot as decimal.
Definition: ToChars.cpp:1225

References ToChars().

Here is the call graph for this function:

◆ ToChars() [4/4]

STRING_UTILS_API ToCharsResult ToChars ( char *  buffer,
char *  last,
unsigned long long  value 
)
noexcept

Convert a unsigned 64 bit integer value to string.

Definition at line 1256 of file ToChars.cpp.

1257{
1258 if (buffer >= last || buffer == nullptr)
1259 return { last, std::errc::value_too_large };
1260
1261 if (value == 0)
1262 {
1263 *buffer++ = '0';
1264 return { buffer, std::errc() };
1265 }
1266
1267 constexpr size_t safeSize =
1268 std::numeric_limits<unsigned long long>::digits10 + 2;
1269
1270 const size_t bufferSize = static_cast<size_t>(last - buffer);
1271
1272 if (bufferSize >= safeSize)
1273 return { internal::itoa_impl::u64toa_jeaiii(value, buffer), std::errc() };
1274
1275 char tempBuffer[safeSize];
1276 char* tempLast = internal::itoa_impl::u64toa_jeaiii(value, tempBuffer);
1277
1278 const size_t resultSize = static_cast<size_t>(tempLast - tempBuffer);
1279
1280 if (resultSize > bufferSize)
1281 return { last, std::errc::value_too_large };
1282
1283 std::copy(tempBuffer, tempLast, buffer);
1284
1285 return { buffer + resultSize, std::errc() };
1286}
char * u64toa_jeaiii(uint64_t n, char *b)
Definition: ToChars.cpp:93
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40

References staffpad::vo::copy(), and internal::itoa_impl::u64toa_jeaiii().

Here is the call graph for this function: