QPMS
Electromagnetic multiple scattering library and toolkit.
Functions
parsing.h File Reference

Some custom string conversions. More...

#include <stddef.h>
Include dependency graph for parsing.h:

Go to the source code of this file.

Functions

size_t qpms_parse_ndoubles (double *target, size_t n, const char *orig)
 
size_t qpms_parse_doubles (double **target, size_t start_index, const char *orig)
 
size_t qpms_parse_doubles_fromfile (double **target, size_t start_index, const char *filepath)
 

Detailed Description

Some custom string conversions.

Function Documentation

◆ qpms_parse_doubles()

size_t qpms_parse_doubles ( double **  target,
size_t  start_index,
const char *  orig 
)

Parse doubles from a string.

The doubles can be separated by whitespaces, comma or semicolon. The parsed numbers are saved into an array specified by *target that has been preallocated with malloc() to contain at least start_index members. If start_index is nonzero, the newly parsed numbers are saved to the positions starting from start_index.

If *target is NULL, the function allocates the necessary space.

Returns
Number of newly parsed doubles + start_index.

◆ qpms_parse_doubles_fromfile()

size_t qpms_parse_doubles_fromfile ( double **  target,
size_t  start_index,
const char *  filepath 
)

Parse doubles from a file.

The doubles can be separated by whitespaces, comma or semicolon. The parsed numbers are saved into an array specified by *target that has been preallocated with malloc() to contain at least start_index members. If start_index is nonzero, the newly parsed numbers are saved to the positions starting from start_index.

If *target is NULL, the function allocates the necessary space.

If filepath is NULL, "" or "-", read from stdin.

Returns
Number of newly parsed doubles + start_index.

◆ qpms_parse_ndoubles()

size_t qpms_parse_ndoubles ( double *  target,
size_t  n,
const char *  orig 
)

Parse a given number of doubles from a string.

The doubles can be separated by whitespaces, comma or semicolon.

Returns
If the string included up to n doubles, number of parsed doubles. If more, n+1.