WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
string.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <stddef.h> // NOLINT
8
9/**
10 * A const UTF8 string.
11 */
12struct WPI_String {
13 /** Contents. */
14 const char* str;
15 /** Length */
16 size_t len;
17};
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23/**
24 * Initializes a WPI_String from a null terminated UTF-8 string.
25 * If input string is null, initializes output to 0 length.
26 * The output length does not include the null terminator.
27 *
28 * The lifetime of the output string is the lifetime of the input string.
29 * Do not call WPI_FreeString() with the output of this call.
30 *
31 * @param wpiString output string
32 * @param utf8String input string (null terminated)
33 */
34void WPI_InitString(struct WPI_String* wpiString, const char* utf8String);
35
36/**
37 * Initializes a WPI_String from a UTF-8 string and length.
38 * If input string is null or 0 length, initializes output to 0 length.
39 * The input string does not need to be null terminated.
40 *
41 * The lifetime of the output string is the lifetime of the input string.
42 * Do not call WPI_FreeString() with the output of this call.
43 *
44 * @param wpiString output string
45 * @param utf8String input string
46 * @param length input string length in chars
47 */
48void WPI_InitStringWithLength(struct WPI_String* wpiString,
49 const char* utf8String, size_t length);
50
51/**
52 * Allocates a WPI_String for the specified length.
53 * The resultant string must be freed with WPI_FreeString().
54 *
55 * @param wpiString output string
56 * @param length string length in chars to allocate
57 * @return mutable pointer to allocated buffer
58 *
59 */
60char* WPI_AllocateString(struct WPI_String* wpiString, size_t length);
61
62/**
63 * Frees a WPI_String that was allocated with WPI_AllocateString()
64 *
65 * @param wpiString string to free
66 */
67void WPI_FreeString(const struct WPI_String* wpiString);
68
69/**
70 * Allocates an array of WPI_Strings.
71 *
72 * @param length array length
73 * @return string array
74 */
75struct WPI_String* WPI_AllocateStringArray(size_t length);
76
77/**
78 * Frees a WPI_String array returned by WPI_AllocateStringArray().
79 *
80 * @param wpiStringArray string array to free
81 * @param length length of array
82 */
83void WPI_FreeStringArray(const struct WPI_String* wpiStringArray,
84 size_t length);
85
86#ifdef __cplusplus
87} // extern "C"
88#endif
char * WPI_AllocateString(struct WPI_String *wpiString, size_t length)
Allocates a WPI_String for the specified length.
struct WPI_String * WPI_AllocateStringArray(size_t length)
Allocates an array of WPI_Strings.
void WPI_InitStringWithLength(struct WPI_String *wpiString, const char *utf8String, size_t length)
Initializes a WPI_String from a UTF-8 string and length.
void WPI_InitString(struct WPI_String *wpiString, const char *utf8String)
Initializes a WPI_String from a null terminated UTF-8 string.
void WPI_FreeString(const struct WPI_String *wpiString)
Frees a WPI_String that was allocated with WPI_AllocateString().
void WPI_FreeStringArray(const struct WPI_String *wpiStringArray, size_t length)
Frees a WPI_String array returned by WPI_AllocateStringArray().
A const UTF8 string.
Definition string.h:12
const char * str
Contents.
Definition string.h:14
size_t len
Length.
Definition string.h:16