tests: move gmio_stlb_header_to_printable_str() to gmio_stl/stlb_header.h

This commit is contained in:
Hugues Delorme 2016-01-13 15:17:18 +01:00
parent 0d7eb270bc
commit d0b213a652
6 changed files with 26 additions and 21 deletions

View File

@ -30,7 +30,6 @@
#include <stddef.h>
#include "stl_format.h"
#include "stlb_header.h"
@ -47,12 +46,12 @@ struct gmio_stl_infos
/*! STL ascii only: name of the solid
*
* The pointer has to be set by the caller of gmio_stl_infos_get() */
* The pointer has to be set before calling gmio_stl_infos_get() */
char* stla_solidname;
/*! STL ascii only: maximum length(capacity) of stla_solidname
*
* The value has to be set by the caller of gmio_stl_infos_get()
* The value has to be set before calling gmio_stl_infos_get()
*/
size_t stla_solidname_maxlen;
@ -92,8 +91,7 @@ struct gmio_stl_infos_get_args
/*! Optional memory block used by the stream to bufferize read operations
*
* If null, then a temporary memblock is created with the global default
* constructor function (see gmio_memblock_default())
*/
* constructor function (see gmio_memblock_default()) */
struct gmio_memblock stream_memblock;
/*! Output informations */

View File

@ -15,6 +15,7 @@
#include "stlb_header.h"
#include <ctype.h>
#include <string.h>
struct gmio_stlb_header gmio_stlb_header_str(const char* str)
@ -24,3 +25,14 @@ struct gmio_stlb_header gmio_stlb_header_str(const char* str)
strncpy((char*)header.data, str, GMIO_STLB_HEADER_SIZE);
return header;
}
void gmio_stlb_header_to_printable_str(
const struct gmio_stlb_header* header, char* str, char replacement)
{
size_t i;
for (i = 0; i < GMIO_STLB_HEADER_SIZE; ++i) {
const int header_char = (int)header->data[i];
str[i] = isprint(header_char) ? (char)header_char : replacement;
}
str[GMIO_STLB_HEADER_SIZE] = 0;
}

View File

@ -44,6 +44,16 @@ GMIO_C_LINKAGE_BEGIN
GMIO_LIBSTL_EXPORT
struct gmio_stlb_header gmio_stlb_header_str(const char* str);
/*! Copies \p header into C string \p str
*
* It replaces non-printable bytes with \p replacement char.
* \p str must be at least \c GMIO_STLB_HEADER_SIZE long, a terminating null
* character ('\0') is copied at position \c GMIO_STLB_HEADER_SIZE
*/
GMIO_LIBSTL_EXPORT
void gmio_stlb_header_to_printable_str(
const struct gmio_stlb_header* header, char* str, char replacement);
GMIO_C_LINKAGE_END
#endif /* GMIO_STLB_HEADER_H */

View File

@ -115,18 +115,6 @@ struct gmio_stl_mesh gmio_stl_data_mesh(const struct gmio_stl_data *data)
return mesh;
}
void gmio_stlb_header_to_printable_string(
const struct gmio_stlb_header *header, char *str, char replacement)
{
size_t i = 0;
for (; i < GMIO_STLB_HEADER_SIZE; ++i) {
str[i] = isprint((int)header->data[i]) ?
(char) header->data[i] :
replacement;
}
str[GMIO_STLB_HEADER_SIZE] = 0;
}
gmio_bool_t gmio_stl_coords_equal(
const struct gmio_stl_coords *lhs,
const struct gmio_stl_coords *rhs,

View File

@ -41,9 +41,6 @@ GMIO_INLINE gmio_bool_t gmio_stlb_header_equal(
return memcmp(lhs, rhs, GMIO_STLB_HEADER_SIZE) == 0;
}
void gmio_stlb_header_to_printable_string(
const struct gmio_stlb_header* header, char* str, char replacement);
/*! Callback for gmio_stl_mesh_creator::func_add_triangle that does
* nothing(ie "no operation") */
void gmio_stl_nop_add_triangle(

View File

@ -325,7 +325,7 @@ const char* test_stla_write()
{
struct gmio_stl_write_args write = {0};
write.mesh = gmio_stl_data_mesh(&data);
gmio_stlb_header_to_printable_string(&data.header, &header_str[0], '_');
gmio_stlb_header_to_printable_str(&data.header, &header_str[0], '_');
write.options.stla_solid_name = &header_str[0];
write.options.stla_float32_prec = 7;
write.options.stla_float32_format =