-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_utils.h
60 lines (44 loc) · 1.85 KB
/
file_utils.h
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
50
51
52
53
54
55
56
57
58
59
60
#pragma once
#include "common.h"
#include <cctype>
template <typename U, typename V>
void Swap(U *a, V *b) // @Cleanup: Use this instead of swap_elements
{
auto temp = *a;
*a = *b;
*b = temp;
}
// #define MYLOGCONCAT(a, b) a b
// #define logprint(ident, ...) \
// printf(MYLOGCONCAT("[", ident) "] Function '%s', line %d: ", __FUNCTION__, __LINE__); \
// printf(__VA_ARGS__);
struct Text_File_Handler
{
String full_path;
String log_agent;
char comment_character = '#';
bool do_version_number = true;
// If you switch this to false, things might be faster, but not by much...
bool strip_comments_from_ends_of_lines = true;
String file_data;
String orig_file_data;
bool failed = false;
i32 version = -1; // Set when parsing the file if do_version_number = true
u32 line_number = 0;
};
typedef void(FileVisitProc)(String short_name, String full_name, void *data);
bool visit_files(String matching_pattern, void *data, FileVisitProc visit_proc, bool only_directory = false);
my_pair<String, bool> read_entire_file(String full_path);
my_pair<String, bool> consume_next_line(String *sp);
String find_character_from_right(String string, u8 c);
String find_character_from_left(String string, u8 c);
void advance(String *s, i64 amount);
void eat_spaces(String *sp);
void eat_trailing_spaces(String *string);
my_pair<String, String> break_by_spaces(String line);
void start_file(Text_File_Handler *handler, String full_path, String log_agent, bool optional = false);
void deinit(Text_File_Handler *handler);
my_pair<String, bool> consume_next_line(Text_File_Handler *handler);
my_pair<f32, String> string_to_float(String s, bool *success);
my_pair<i64, String> string_to_int(String s, bool *success);
my_pair<Vector4, String> string_to_vec4(String s, bool *success);