Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Variant/CharacterDelimitedLines/Reader.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_DataExchange_Variant_CharacterDelimitedLines_Reader_h_
5#define _Stroika_Foundation_DataExchange_Variant_CharacterDelimitedLines_Reader_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include "Stroika/Foundation/Common/Common.h"
10#include "Stroika/Foundation/Containers/Sequence.h"
11#include "Stroika/Foundation/Containers/Set.h"
15
16/**
17 * \file
18 *
19 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
20 *
21 * TODO:
22 */
23
24namespace Stroika::Foundation::DataExchange::Variant::CharacterDelimitedLines {
25
26 using Characters::Character;
27 using Characters::String;
28 using Containers::Sequence;
29 using Containers::Set;
30 using Traversal::Iterable;
31
32 /**
33 * \brief This COULD be easily used to read CSV files, or tab-delimited files, for example.
34 *
35 * \par Example Usage
36 * Source file(/usr/share/mime/globs):
37 * # This file was automatically generated by the
38 * # update-mime-database command. DO NOT EDIT!
39 * application/x-doom-wad:*.wad
40 * application/x-cd-image:*.iso
41 * application/x-abiword:*.abw.crashed
42 *...
43 * \code
44 * Bijection<InternetMediaType, FileSuffixType> results{};
45 * for (Sequence<String> line : DataExchange::Variant::CharacterDelimitedLines::Reader{{':'}}.ReadMatrix (IO::FileSystem::FileInputStream::New ("/usr/share/mime/globs"sv))) {
46 * if (line.length () == 2) {
47 * String glob = line[1];
48 * if (glob.StartsWith ('*')) {
49 * glob = glob.SubString (1);
50 * }
51 * results.Add (InternetMediaType{line[0]}, glob);
52 * }
53 * }
54 * \endcode
55 */
56 class Reader : public Variant::Reader {
57 private:
59
60 private:
61 class Rep_;
62
63 public:
64 Reader (const Set<Character>& columnDelimiters, bool trimTokens = true);
65
66 public:
67 /**
68 * Alternative reading API for this file type, which maybe helpful, to read as a series of lines.
69 */
73 nonvirtual Iterable<Sequence<String>> ReadMatrix (istream& in);
74 nonvirtual Iterable<Sequence<String>> ReadMatrix (wistream& in);
75 };
76
77}
78
79/*
80 ********************************************************************************
81 ***************************** Implementation Details ***************************
82 ********************************************************************************
83 */
84#include "Reader.inl"
85
86#endif /*_Stroika_Foundation_DataExchange_Variant_CharacterDelimitedLines_Reader_h_*/
Set<T> is a container of T, where once an item is added, additionally adds () do nothing.
Definition Set.h:105
This COULD be easily used to read CSV files, or tab-delimited files, for example.
nonvirtual Iterable< Sequence< String > > ReadMatrix(const Streams::InputStream::Ptr< byte > &in) const
abstract class specifying interface for readers that map a source like XML or JSON to a VariantValue ...
InputStream<>::Ptr is Smart pointer (with abstract Rep) class defining the interface to reading from ...
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
Definition Iterable.h:237