Loading...
Searching...
No Matches
field_parsing.h
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-only
2// Copyright (C) 2026 Artificial Intelligence Techniques, S.L. and Roberto López González
3
4#pragma once
5
8
9#include <utility>
10
11namespace opennn
12{
13
15{
16public:
17
18 struct Result
19 {
21 string buffer;
22 vector<string_view> lines;
23 bool has_quotes = false;
24 };
25
26 explicit CsvReader(function<void(string_view)> new_line_validator = {})
27 : line_validator(std::move(new_line_validator))
28 {
29 }
30
31 Result read(const filesystem::path&) const;
32
33private:
34
35 function<void(string_view)> line_validator;
36
37 void parse(Result&, string_view) const;
38};
39
41{
43 char group_separator = '\0';
44
45 bool is_default() const
46 {
47 return decimal_separator == '.' && group_separator == '\0';
48 }
49};
50
52{
53 Index point_decimal = 0;
54 Index comma_decimal = 0;
55 Index point_group = 0;
56 Index comma_group = 0;
57
58 // Tokens that read both ways, such as "9,465": three digits after a single
59 // separator, and a leading part short enough to be a group of its own. They
60 // decide nothing on their own, and are only consulted when no other token
61 // in the file settles the format.
62 Index point_ambiguous = 0;
63 Index comma_ambiguous = 0;
64};
65
68
69string number_format_name(char);
70char number_format_separator(const string&, string_view);
71
72bool parse_real(string_view, float&, const NumberFormat& = {});
73bool parse_real(string_view, double&, const NumberFormat& = {});
74
75bool is_numeric_string(string_view, const NumberFormat& = {});
76bool is_date_time_string(string_view);
77
78extern const vector<string> positive_words;
79extern const vector<string> negative_words;
80
82
84time_t date_to_timestamp(string_view, Index = 0, DateFormat format = Auto);
85
86}
CsvReader(function< void(string_view)> new_line_validator={})
Definition field_parsing.h:26
Result read(const filesystem::path &) const
Definition io_utilities.h:139
Definition configuration.h:10
const vector< string > positive_words
char number_format_separator(const string &, string_view)
string number_format_name(char)
const vector< string > negative_words
NumberFormat decide_number_format(const NumberFormatVotes &)
void vote_number_format(string_view, NumberFormatVotes &)
time_t date_to_timestamp(string_view, Index=0, DateFormat format=Auto)
bool is_numeric_string(string_view, const NumberFormat &={})
bool is_date_time_string(string_view)
DateFormat
Definition field_parsing.h:81
@ Auto
Definition field_parsing.h:81
@ Mdy
Definition field_parsing.h:81
@ Ymd
Definition field_parsing.h:81
@ Dmy
Definition field_parsing.h:81
bool parse_real(string_view, float &, const NumberFormat &={})
DateFormat detect_date_format(string_view)
Definition field_parsing.h:19
bool has_quotes
Definition field_parsing.h:23
FileMapping mapping
Definition field_parsing.h:20
vector< string_view > lines
Definition field_parsing.h:22
string buffer
Definition field_parsing.h:21
Definition field_parsing.h:52
Index comma_ambiguous
Definition field_parsing.h:63
Index comma_decimal
Definition field_parsing.h:54
Index point_group
Definition field_parsing.h:55
Index point_ambiguous
Definition field_parsing.h:62
Index comma_group
Definition field_parsing.h:56
Index point_decimal
Definition field_parsing.h:53
Definition field_parsing.h:41
bool is_default() const
Definition field_parsing.h:45
char decimal_separator
Definition field_parsing.h:42
char group_separator
Definition field_parsing.h:43