/* VectorNav HSI Calibration Library v1.0.0.2
 *
 * Copyright (c) 2018 VectorNav Technologies, LLC
 *
 * This source code is proprietary to and copyrighted by VectorNav Technologies, LLC and is
 * available solely under license from VectorNav. All rights reserved. If you do not have a
 * license to use this source code from VectorNav, any use hereof is strictly prohibited by
 * U.S. law and other applicable law. This source code is restricted for use solely with the
 * products of VectorNav and as otherwise set forth in any agreement with VectorNav. Any
 * disclosure of this source code to the public or to any third party is also prohibited.
 */
#ifndef VNSTRING_H_INCLUDED
#define VNSTRING_H_INCLUDED

#include <stddef.h>
#include "vnenum.h"

#ifdef __cplusplus
extern "C" {
#endif

/**\brief Cross-platform strcpy. MSBuild prefers to use strcpy_s otherwise
 * warnings are generated and Linux does not have a corresponding function.
 * \param dest The destination buffer.
 * \param numOfElements Size of the destination buffer.
 * \param src Null-terminated string to copy.
 * \return Any errors encountered. */
enum VnError
strcpy_x(
    char *dest,
    size_t numOfElements,
    const char *src);

/**\brief Cross-platform strcat. MSBuild prefers to use strcat_s otherwise
 * warnings are generated and Linux does not have a corresponding function.
 * \param dest The destination buffer.
 * \param numOfElements Size of the destination buffer.
 * \param src Null-terminated string to copy.
 * \return Any errors encountered. */
enum VnError
strcat_x(
    char* dest,
    size_t numOfElements,
    const char *src);

/**\brief Cross-platform sprintf with safety checks.
 * \param[out] buffer Output buffer to write the string.
 * \param[in] sizeOfBuffer Size of the output buffer.
 * \param[in] format The format string.
 * \return On success, the total number of characters written, not including
 *     the null-termination character. On failure, a negative number is
 *     returned. */
int
sprintf_x(
    char *buffer,
    size_t sizeOfBuffer,
    const char *format,
    ...);

/**\brief Cross-platform strtok with safety checks.
 * \param[in] str String to tokenize.
 * \param[in] delim The deliminator.
 * \param[in/out] saveptr Internal state which must be passed on each
 *     subsequent call to <c>strtok_x</c> when processing the same string.
 * \return The beginning of the next tokenized string. <c>NULL</c> if the end
 *     is reached. */
char*
strtok_x(
    char *str,
    const char *delim,
    char **saveptr);

#ifdef __cplusplus
}
#endif

#endif
