-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstring_input_stream.h
More file actions
49 lines (43 loc) · 1.77 KB
/
string_input_stream.h
File metadata and controls
49 lines (43 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
/* ************************************************************************** */
/* ____ _ _____ ____ _ _ _ _____ _ _ ____ ____ */
/* / ___| / \ | ___| _ \ / \ | \ | | |_ _| || | | _ \/ ___| */
/* \___ \ / _ \ | |_ | |_) | / _ \ | \| | | | | || |_| | | \___ \ */
/* ___) / ___ \| _| | _ < / ___ \| |\ | | | |__ _| |_| |___) | */
/* |____/_/ \_|_| |_| \_/_/ \_|_| \_| |_| |_| |____/|____/ */
/* */
/**
* @copyright 2023, SAFRAN T4DS, ALL RIGHTS RESERVED
* @file string_input_stream.h
* @author Antoine GAGNIERE
* @brief Create input streams from strings
*/
/* ************************************************************************** */
#include "o2s/input_stream.h"
#include "o2s/string.h"
#include <stddef.h> // size_t
istream_t string_input_stream(const string_t* value);
istream_t cstring_input_stream(const char* value, size_t length);
/**
* Create an input stream with the content of a C string.
* @note strlen() of a literal can be computed at compile time.
*/
#define string_literal_input_stream(Value) \
cstring_input_stream(Value, strlen(Value))
/**
* Use the RAII idiom with a string input stream.
*
* In a situation where one wants to declare an istream variable
* on the stack in the local scope, this "typedef" can be used for
* the file to be closed automatically when the variable goes out
* of scope.
*
* It means this "typedef" can only be used like this :
* @code{.c}
* {
* StringInputStream file = string_input_string(...);
* ...
* } // <- The stream will be closed at that point
* @endcode
*/
#define StringInputStream __attribute__((cleanup(istream_close))) istream_t